[PATCH] x86_64: Optimize ffsll function code size.
H.J. Lu
hjl.tools@gmail.com
Wed Jul 26 16:50:34 GMT 2023
On Wed, Jul 26, 2023 at 9:38 AM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 7/26/23 09:05, Sunil K Pandey via Libc-alpha wrote:
> > Ffsll function size is 17 byte, this patch optimizes size to 16 byte.
> > Currently ffsll function randomly regress by ~20%, depending on how
> > code get aligned.
> >
> > This patch fixes ffsll function random performance regression.
> > ---
> > sysdeps/x86_64/ffsll.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/sysdeps/x86_64/ffsll.c b/sysdeps/x86_64/ffsll.c
> > index a1c13d4906..dbded6f0a1 100644
> > --- a/sysdeps/x86_64/ffsll.c
> > +++ b/sysdeps/x86_64/ffsll.c
> > @@ -29,7 +29,7 @@ ffsll (long long int x)
> > long long int tmp;
> >
> > asm ("bsfq %2,%0\n" /* Count low bits in X and store in %1. */
> > - "cmoveq %1,%0\n" /* If number was zero, use -1 as result. */
> > + "cmove %k1,%k0\n" /* If number was zero, use -1 as result. */
>
> This no longer produces -1, but 0xffffffff in cnt. However, since the return type is
> 'int', cnt need not be 'long long int' either. I'm not sure why tmp exists at all, since
> cnt is the only register modified.
>
>
> r~
tmp was initialized to -1 with
: "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1));
H.J.
More information about the Libc-alpha
mailing list