public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-688] libgcc: use __builtin_clz and __builtin_ctz in libbid
@ 2022-05-20  7:36 Christophe Lyon
  0 siblings, 0 replies; only message in thread
From: Christophe Lyon @ 2022-05-20  7:36 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5143faee0d0edfd5849c5f54677cb699bf84a5db

commit r13-688-g5143faee0d0edfd5849c5f54677cb699bf84a5db
Author: Christophe Lyon <christophe.lyon@arm.com>
Date:   Thu May 5 09:25:14 2022 +0100

    libgcc: use __builtin_clz and __builtin_ctz in libbid
    
    This patch replaces libbid's implementations of clz and ctz for 32 and
    64 bits inputs which used several masks, and switches to the
    corresponding builtins. This will provide a better implementation,
    especially on targets with clz/ctz instructions.
    
    2022-05-06  Christophe Lyon  <christophe.lyon@arm.com>
    
    libgcc/config/libbid/ChangeLog:
    
            * bid_binarydecimal.c (CLZ32_MASK16): Delete.
            (CLZ32_MASK8): Delete.
            (CLZ32_MASK4): Delete.
            (CLZ32_MASK2): Delete.
            (CLZ32_MASK1): Delete.
            (clz32_nz): Use __builtin_clz.
            (ctz32_1bit): Delete.
            (ctz32): Use __builtin_ctz.
            (CLZ64_MASK32): Delete.
            (CLZ64_MASK16): Delete.
            (CLZ64_MASK8): Delete.
            (CLZ64_MASK4): Delete.
            (CLZ64_MASK2): Delete.
            (CLZ64_MASK1): Delete.
            (clz64_nz): Use __builtin_clzl.
            (ctz64_1bit): Delete.
            (ctz64): Use __builtin_ctzl.

Diff:
---
 libgcc/config/libbid/bid_binarydecimal.c | 51 +++-----------------------------
 1 file changed, 4 insertions(+), 47 deletions(-)

diff --git a/libgcc/config/libbid/bid_binarydecimal.c b/libgcc/config/libbid/bid_binarydecimal.c
index e156ea60d11..5413acceeaf 100644
--- a/libgcc/config/libbid/bid_binarydecimal.c
+++ b/libgcc/config/libbid/bid_binarydecimal.c
@@ -26,65 +26,22 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 // Counting leading zeros in an unsigned 32-bit word
 // The "_nz" version will return the wrong answer (31) for zero inputs
 
-#define CLZ32_MASK16 0xFFFF0000ul
-#define CLZ32_MASK8  0xFF00FF00ul
-#define CLZ32_MASK4  0xF0F0F0F0ul
-#define CLZ32_MASK2  0xCCCCCCCCul
-#define CLZ32_MASK1  0xAAAAAAAAul
-
-#define clz32_nz(n)                                             \
- (((((n) & CLZ32_MASK16) <= ((n) & ~CLZ32_MASK16)) ? 16 : 0) +  \
-  ((((n) & CLZ32_MASK8) <= ((n) & ~CLZ32_MASK8)) ? 8 : 0) +     \
-  ((((n) & CLZ32_MASK4) <= ((n) & ~CLZ32_MASK4)) ? 4 : 0) +     \
-  ((((n) & CLZ32_MASK2) <= ((n) & ~CLZ32_MASK2)) ? 2 : 0) +     \
-  ((((n) & CLZ32_MASK1) <= ((n) & ~CLZ32_MASK1)) ? 1 : 0))
-
+#define clz32_nz(n) (__builtin_clz (n))
 #define clz32(n) (((n)==0) ? 32 : clz32_nz(n))
 
 // Counting trailing zeros in an unsigned 32-bit word
-// The ctz32_1bit version is for a single bit
-
-#define ctz32_1bit(n)                                           \
- ((((n) & ~CLZ32_MASK16) ? 0 : 16) +                            \
-  (((n) & ~CLZ32_MASK8) ? 0 : 8) +                              \
-  (((n) & ~CLZ32_MASK4) ? 0 : 4) +                              \
-  (((n) & ~CLZ32_MASK2) ? 0 : 2) +                              \
-  (((n) & ~CLZ32_MASK1) ? 0 : 1))
+#define ctz32(n) (__builtin_ctz (n))
 
-#define ctz32(n) (((n) == 0) ? 32 : ctz32_1bit((n) & -(n)))
 
 // Counting leading zeros in an unsigned 64-bit word
 // The "_nz" version will return the wrong answer (63) for zero inputs
 
-#define CLZ64_MASK32 0xFFFFFFFF00000000ull
-#define CLZ64_MASK16 0xFFFF0000FFFF0000ull
-#define CLZ64_MASK8  0xFF00FF00FF00FF00ull
-#define CLZ64_MASK4  0xF0F0F0F0F0F0F0F0ull
-#define CLZ64_MASK2  0xCCCCCCCCCCCCCCCCull
-#define CLZ64_MASK1  0xAAAAAAAAAAAAAAAAull
-
-#define clz64_nz(n)                                             \
- (((((n) & CLZ64_MASK32) <= ((n) & ~CLZ64_MASK32)) ? 32 : 0) +  \
-  ((((n) & CLZ64_MASK16) <= ((n) & ~CLZ64_MASK16)) ? 16 : 0) +  \
-  ((((n) & CLZ64_MASK8) <= ((n) & ~CLZ64_MASK8)) ? 8 : 0) +     \
-  ((((n) & CLZ64_MASK4) <= ((n) & ~CLZ64_MASK4)) ? 4 : 0) +     \
-  ((((n) & CLZ64_MASK2) <= ((n) & ~CLZ64_MASK2)) ? 2 : 0) +     \
-  ((((n) & CLZ64_MASK1) <= ((n) & ~CLZ64_MASK1)) ? 1 : 0))      \
-
+#define clz64_nz(n) ( (__SIZEOF_LONG__ == 8) ?__builtin_clzl(n) : __builtin_clzll(n) )
 #define clz64(n) (((n)==0) ? 64 : clz64_nz(n))
 
 // Counting trailing zeros in an unsigned 64-bit word
-// The ctz64_1bit version is for a single bit
-
-#define ctz64_1bit(n)                                           \
- ((((n) & ~CLZ64_MASK32) ? 0 : 32) +                            \
-  (((n) & ~CLZ64_MASK16) ? 0 : 16) +                            \
-  (((n) & ~CLZ64_MASK8) ? 0 : 8) +                              \
-  (((n) & ~CLZ64_MASK4) ? 0 : 4) +                              \
-  (((n) & ~CLZ64_MASK2) ? 0 : 2) +                              \
-  (((n) & ~CLZ64_MASK1) ? 0 : 1))
+#define ctz64(n) ( (__SIZEOF_LONG__ == 8) ?__builtin_ctzl(n) : __builtin_ctzll(n) )
 
-#define ctz64(n) (((n) == 0) ? 64 : ctz64_1bit((n) & -(n)))
 
 // Counting leading zeros in an unsigned 2-part 128-bit word


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-20  7:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20  7:36 [gcc r13-688] libgcc: use __builtin_clz and __builtin_ctz in libbid Christophe Lyon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).