While shifting "value" to left, we would iterate through all bits of an unsigned long long, while we only expect to count through "size * CHAR_BIT" bits; instead shift bits to the right and just count the trailing zeros. This fixes fate with MSVC.
Showing the changes to compat/stdbit (1 of 1 file). Show all
Unified · Split
| @@ -178,11 +178,14 @@ static inline unsigned int stdc_trailing_zeros_uc(unsigned char value) · 177 unmodified lines | |||
| 178 | static inline unsigned int __stdc_trailing_zeros(unsigned long long value, | 178 | static inline unsigned int __stdc_trailing_zeros(unsigned long long value, |
| 179 | unsigned int size) | 179 | unsigned int size) |
| 180 | { | 180 | { |
| 181 | unsigned int zeros = size * CHAR_BIT; | 181 | unsigned int zeros = 0; |
| 182 | 182 | ||
| 183 | while (value != 0) { | 183 | if (!value) |
| 184 | value <<= 1; | 184 | return size * CHAR_BIT; |
| 185 | zeros--; | 185 | |
| 186 | while ((value & 1) == 0) { | ||
| 187 | value >>= 1; | ||
| 188 | zeros++; | ||
| 186 | } | 189 | } |
| 187 | 190 | ||
| 188 | return zeros; | 191 | return zeros; |