diff --git a/libcudacxx/include/cuda/std/__cccl/attributes.h b/libcudacxx/include/cuda/std/__cccl/attributes.h index a5888cc289..79f9cadbdc 100644 --- a/libcudacxx/include/cuda/std/__cccl/attributes.h +++ b/libcudacxx/include/cuda/std/__cccl/attributes.h @@ -134,4 +134,10 @@ # define _CCCL_RESTRICT __restrict__ #endif // ^^^ !_CCCL_COMPILER(MSVC) ^^^ +#if _CCCL_HAS_CPP_ATTRIBUTE(assume) +# define _CCCL_ASSUME(...) [[assume(__VA_ARGS__)]] +#else // ^^^ _CCCL_COMPILER(MSVC) ^^^ / vvv !_CCCL_COMPILER(MSVC) vvv +# define _CCCL_ASSUME(...) _CCCL_BUILTIN_ASSUME(__VA_ARGS__) +#endif // ^^^ !_CCCL_COMPILER(MSVC) ^^^ + #endif // __CCCL_ATTRIBUTES_H diff --git a/libcudacxx/include/cuda/std/__cccl/builtin.h b/libcudacxx/include/cuda/std/__cccl/builtin.h index 3a5fda2f0f..7442a6b85e 100644 --- a/libcudacxx/include/cuda/std/__cccl/builtin.h +++ b/libcudacxx/include/cuda/std/__cccl/builtin.h @@ -101,8 +101,14 @@ # define _CCCL_BUILTIN_ADDRESSOF(...) __builtin_addressof(__VA_ARGS__) #endif // _CCCL_CHECK_BUILTIN(builtin_addressof) -#if _CCCL_CHECK_BUILTIN(builtin_assume) +#if _CCCL_CHECK_BUILTIN(builtin_assume) || _CCCL_COMPILER(CLANG) || _CCCL_COMPILER(NVHPC) # define _CCCL_BUILTIN_ASSUME(...) __builtin_assume(__VA_ARGS__) +#elif _CCCL_COMPILER(GCC, >=, 13) +# define _CCCL_BUILTIN_ASSUME(...) \ + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (__builtin_assume(__VA_ARGS__);), (__attribute__((__assume__(__VA_ARGS__)));)) +#elif _CCCL_COMPILER(MSVC) +# define _CCCL_BUILTIN_ASSUME(...) \ + NV_IF_ELSE_TARGET(NV_IS_DEVICE, (__builtin_assume(__VA_ARGS__);), (__assume(__VA_ARGS__);)) #endif // _CCCL_CHECK_BUILTIN(builtin_assume) // NVCC prior to 11.2 cannot handle __builtin_assume