Thread (1 message) 1 message, 1 author, 2024-09-04

Re: [PATCH 2/2] refs/files: use heuristic to decide whether to repack with `--auto`

From: Junio C Hamano <hidden>
Date: 2024-09-04 16:15:11

Patrick Steinhardt [off-list ref] writes:
In any case, GCC is clever enough to notice what we're doing:

    fastlog2(unsigned long):
            xor     eax, eax
            test    rdi, rdi
            je      .L5
            bsr     rax, rdi
    .L5:
            ret
Nice.  Aiming to compile to "bsr" is very good.
So with the following definition we're optimizing both with GCC and
Clang:

    size_t fastlog2(size_t sz)
    {
        size_t l = 0;
        if (!sz)
            return 0;
        for (; sz; sz >>= 1)
            l++;
        return l;
    }

I'd thus say we can just pick that function instead of caring about
platform endianess with `ffs()`.
The above loop that compilers seem to know to reduce to "bsr" is
good.

FWIW, because the definition of "first bit" in ffs() is "least
significant bit", you do not need to worry about endianness at all,
but what we want is most significant, so it is not directly usable.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help