mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-25 06:20:06 +00:00
9d94997b5f
Ffsll function randomly regress by ~20%, depending on how code gets aligned in memory. Ffsll function code size is 17 bytes. Since default function alignment is 16 bytes, it can load on 16, 32, 48 or 64 bytes aligned memory. When ffsll function load at 16, 32 or 64 bytes aligned memory, entire code fits in single 64 bytes cache line. When ffsll function load at 48 bytes aligned memory, it splits in two cache line, hence random regression. Ffsll function size reduction from 17 bytes to 12 bytes ensures that it will always fit in single 64 bytes cache line. This patch fixes ffsll function random performance regression. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
/* ffsll -- find first set bit in a word, counted from least significant end.
|
|
For AMD x86-64.
|
|
This file is part of the GNU C Library.
|
|
Copyright (C) 1991-2024 Free Software Foundation, Inc.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#define ffsl __something_else
|
|
#include <string.h>
|
|
|
|
#undef ffsll
|
|
|
|
int
|
|
ffsll (long long int x)
|
|
{
|
|
long long int cnt;
|
|
|
|
asm ("mov $-1,%k0\n" /* Initialize cnt to -1. */
|
|
"bsf %1,%0\n" /* Count low bits in x and store in cnt. */
|
|
"inc %k0\n" /* Increment cnt by 1. */
|
|
: "=&r" (cnt) : "r" (x));
|
|
|
|
return cnt;
|
|
}
|
|
|
|
#ifndef __ILP32__
|
|
#undef ffsl
|
|
weak_alias (ffsll, ffsl)
|
|
#endif
|