History

compat: Fix the fallback definition of stdc_trailing_zeros

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.

Martin Storsjö committed 2 years ago

Commit b4d9fa61 parent e18b46d1 file · +7 −4Browse files

Unified · Split

compat/stdbit/stdbit.h+7−4
@@ -178,11 +178,14 @@ static inline unsigned int stdc_trailing_zeros_uc(unsigned char value) · 177 unmodified lines
178static inline unsigned int __stdc_trailing_zeros(unsigned long long value,178static 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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t