MCPcopy Create free account
hub / github.com/NVIDIA/cutlass / bit_width

Function bit_width

include/cute/numeric/math.hpp:145–160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143// bit_width( 0b0111 ) = 3
144template <class T>
145CUTE_HOST_DEVICE constexpr
146int
147bit_width(T x) {
148 static_assert(is_unsigned<T>::value, "Only to be used for unsigned types.");
149 constexpr int N = (numeric_limits<T>::digits == 64 ? 6 :
150 (numeric_limits<T>::digits == 32 ? 5 :
151 (numeric_limits<T>::digits == 16 ? 4 :
152 (numeric_limits<T>::digits == 8 ? 3 : (assert(false),0)))));
153 T r = 0;
154 for (int i = N - 1; i >= 0; --i) {
155 T shift = (x > ((T(1) << (T(1) << i))-1)) << i;
156 x >>= shift;
157 r |= shift;
158 }
159 return r + (x != 0);
160}
161
162// Smallest integral power of two not less than the given value
163// bit_ceil( 0b00000000 ) = 0b00000001

Callers 7

upcastFunction · 0.85
downcastFunction · 0.85
bit_ceilFunction · 0.85
bit_floorFunction · 0.85
countl_zeroFunction · 0.85
countr_zeroFunction · 0.85
log_2Function · 0.85

Calls 1

TClass · 0.85

Tested by

no test coverage detected