From: Uros Bizjak <ubizjak@gmail.com>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH 2/2] x86/bootflag: Use __builtin_parity() when available
Date: Wed, 29 Jan 2025 16:47:51 +0100 [thread overview]
Message-ID: <20250129154920.6773-2-ubizjak@gmail.com> (raw)
In-Reply-To: <20250129154920.6773-1-ubizjak@gmail.com>
Compilers (GCC and clang) provide optimized __builtin_parity() function
that returns the parity of X, i.e. the number of 1-bits in X modulo 2.
Use __builtin_parity() built-in function to optimize parity(). This
improves generated parity code to just:
57: 84 db test %bl,%bl
59: 7a 5c jp b7 <sbf_init+0xa7>
where TEST instruction sets parity flag (PF) in EFLAGS, exercised by the
follow-up jump instruction.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/kernel/bootflag.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/bootflag.c b/arch/x86/kernel/bootflag.c
index 4d89a2d80d0f..d63247d7abd4 100644
--- a/arch/x86/kernel/bootflag.c
+++ b/arch/x86/kernel/bootflag.c
@@ -22,6 +22,9 @@ int sbf_port __initdata = -1; /* set via acpi_boot_init() */
static bool __init parity(u8 v)
{
+#if __has_builtin(__builtin_parity)
+ int x = __builtin_parity(v);
+#else
int x = 0;
int i;
@@ -29,7 +32,7 @@ static bool __init parity(u8 v)
x ^= (v & 1);
v >>= 1;
}
-
+#endif
return !!x;
}
--
2.42.0
next prev parent reply other threads:[~2025-01-29 15:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-29 15:47 [PATCH 1/2] x86/bootflag: Change some static functions to bool Uros Bizjak
2025-01-29 15:47 ` Uros Bizjak [this message]
2025-01-31 15:15 ` [PATCH 2/2] x86/bootflag: Use __builtin_parity() when available Uros Bizjak
2025-02-22 11:56 ` [tip: x86/boot] x86/boot: Change some static bootflag functions to bool tip-bot2 for Uros Bizjak
2025-02-24 7:18 ` [PATCH 1/2] x86/bootflag: Change some static " Jiri Slaby
2025-02-24 7:24 ` Uros Bizjak
2025-02-24 7:27 ` Jiri Slaby
2025-02-24 7:39 ` Uros Bizjak
2025-02-24 7:48 ` Jiri Slaby
2025-02-24 7:56 ` Uros Bizjak
2025-02-24 18:58 ` Ingo Molnar
2025-02-26 6:31 ` Jiri Slaby
2025-02-26 7:17 ` H. Peter Anvin
2025-02-26 7:21 ` Jiri Slaby
2025-02-26 12:21 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250129154920.6773-2-ubizjak@gmail.com \
--to=ubizjak@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.