]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify 32-bit Android bit fiddling
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 12 May 2024 21:26:32 +0000 (14:26 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sat, 18 May 2024 19:12:39 +0000 (21:12 +0200)
* 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)

src/sfnt.c

index d909fba7677ddc7671f1cee8029bdffea9ffe55f..1832082e4f9de8c2ed72497ecba12ce31eeef8af 100644 (file)
@@ -27,6 +27,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #include <intprops.h>
 #include <inttypes.h>
+#include <stdbit.h>
 #include <stdckdint.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -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;