From: Paul Eggert Date: Sun, 12 May 2024 21:26:32 +0000 (-0700) Subject: Simplify 32-bit Android bit fiddling X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=055e008641df0d1acc8fdc83eb204a14e03a2194;p=emacs.git 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. (cherry picked from commit 21ed391440ec9c227f3d18cc222aab2d3d0f9e14) --- 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 @@ along with GNU Emacs. If not, see . */ #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;