public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Christophe Lyon <clyon@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-688] libgcc: use __builtin_clz and __builtin_ctz in libbid
Date: Fri, 20 May 2022 07:36:10 +0000 (GMT)	[thread overview]
Message-ID: <20220520073610.65E723857423@sourceware.org> (raw)

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


                 reply	other threads:[~2022-05-20  7:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220520073610.65E723857423@sourceware.org \
    --to=clyon@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).