https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93071

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
These might benefit from the same improvements (compile with -std=c++20):

#include <bit>

int i(int x) {
    return 31 - std::countl_zero((unsigned)x);
}

int j(int x) {
    return std::bit_width((unsigned)x) - 1;
}

They're currently horrible:

i(int):
        mov     eax, -1
        test    edi, edi
        je      .L5
        bsr     edi, edi
        mov     eax, 31
        xor     edi, 31
        sub     eax, edi
.L5:
        ret
j(int):
        xor     eax, eax
        test    edi, edi
        je      .L9
        bsr     edi, edi
        mov     eax, 32
        xor     edi, 31
        sub     eax, edi
.L9:
        ret

Reply via email to