From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7852) id 4E9193858C3A; Thu, 1 Feb 2024 17:47:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E9193858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706809663; bh=lZtjwVQmpV1vgL/nu6RkPG4u/Ct2N4/zMzEjB4P0CNE=; h=From:To:Subject:Date:From; b=ILbxO44rwH/9Zi5JYf2W6UIOPzhKxQDJ1DQTMB6osTWg7ExCZ7kjCuikqr4aaqxZQ yas6ZqpnLP6Zqz0NxZTI81i6LlH7zNH2Y0fww67M3aif0uG5A4B/HCXGdGGVY6wiic DpzkyByCVnrHbBqshhCXfQ/M7DMWoerbZetJc+Z4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Sunil Pandey To: glibc-cvs@sourceware.org Subject: [glibc/release/2.34/master] x86_64: Optimize ffsll function code size. X-Act-Checkin: glibc X-Git-Author: Sunil K Pandey X-Git-Refname: refs/heads/release/2.34/master X-Git-Oldrev: 43ac0f94f19a55bd2454f64b95275b3206ca6c1b X-Git-Newrev: a08677d389924c1bccf640f650f5f121abf90cd5 Message-Id: <20240201174743.4E9193858C3A@sourceware.org> Date: Thu, 1 Feb 2024 17:47:43 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a08677d389924c1bccf640f650f5f121abf90cd5 commit a08677d389924c1bccf640f650f5f121abf90cd5 Author: Sunil K Pandey Date: Wed Jul 26 08:34:05 2023 -0700 x86_64: Optimize ffsll function code size. 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 (cherry picked from commit 9d94997b5f9445afd4f2bccc5fa60ff7c4361ec1) Diff: --- sysdeps/x86_64/ffsll.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sysdeps/x86_64/ffsll.c b/sysdeps/x86_64/ffsll.c index 2201a7aacd..17551fcff8 100644 --- a/sysdeps/x86_64/ffsll.c +++ b/sysdeps/x86_64/ffsll.c @@ -27,13 +27,13 @@ int ffsll (long long int x) { long long int cnt; - 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. */ - : "=&r" (cnt), "=r" (tmp) : "rm" (x), "1" (-1)); + 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 + 1; + return cnt; } #ifndef __ILP32__