File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,12 +13,37 @@ static float halfToFloat(half h);
1313
1414#ifdef _MSC_VER
1515#include < intrin.h>
16+
17+ static inline uint32_t __builtin_clz (uint32_t value) {
18+ unsigned long leading_zero = 0 ;
19+ if (value == 0 ) {
20+ return 32 ;
21+ }
22+ _BitScanReverse (&leading_zero, value);
23+ return 31 - leading_zero;
24+ }
25+
1626static inline uint16_t __builtin_clz (uint16_t value) {
27+ return __builtin_clz (static_cast <uint32_t >(value)) - 16 ;
28+ }
29+
30+ static inline uint64_t __builtin_clz (uint64_t value) {
1731 unsigned long leading_zero = 0 ;
18- if (_BitScanReverse (&leading_zero, static_cast < unsigned long >(value)) ) {
19- return 15 - leading_zero ;
32+ if (value == 0 ) {
33+ return 64 ;
2034 }
21- return 16 ;
35+ #if defined(_WIN64)
36+ _BitScanReverse64 (&leading_zero, value);
37+ return 63 - leading_zero;
38+ #else
39+ uint32_t high = static_cast <uint32_t >(value >> 32 );
40+ uint32_t low = static_cast <uint32_t >(value);
41+ if (high != 0 ) {
42+ return __builtin_clz (high);
43+ } else {
44+ return 32 + __builtin_clz (low);
45+ }
46+ #endif
2247}
2348#endif
2449
You can’t perform that action at this time.
0 commit comments