File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 31
31
32
32
#if defined(_MSC_VER )
33
33
#include <intrin.h>
34
- static inline int clz (uint32_t v )
34
+ static inline int rv_clz (uint32_t v )
35
35
{
36
36
uint32_t leading_zero = 0 ;
37
37
if (_BitScanReverse (& leading_zero , v ))
38
38
return 31 - leading_zero ;
39
39
return 32 ; /* undefined behavior */
40
40
}
41
41
#elif defined(__GNUC__ ) || defined(__clang__ )
42
- static inline int clz (uint32_t v )
42
+ static inline int rv_clz (uint32_t v )
43
43
{
44
+ /* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
45
+ /* If x is 0, the result is undefined. */
44
46
return __builtin_clz (v );
45
47
}
46
48
#else /* generic implementation */
47
- static inline int clz (uint32_t v )
49
+ static inline int rv_clz (uint32_t v )
48
50
{
49
51
/* http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn */
50
52
static const uint8_t mul_debruijn [] = {
@@ -64,10 +66,14 @@ static inline int clz(uint32_t v)
64
66
65
67
/*
66
68
* Integer log base 2
69
+ *
70
+ * The input x must not be zero.
71
+ * Otherwise, the result is undefined on some platform.
72
+ *
67
73
*/
68
74
static inline uint8_t ilog2 (uint32_t x )
69
75
{
70
- return 31 - clz (x );
76
+ return 31 - rv_clz (x );
71
77
}
72
78
73
79
/* Alignment macro */
You can’t perform that action at this time.
0 commit comments