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.
Unified · Split
| @@ -178,11 +178,14 @@ static inline unsigned int stdc_trailing_zeros_uc(unsigned char value) · 177 unmodified lines | ||
| 178 | 178 | static inline unsigned int __stdc_trailing_zeros(unsigned long long value, |
| 179 | 179 | unsigned int size) |
| 180 | 180 | { |
| 181 | − unsigned int zeros = size * CHAR_BIT; | |
| 181 | + unsigned int zeros = 0; | |
| 182 | 182 | |
| 183 | − while (value != 0) { | |
| 184 | − value <<= 1; | |
| 185 | − zeros--; | |
| 183 | + if (!value) | |
| 184 | + return size * CHAR_BIT; | |
| 185 | + | |
| 186 | + while ((value & 1) == 0) { | |
| 187 | + value >>= 1; | |
| 188 | + zeros++; | |
| 186 | 189 | } |
| 187 | 190 | |
| 188 | 191 | return zeros; |