[PATCH] x86_64: Optimize ffsll function code size.
Andrew Pinski
pinskia@gmail.com
Wed Jul 26 17:25:27 GMT 2023
On Wed, Jul 26, 2023 at 10:05 AM Noah Goldstein via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> On Wed, Jul 26, 2023 at 11:06 AM Sunil K Pandey via Libc-alpha
> <libc-alpha@sourceware.org> 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. */
> > : "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1));
> >
> Note, there is technically a "bug" in this code in that we clobber
> "cc" but don't
> specify so.
> Mightly as well fix that.
On x86, flags/cc is always considered as clobbered by inline-asm.
ix86_md_asm_adjust will add the clobber if there was no asm flags output.
Thanks,
Andrew Pinski
> > return cnt + 1;
> > --
> > 2.41.0
> >
More information about the Libc-alpha
mailing list