|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION. |
| 2 | + * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
|
17 | 17 | namespace numeric { |
18 | 18 | namespace detail { |
19 | 19 |
|
20 | | -/** |
21 | | - * @brief Determine the number of significant bits in an integer |
22 | | - * |
23 | | - * @tparam T Type of input integer value. Must be either uint32_t, uint64_t, or __uint128_t |
24 | | - * @param value The integer whose bits are being counted |
25 | | - * @return The number of significant bits: the # of bits - # of leading zeroes |
26 | | - */ |
27 | | -template <typename T, |
28 | | - CUDF_ENABLE_IF(cuda::std::is_same_v<T, uint32_t> || cuda::std::is_same_v<T, uint64_t> || |
29 | | - cuda::std::is_same_v<T, __uint128_t>)> |
30 | | -CUDF_HOST_DEVICE inline constexpr int count_significant_bits(T value) |
31 | | -{ |
32 | | -#ifdef __CUDA_ARCH__ |
33 | | - if constexpr (cuda::std::is_same_v<T, uint64_t>) { |
34 | | - return 64 - __clzll(static_cast<int64_t>(value)); |
35 | | - } else if constexpr (cuda::std::is_same_v<T, uint32_t>) { |
36 | | - return 32 - __clz(static_cast<int32_t>(value)); |
37 | | - } else if constexpr (cuda::std::is_same_v<T, __uint128_t>) { |
38 | | - // 128 bit type, must break up into high and low components |
39 | | - auto const high_bits = static_cast<int64_t>(value >> 64); |
40 | | - auto const low_bits = static_cast<int64_t>(value); |
41 | | - return 128 - (__clzll(high_bits) + static_cast<int>(high_bits == 0) * __clzll(low_bits)); |
42 | | - } |
43 | | -#else |
44 | | - if constexpr (cuda::std::is_same_v<T, uint64_t>) { |
45 | | - return 64 - cuda::std::countl_zero(value); |
46 | | - } else if constexpr (cuda::std::is_same_v<T, uint32_t>) { |
47 | | - return 32 - cuda::std::countl_zero(value); |
48 | | - } else if constexpr (cuda::std::is_same_v<T, __uint128_t>) { |
49 | | - // 128 bit type, must break up into high and low components |
50 | | - auto const high_bits = static_cast<uint64_t>(value >> 64); |
51 | | - if (high_bits == 0) { |
52 | | - return 64 - cuda::std::countl_zero(static_cast<uint64_t>(value)); |
53 | | - } else { |
54 | | - return 128 - cuda::std::countl_zero(high_bits); |
55 | | - } |
56 | | - } |
57 | | -#endif |
58 | | -} |
59 | | - |
60 | 20 | /** |
61 | 21 | * @brief Helper struct for getting and setting the components of a floating-point value |
62 | 22 | * |
@@ -189,7 +149,7 @@ struct floating_converter { |
189 | 149 |
|
190 | 150 | // Line-up denormal to same (understood) bit as normal numbers |
191 | 151 | // This is so bit-shifting starts at the same bit index |
192 | | - auto const lineup_shift = num_significand_bits - count_significant_bits(significand); |
| 152 | + auto const lineup_shift = num_significand_bits - cuda::std::bit_width(significand); |
193 | 153 | significand <<= lineup_shift; |
194 | 154 | floating_pow2 -= lineup_shift; |
195 | 155 | } else { |
@@ -954,7 +914,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_pospow(DecimalRep decimal_rep, int |
954 | 914 | // except our first operation is a multiply, so not quite that far |
955 | 915 | // We are bit-shifting down, so we need extra bits on the low-side, which this has. |
956 | 916 | static constexpr int shift_up_to = sizeof(ShiftingRep) * 8 - Constants::max_bits_shift; |
957 | | - int const shift_from = count_significant_bits(decimal_rep); |
| 917 | + int const shift_from = cuda::std::bit_width(decimal_rep); |
958 | 918 | int const num_init_bit_shift = shift_up_to - shift_from; |
959 | 919 | int pow2 = -num_init_bit_shift; |
960 | 920 |
|
@@ -1017,7 +977,7 @@ CUDF_HOST_DEVICE inline auto shift_to_binary_negpow(DecimalRep decimal_rep, int |
1017 | 977 | // so that we lose minimal information we need on intermediary right-shifts. |
1018 | 978 | // Note that since we're shifting 2s up, we need num_2s_shift_buffer_bits space on the high side |
1019 | 979 | static constexpr int shift_up_to = sizeof(ShiftingRep) * 8 - Constants::num_2s_shift_buffer_bits; |
1020 | | - int const shift_from = count_significant_bits(decimal_rep); |
| 980 | + int const shift_from = cuda::std::bit_width(decimal_rep); |
1021 | 981 | int const num_init_bit_shift = shift_up_to - shift_from; |
1022 | 982 | int pow2 = -num_init_bit_shift; |
1023 | 983 |
|
|
0 commit comments