[PATCH v2 08/32] mpi: Declare the clz table at the top of longlong.h as __clz_tab.

Matt Turner mattst88 at gmail.com
Wed Nov 25 21:19:45 CET 2026


* mpi/longlong.h (__clz_tab): New macro for _gcry_clz_tab.  Declare
it at the top of the file, as GCC does.
(attribute_hidden): New, from GCC.
(count_leading_zeros) [!count_leading_zeros]: Use __clz_tab and drop
the declaration of _gcry_clz_tab.

--

GCC's copy of longlong.h declares the table as __clz_tab at the top of
the file, so that CPU-specific code can use it too.  Do the same, under
Libgcrypt's name, so that the Alpha count_leading_zeros from GCC can
be taken as is.

Signed-off-by: Matt Turner <mattst88 at gmail.com>
---
 mpi/longlong.h | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/mpi/longlong.h b/mpi/longlong.h
index dc85775c..e5c4ea9f 100644
--- a/mpi/longlong.h
+++ b/mpi/longlong.h
@@ -39,6 +39,7 @@ SPDX-License-Identifier: LGPL-2.1-or-later
    UDWtype -- An unsigned type, at least twice as large a UWtype.
    W_TYPE_SIZE -- size in bits of UWtype.
 
+   UQItype -- Unsigned 8 bit type.
    SItype, USItype -- Signed and unsigned 32 bit types.
    DItype, UDItype -- Signed and unsigned 64 bit types.
 
@@ -57,6 +58,17 @@ SPDX-License-Identifier: LGPL-2.1-or-later
 # define __MPN(x) __##x
 #endif
 
+/* Libgcrypt's __clz_tab is defined in mpi-bit.c.  */
+#define __clz_tab _gcry_clz_tab
+
+/* Define attribute_hidden before including this file to give __clz_tab
+   hidden visibility.  */
+#ifndef attribute_hidden
+#define attribute_hidden
+#endif
+
+extern const UQItype __clz_tab[256] attribute_hidden;
+
 /* Define auxiliary asm macros.
 
    1) umul_ppmm(high_prod, low_prod, multipler, multiplicand) multiplies two
@@ -1544,11 +1556,6 @@ typedef unsigned int UTItype __attribute__ ((mode (TI)));
 #endif
 
 #if !defined (count_leading_zeros)
-extern
-#  ifdef __STDC__
-const
-#  endif
-unsigned char _gcry_clz_tab[];
 #  define MPI_INTERNAL_NEED_CLZ_TAB 1
 #  define count_leading_zeros(count, x) \
   do {									\
@@ -1568,7 +1575,7 @@ unsigned char _gcry_clz_tab[];
 	    break;							\
       } 								\
 									\
-    (count) = W_TYPE_SIZE - (_gcry_clz_tab[__xr >> __a] + __a);		\
+    (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a);		\
   } while (0)
 /* This version gives a well-defined value for zero. */
 #  define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE

-- 
2.56.1



More information about the Gcrypt-devel mailing list