Skip to content

Commit

Permalink
optimize __is_arithmetic_integral
Browse files Browse the repository at this point in the history
  • Loading branch information
davebayer committed Jan 20, 2025
1 parent 708597b commit 6a84fa9
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions libcudacxx/include/cuda/std/__type_traits/is_arithmetic_integral.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if defined(_CCCL_NO_VARIABLE_TEMPLATES)

template <class _Tp>
struct __is_arithmetic_integral_impl : public false_type
{};
Expand Down Expand Up @@ -57,24 +59,67 @@ struct __is_arithmetic_integral_impl<long long> : public true_type
template <>
struct __is_arithmetic_integral_impl<unsigned long long> : public true_type
{};
#ifndef _LIBCUDACXX_HAS_NO_INT128
# if !defined(_LIBCUDACXX_HAS_NO_INT128)
template <>
struct __is_arithmetic_integral_impl<__int128_t> : public true_type
{};
template <>
struct __is_arithmetic_integral_impl<__uint128_t> : public true_type
{};
#endif
# endif // !_LIBCUDACXX_HAS_NO_INT128

template <class _Tp>
struct _CCCL_TYPE_VISIBILITY_DEFAULT __is_arithmetic_integral
: public integral_constant<bool, __is_arithmetic_integral_impl<remove_cv_t<_Tp>>::value>
{};

#if !defined(_CCCL_NO_VARIABLE_TEMPLATES)
#else // ^^^ _CCCL_NO_VARIABLE_TEMPLATES ^^^ / vvv !_CCCL_NO_VARIABLE_TEMPLATES vvv

template <class _Tp>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v = __is_arithmetic_integral<_Tp>::value;
#endif // !_CCCL_NO_VARIABLE_TEMPLATES
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl = false;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<signed char> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<unsigned char> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<short> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<unsigned short> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<int> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<unsigned int> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<long> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<unsigned long> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<long long> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<unsigned long long> = true;

# if !defined(_LIBCUDACXX_HAS_NO_INT128)
template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<__int128_t> = true;

template <>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v_impl<__uint128_t> = true;
# endif // !_LIBCUDACXX_HAS_NO_INT128

template <class _Tp>
_CCCL_INLINE_VAR constexpr bool __is_arithmetic_integral_v = __is_arithmetic_integral_v_impl<remove_cv_t<_Tp>>;

#endif // ^^^ !_CCCL_NO_VARIABLE_TEMPLATES ^^^

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down

0 comments on commit 6a84fa9

Please sign in to comment.