Skip to content

Commit be1679b

Browse files
authored
[SYCL][COMPAT] Specialize reverse_bits for nvptx (intel#15805)
This uses a ptx instruction to specialize `syclcompat::bit_reverse` for NVPTX backend. --------- Signed-off-by: JackAKirk <[email protected]>
1 parent 53ca518 commit be1679b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sycl/include/syclcompat/util.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ inline double cast_ints_to_double(int high32, int low32) {
162162
template <typename T> inline T reverse_bits(T a) {
163163
static_assert(std::is_unsigned<T>::value && std::is_integral<T>::value,
164164
"unsigned integer required");
165+
#if defined(__NVPTX__)
166+
if constexpr (sizeof(T) == 4) {
167+
unsigned result;
168+
asm volatile("brev.b32 %0, %1;" : "=r"(result) : "r"(a));
169+
return result;
170+
}
171+
#endif // __NVPTX__
165172
if (!a)
166173
return 0;
167174
T mask = 0;

0 commit comments

Comments
 (0)