[Bug target/126973] __builtin_clzg could be improved by using bsrw rather than bsrl or using a shift rather than an and/sub

"pinskia at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126973

Drea Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Worse X86 codegen for       |__builtin_clzg  could be
                   |arbitrary                   |improved by using bsrw
                   |__builtin_clzg/__builtin_ct |rather than bsrl or using a
                   |zg compared to clang.       |shift rather than an
                   |                            |and/sub
           Severity|normal                      |enhancement
         Resolution|DUPLICATE                   |---
           Keywords|ABI                         |
   Last reconfirmed|                            |2026-08-21
             Status|RESOLVED                    |NEW
     Ever confirmed|0                           |1

--- Comment #3 from Drea Pinski <pinskia at gcc dot gnu.org> ---
Well __builtin_clzg   could be improved slightly by using bsrw rather than
bsrl.

You could do also a shift for __builtin_clzg  too.

But that is not always better:
https://godbolt.org/z/7hbcnGq9E
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.