[FFmpeg-cvslog] compat: Fix the fallback definition of stdc_trailing_zeros
Martin Storsjö
git at videolan.org
Tue Sep 24 14:00:44 EEST 2024
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Tue Sep 24 11:44:19 2024 +0300| [b4d9fa6cb93a3ef8209508b2fb9cd1dc95f03090] | committer: Martin Storsjö
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.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b4d9fa6cb93a3ef8209508b2fb9cd1dc95f03090
---
compat/stdbit/stdbit.h | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/compat/stdbit/stdbit.h b/compat/stdbit/stdbit.h
index b434fc2357..53419cf9f9 100644
--- a/compat/stdbit/stdbit.h
+++ b/compat/stdbit/stdbit.h
@@ -178,11 +178,14 @@ static inline unsigned int stdc_trailing_zeros_uc(unsigned char value)
static inline unsigned int __stdc_trailing_zeros(unsigned long long value,
unsigned int size)
{
- unsigned int zeros = size * CHAR_BIT;
+ unsigned int zeros = 0;
- while (value != 0) {
- value <<= 1;
- zeros--;
+ if (!value)
+ return size * CHAR_BIT;
+
+ while ((value & 1) == 0) {
+ value >>= 1;
+ zeros++;
}
return zeros;
More information about the ffmpeg-cvslog
mailing list