__clang_cuda_intrinsics.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. /*===--- __clang_cuda_intrinsics.h - Device-side CUDA intrinsic wrappers ---===
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. *
  21. *===-----------------------------------------------------------------------===
  22. */
  23. #ifndef __CLANG_CUDA_INTRINSICS_H__
  24. #define __CLANG_CUDA_INTRINSICS_H__
  25. #ifndef __CUDA__
  26. #error "This file is for CUDA compilation only."
  27. #endif
  28. // sm_30 intrinsics: __shfl_{up,down,xor}.
  29. #define __SM_30_INTRINSICS_H__
  30. #define __SM_30_INTRINSICS_HPP__
  31. #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
  32. #pragma push_macro("__MAKE_SHUFFLES")
  33. #define __MAKE_SHUFFLES(__FnName, __IntIntrinsic, __FloatIntrinsic, __Mask, \
  34. __Type) \
  35. inline __device__ int __FnName(int __val, __Type __offset, \
  36. int __width = warpSize) { \
  37. return __IntIntrinsic(__val, __offset, \
  38. ((warpSize - __width) << 8) | (__Mask)); \
  39. } \
  40. inline __device__ float __FnName(float __val, __Type __offset, \
  41. int __width = warpSize) { \
  42. return __FloatIntrinsic(__val, __offset, \
  43. ((warpSize - __width) << 8) | (__Mask)); \
  44. } \
  45. inline __device__ unsigned int __FnName(unsigned int __val, __Type __offset, \
  46. int __width = warpSize) { \
  47. return static_cast<unsigned int>( \
  48. ::__FnName(static_cast<int>(__val), __offset, __width)); \
  49. } \
  50. inline __device__ long long __FnName(long long __val, __Type __offset, \
  51. int __width = warpSize) { \
  52. struct __Bits { \
  53. int __a, __b; \
  54. }; \
  55. _Static_assert(sizeof(__val) == sizeof(__Bits)); \
  56. _Static_assert(sizeof(__Bits) == 2 * sizeof(int)); \
  57. __Bits __tmp; \
  58. memcpy(&__val, &__tmp, sizeof(__val)); \
  59. __tmp.__a = ::__FnName(__tmp.__a, __offset, __width); \
  60. __tmp.__b = ::__FnName(__tmp.__b, __offset, __width); \
  61. long long __ret; \
  62. memcpy(&__ret, &__tmp, sizeof(__tmp)); \
  63. return __ret; \
  64. } \
  65. inline __device__ long __FnName(long __val, __Type __offset, \
  66. int __width = warpSize) { \
  67. _Static_assert(sizeof(long) == sizeof(long long) || \
  68. sizeof(long) == sizeof(int)); \
  69. if (sizeof(long) == sizeof(long long)) { \
  70. return static_cast<long>( \
  71. ::__FnName(static_cast<long long>(__val), __offset, __width)); \
  72. } else if (sizeof(long) == sizeof(int)) { \
  73. return static_cast<long>( \
  74. ::__FnName(static_cast<int>(__val), __offset, __width)); \
  75. } \
  76. } \
  77. inline __device__ unsigned long __FnName( \
  78. unsigned long __val, __Type __offset, int __width = warpSize) { \
  79. return static_cast<unsigned long>( \
  80. ::__FnName(static_cast<long>(__val), __offset, __width)); \
  81. } \
  82. inline __device__ unsigned long long __FnName( \
  83. unsigned long long __val, __Type __offset, int __width = warpSize) { \
  84. return static_cast<unsigned long long>(::__FnName( \
  85. static_cast<unsigned long long>(__val), __offset, __width)); \
  86. } \
  87. inline __device__ double __FnName(double __val, __Type __offset, \
  88. int __width = warpSize) { \
  89. long long __tmp; \
  90. _Static_assert(sizeof(__tmp) == sizeof(__val)); \
  91. memcpy(&__tmp, &__val, sizeof(__val)); \
  92. __tmp = ::__FnName(__tmp, __offset, __width); \
  93. double __ret; \
  94. memcpy(&__ret, &__tmp, sizeof(__ret)); \
  95. return __ret; \
  96. }
  97. __MAKE_SHUFFLES(__shfl, __nvvm_shfl_idx_i32, __nvvm_shfl_idx_f32, 0x1f, int);
  98. // We use 0 rather than 31 as our mask, because shfl.up applies to lanes >=
  99. // maxLane.
  100. __MAKE_SHUFFLES(__shfl_up, __nvvm_shfl_up_i32, __nvvm_shfl_up_f32, 0,
  101. unsigned int);
  102. __MAKE_SHUFFLES(__shfl_down, __nvvm_shfl_down_i32, __nvvm_shfl_down_f32, 0x1f,
  103. unsigned int);
  104. __MAKE_SHUFFLES(__shfl_xor, __nvvm_shfl_bfly_i32, __nvvm_shfl_bfly_f32, 0x1f,
  105. int);
  106. #pragma pop_macro("__MAKE_SHUFFLES")
  107. #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
  108. #if CUDA_VERSION >= 9000
  109. #if (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300)
  110. // __shfl_sync_* variants available in CUDA-9
  111. #pragma push_macro("__MAKE_SYNC_SHUFFLES")
  112. #define __MAKE_SYNC_SHUFFLES(__FnName, __IntIntrinsic, __FloatIntrinsic, \
  113. __Mask, __Type) \
  114. inline __device__ int __FnName(unsigned int __mask, int __val, \
  115. __Type __offset, int __width = warpSize) { \
  116. return __IntIntrinsic(__mask, __val, __offset, \
  117. ((warpSize - __width) << 8) | (__Mask)); \
  118. } \
  119. inline __device__ float __FnName(unsigned int __mask, float __val, \
  120. __Type __offset, int __width = warpSize) { \
  121. return __FloatIntrinsic(__mask, __val, __offset, \
  122. ((warpSize - __width) << 8) | (__Mask)); \
  123. } \
  124. inline __device__ unsigned int __FnName(unsigned int __mask, \
  125. unsigned int __val, __Type __offset, \
  126. int __width = warpSize) { \
  127. return static_cast<unsigned int>( \
  128. ::__FnName(__mask, static_cast<int>(__val), __offset, __width)); \
  129. } \
  130. inline __device__ long long __FnName(unsigned int __mask, long long __val, \
  131. __Type __offset, \
  132. int __width = warpSize) { \
  133. struct __Bits { \
  134. int __a, __b; \
  135. }; \
  136. _Static_assert(sizeof(__val) == sizeof(__Bits)); \
  137. _Static_assert(sizeof(__Bits) == 2 * sizeof(int)); \
  138. __Bits __tmp; \
  139. memcpy(&__val, &__tmp, sizeof(__val)); \
  140. __tmp.__a = ::__FnName(__mask, __tmp.__a, __offset, __width); \
  141. __tmp.__b = ::__FnName(__mask, __tmp.__b, __offset, __width); \
  142. long long __ret; \
  143. memcpy(&__ret, &__tmp, sizeof(__tmp)); \
  144. return __ret; \
  145. } \
  146. inline __device__ unsigned long long __FnName( \
  147. unsigned int __mask, unsigned long long __val, __Type __offset, \
  148. int __width = warpSize) { \
  149. return static_cast<unsigned long long>(::__FnName( \
  150. __mask, static_cast<unsigned long long>(__val), __offset, __width)); \
  151. } \
  152. inline __device__ long __FnName(unsigned int __mask, long __val, \
  153. __Type __offset, int __width = warpSize) { \
  154. _Static_assert(sizeof(long) == sizeof(long long) || \
  155. sizeof(long) == sizeof(int)); \
  156. if (sizeof(long) == sizeof(long long)) { \
  157. return static_cast<long>(::__FnName( \
  158. __mask, static_cast<long long>(__val), __offset, __width)); \
  159. } else if (sizeof(long) == sizeof(int)) { \
  160. return static_cast<long>( \
  161. ::__FnName(__mask, static_cast<int>(__val), __offset, __width)); \
  162. } \
  163. } \
  164. inline __device__ unsigned long __FnName( \
  165. unsigned int __mask, unsigned long __val, __Type __offset, \
  166. int __width = warpSize) { \
  167. return static_cast<unsigned long>( \
  168. ::__FnName(__mask, static_cast<long>(__val), __offset, __width)); \
  169. } \
  170. inline __device__ double __FnName(unsigned int __mask, double __val, \
  171. __Type __offset, int __width = warpSize) { \
  172. long long __tmp; \
  173. _Static_assert(sizeof(__tmp) == sizeof(__val)); \
  174. memcpy(&__tmp, &__val, sizeof(__val)); \
  175. __tmp = ::__FnName(__mask, __tmp, __offset, __width); \
  176. double __ret; \
  177. memcpy(&__ret, &__tmp, sizeof(__ret)); \
  178. return __ret; \
  179. }
  180. __MAKE_SYNC_SHUFFLES(__shfl_sync, __nvvm_shfl_sync_idx_i32,
  181. __nvvm_shfl_sync_idx_f32, 0x1f, int);
  182. // We use 0 rather than 31 as our mask, because shfl.up applies to lanes >=
  183. // maxLane.
  184. __MAKE_SYNC_SHUFFLES(__shfl_up_sync, __nvvm_shfl_sync_up_i32,
  185. __nvvm_shfl_sync_up_f32, 0, unsigned int);
  186. __MAKE_SYNC_SHUFFLES(__shfl_down_sync, __nvvm_shfl_sync_down_i32,
  187. __nvvm_shfl_sync_down_f32, 0x1f, unsigned int);
  188. __MAKE_SYNC_SHUFFLES(__shfl_xor_sync, __nvvm_shfl_sync_bfly_i32,
  189. __nvvm_shfl_sync_bfly_f32, 0x1f, int);
  190. #pragma pop_macro("__MAKE_SYNC_SHUFFLES")
  191. inline __device__ void __syncwarp(unsigned int mask = 0xffffffff) {
  192. return __nvvm_bar_warp_sync(mask);
  193. }
  194. inline __device__ void __barrier_sync(unsigned int id) {
  195. __nvvm_barrier_sync(id);
  196. }
  197. inline __device__ void __barrier_sync_count(unsigned int id,
  198. unsigned int count) {
  199. __nvvm_barrier_sync_cnt(id, count);
  200. }
  201. inline __device__ int __all_sync(unsigned int mask, int pred) {
  202. return __nvvm_vote_all_sync(mask, pred);
  203. }
  204. inline __device__ int __any_sync(unsigned int mask, int pred) {
  205. return __nvvm_vote_any_sync(mask, pred);
  206. }
  207. inline __device__ int __uni_sync(unsigned int mask, int pred) {
  208. return __nvvm_vote_uni_sync(mask, pred);
  209. }
  210. inline __device__ unsigned int __ballot_sync(unsigned int mask, int pred) {
  211. return __nvvm_vote_ballot_sync(mask, pred);
  212. }
  213. inline __device__ unsigned int __activemask() { return __nvvm_vote_ballot(1); }
  214. inline __device__ unsigned int __fns(unsigned mask, unsigned base, int offset) {
  215. return __nvvm_fns(mask, base, offset);
  216. }
  217. #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 300
  218. // Define __match* builtins CUDA-9 headers expect to see.
  219. #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700
  220. inline __device__ unsigned int __match32_any_sync(unsigned int mask,
  221. unsigned int value) {
  222. return __nvvm_match_any_sync_i32(mask, value);
  223. }
  224. inline __device__ unsigned long long
  225. __match64_any_sync(unsigned int mask, unsigned long long value) {
  226. return __nvvm_match_any_sync_i64(mask, value);
  227. }
  228. inline __device__ unsigned int
  229. __match32_all_sync(unsigned int mask, unsigned int value, int *pred) {
  230. return __nvvm_match_all_sync_i32p(mask, value, pred);
  231. }
  232. inline __device__ unsigned long long
  233. __match64_all_sync(unsigned int mask, unsigned long long value, int *pred) {
  234. return __nvvm_match_all_sync_i64p(mask, value, pred);
  235. }
  236. #include "crt/sm_70_rt.hpp"
  237. #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 700
  238. #endif // __CUDA_VERSION >= 9000
  239. // sm_32 intrinsics: __ldg and __funnelshift_{l,lc,r,rc}.
  240. // Prevent the vanilla sm_32 intrinsics header from being included.
  241. #define __SM_32_INTRINSICS_H__
  242. #define __SM_32_INTRINSICS_HPP__
  243. #if !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 320
  244. inline __device__ char __ldg(const char *ptr) { return __nvvm_ldg_c(ptr); }
  245. inline __device__ short __ldg(const short *ptr) { return __nvvm_ldg_s(ptr); }
  246. inline __device__ int __ldg(const int *ptr) { return __nvvm_ldg_i(ptr); }
  247. inline __device__ long __ldg(const long *ptr) { return __nvvm_ldg_l(ptr); }
  248. inline __device__ long long __ldg(const long long *ptr) {
  249. return __nvvm_ldg_ll(ptr);
  250. }
  251. inline __device__ unsigned char __ldg(const unsigned char *ptr) {
  252. return __nvvm_ldg_uc(ptr);
  253. }
  254. inline __device__ unsigned short __ldg(const unsigned short *ptr) {
  255. return __nvvm_ldg_us(ptr);
  256. }
  257. inline __device__ unsigned int __ldg(const unsigned int *ptr) {
  258. return __nvvm_ldg_ui(ptr);
  259. }
  260. inline __device__ unsigned long __ldg(const unsigned long *ptr) {
  261. return __nvvm_ldg_ul(ptr);
  262. }
  263. inline __device__ unsigned long long __ldg(const unsigned long long *ptr) {
  264. return __nvvm_ldg_ull(ptr);
  265. }
  266. inline __device__ float __ldg(const float *ptr) { return __nvvm_ldg_f(ptr); }
  267. inline __device__ double __ldg(const double *ptr) { return __nvvm_ldg_d(ptr); }
  268. inline __device__ char2 __ldg(const char2 *ptr) {
  269. typedef char c2 __attribute__((ext_vector_type(2)));
  270. // We can assume that ptr is aligned at least to char2's alignment, but the
  271. // load will assume that ptr is aligned to char2's alignment. This is only
  272. // safe if alignof(c2) <= alignof(char2).
  273. c2 rv = __nvvm_ldg_c2(reinterpret_cast<const c2 *>(ptr));
  274. char2 ret;
  275. ret.x = rv[0];
  276. ret.y = rv[1];
  277. return ret;
  278. }
  279. inline __device__ char4 __ldg(const char4 *ptr) {
  280. typedef char c4 __attribute__((ext_vector_type(4)));
  281. c4 rv = __nvvm_ldg_c4(reinterpret_cast<const c4 *>(ptr));
  282. char4 ret;
  283. ret.x = rv[0];
  284. ret.y = rv[1];
  285. ret.z = rv[2];
  286. ret.w = rv[3];
  287. return ret;
  288. }
  289. inline __device__ short2 __ldg(const short2 *ptr) {
  290. typedef short s2 __attribute__((ext_vector_type(2)));
  291. s2 rv = __nvvm_ldg_s2(reinterpret_cast<const s2 *>(ptr));
  292. short2 ret;
  293. ret.x = rv[0];
  294. ret.y = rv[1];
  295. return ret;
  296. }
  297. inline __device__ short4 __ldg(const short4 *ptr) {
  298. typedef short s4 __attribute__((ext_vector_type(4)));
  299. s4 rv = __nvvm_ldg_s4(reinterpret_cast<const s4 *>(ptr));
  300. short4 ret;
  301. ret.x = rv[0];
  302. ret.y = rv[1];
  303. ret.z = rv[2];
  304. ret.w = rv[3];
  305. return ret;
  306. }
  307. inline __device__ int2 __ldg(const int2 *ptr) {
  308. typedef int i2 __attribute__((ext_vector_type(2)));
  309. i2 rv = __nvvm_ldg_i2(reinterpret_cast<const i2 *>(ptr));
  310. int2 ret;
  311. ret.x = rv[0];
  312. ret.y = rv[1];
  313. return ret;
  314. }
  315. inline __device__ int4 __ldg(const int4 *ptr) {
  316. typedef int i4 __attribute__((ext_vector_type(4)));
  317. i4 rv = __nvvm_ldg_i4(reinterpret_cast<const i4 *>(ptr));
  318. int4 ret;
  319. ret.x = rv[0];
  320. ret.y = rv[1];
  321. ret.z = rv[2];
  322. ret.w = rv[3];
  323. return ret;
  324. }
  325. inline __device__ longlong2 __ldg(const longlong2 *ptr) {
  326. typedef long long ll2 __attribute__((ext_vector_type(2)));
  327. ll2 rv = __nvvm_ldg_ll2(reinterpret_cast<const ll2 *>(ptr));
  328. longlong2 ret;
  329. ret.x = rv[0];
  330. ret.y = rv[1];
  331. return ret;
  332. }
  333. inline __device__ uchar2 __ldg(const uchar2 *ptr) {
  334. typedef unsigned char uc2 __attribute__((ext_vector_type(2)));
  335. uc2 rv = __nvvm_ldg_uc2(reinterpret_cast<const uc2 *>(ptr));
  336. uchar2 ret;
  337. ret.x = rv[0];
  338. ret.y = rv[1];
  339. return ret;
  340. }
  341. inline __device__ uchar4 __ldg(const uchar4 *ptr) {
  342. typedef unsigned char uc4 __attribute__((ext_vector_type(4)));
  343. uc4 rv = __nvvm_ldg_uc4(reinterpret_cast<const uc4 *>(ptr));
  344. uchar4 ret;
  345. ret.x = rv[0];
  346. ret.y = rv[1];
  347. ret.z = rv[2];
  348. ret.w = rv[3];
  349. return ret;
  350. }
  351. inline __device__ ushort2 __ldg(const ushort2 *ptr) {
  352. typedef unsigned short us2 __attribute__((ext_vector_type(2)));
  353. us2 rv = __nvvm_ldg_us2(reinterpret_cast<const us2 *>(ptr));
  354. ushort2 ret;
  355. ret.x = rv[0];
  356. ret.y = rv[1];
  357. return ret;
  358. }
  359. inline __device__ ushort4 __ldg(const ushort4 *ptr) {
  360. typedef unsigned short us4 __attribute__((ext_vector_type(4)));
  361. us4 rv = __nvvm_ldg_us4(reinterpret_cast<const us4 *>(ptr));
  362. ushort4 ret;
  363. ret.x = rv[0];
  364. ret.y = rv[1];
  365. ret.z = rv[2];
  366. ret.w = rv[3];
  367. return ret;
  368. }
  369. inline __device__ uint2 __ldg(const uint2 *ptr) {
  370. typedef unsigned int ui2 __attribute__((ext_vector_type(2)));
  371. ui2 rv = __nvvm_ldg_ui2(reinterpret_cast<const ui2 *>(ptr));
  372. uint2 ret;
  373. ret.x = rv[0];
  374. ret.y = rv[1];
  375. return ret;
  376. }
  377. inline __device__ uint4 __ldg(const uint4 *ptr) {
  378. typedef unsigned int ui4 __attribute__((ext_vector_type(4)));
  379. ui4 rv = __nvvm_ldg_ui4(reinterpret_cast<const ui4 *>(ptr));
  380. uint4 ret;
  381. ret.x = rv[0];
  382. ret.y = rv[1];
  383. ret.z = rv[2];
  384. ret.w = rv[3];
  385. return ret;
  386. }
  387. inline __device__ ulonglong2 __ldg(const ulonglong2 *ptr) {
  388. typedef unsigned long long ull2 __attribute__((ext_vector_type(2)));
  389. ull2 rv = __nvvm_ldg_ull2(reinterpret_cast<const ull2 *>(ptr));
  390. ulonglong2 ret;
  391. ret.x = rv[0];
  392. ret.y = rv[1];
  393. return ret;
  394. }
  395. inline __device__ float2 __ldg(const float2 *ptr) {
  396. typedef float f2 __attribute__((ext_vector_type(2)));
  397. f2 rv = __nvvm_ldg_f2(reinterpret_cast<const f2 *>(ptr));
  398. float2 ret;
  399. ret.x = rv[0];
  400. ret.y = rv[1];
  401. return ret;
  402. }
  403. inline __device__ float4 __ldg(const float4 *ptr) {
  404. typedef float f4 __attribute__((ext_vector_type(4)));
  405. f4 rv = __nvvm_ldg_f4(reinterpret_cast<const f4 *>(ptr));
  406. float4 ret;
  407. ret.x = rv[0];
  408. ret.y = rv[1];
  409. ret.z = rv[2];
  410. ret.w = rv[3];
  411. return ret;
  412. }
  413. inline __device__ double2 __ldg(const double2 *ptr) {
  414. typedef double d2 __attribute__((ext_vector_type(2)));
  415. d2 rv = __nvvm_ldg_d2(reinterpret_cast<const d2 *>(ptr));
  416. double2 ret;
  417. ret.x = rv[0];
  418. ret.y = rv[1];
  419. return ret;
  420. }
  421. // TODO: Implement these as intrinsics, so the backend can work its magic on
  422. // these. Alternatively, we could implement these as plain C and try to get
  423. // llvm to recognize the relevant patterns.
  424. inline __device__ unsigned __funnelshift_l(unsigned low32, unsigned high32,
  425. unsigned shiftWidth) {
  426. unsigned result;
  427. asm("shf.l.wrap.b32 %0, %1, %2, %3;"
  428. : "=r"(result)
  429. : "r"(low32), "r"(high32), "r"(shiftWidth));
  430. return result;
  431. }
  432. inline __device__ unsigned __funnelshift_lc(unsigned low32, unsigned high32,
  433. unsigned shiftWidth) {
  434. unsigned result;
  435. asm("shf.l.clamp.b32 %0, %1, %2, %3;"
  436. : "=r"(result)
  437. : "r"(low32), "r"(high32), "r"(shiftWidth));
  438. return result;
  439. }
  440. inline __device__ unsigned __funnelshift_r(unsigned low32, unsigned high32,
  441. unsigned shiftWidth) {
  442. unsigned result;
  443. asm("shf.r.wrap.b32 %0, %1, %2, %3;"
  444. : "=r"(result)
  445. : "r"(low32), "r"(high32), "r"(shiftWidth));
  446. return result;
  447. }
  448. inline __device__ unsigned __funnelshift_rc(unsigned low32, unsigned high32,
  449. unsigned shiftWidth) {
  450. unsigned ret;
  451. asm("shf.r.clamp.b32 %0, %1, %2, %3;"
  452. : "=r"(ret)
  453. : "r"(low32), "r"(high32), "r"(shiftWidth));
  454. return ret;
  455. }
  456. #endif // !defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 320
  457. #endif // defined(__CLANG_CUDA_INTRINSICS_H__)