From eee44e35c13356193a615f9cf21b5f417b421152 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 12 May 2024 14:26:32 -0700 Subject: [PATCH 2/2] Simplify 32-bit Android bit fiddling * src/sfnt.c: Include stdbit.h. (sfnt_count_leading_zero_bits) [!INT64_MAX]: Remove this function, which was confusingly named as it actually returned 31 minus the number of leading zero bits. (sfnt_multiply_divide_2) [!INT64_MAX]: Use stdc_leading_zeros instead. --- src/sfnt.c | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/src/sfnt.c b/src/sfnt.c index d909fba7677..1832082e4f9 100644 --- a/src/sfnt.c +++ b/src/sfnt.c @@ -27,6 +27,7 @@ Copyright (C) 2023-2024 Free Software Foundation, Inc. #include #include #include +#include #include #include #include @@ -3678,45 +3679,6 @@ sfnt_multiply_divide_1 (unsigned int a, unsigned int b, value->high = hi; } -/* Count the number of most significant zero bits in N. */ - -static unsigned int -sfnt_count_leading_zero_bits (unsigned int n) -{ - int shift; - - shift = 0; - - if (n & 0xffff0000ul) - { - n >>= 16; - shift += 16; - } - - if (n & 0x0000ff00ul) - { - n >>= 8; - shift += 8; - } - - if (n & 0x000000f0ul) - { - n >>= 4; - shift += 4; - } - - if (n & 0x0000000cul) - { - n >>= 2; - shift += 2; - } - - if (n & 0x00000002ul) - shift += 1; - - return shift; -} - /* Calculate AB / C. Value is a 32 bit unsigned integer. */ static unsigned int @@ -3730,7 +3692,7 @@ sfnt_multiply_divide_2 (struct sfnt_large_integer *ab, hi = ab->high; lo = ab->low; - i = 31 - sfnt_count_leading_zero_bits (hi); + i = stdc_leading_zeros (hi); r = (hi << i) | (lo >> (32 - i)); lo <<= i; q = r / c; -- 2.44.0