All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Teddy Astie" <teddy.astie@vates.tech>,
	"Roger Pau Monné" <roger@xenproject.org>,
	"Jason Andryuk" <jason.andryuk@amd.com>
Subject: Re: [PATCH v4 2/3] x86: use __builtin_popcountl() for arch_hweightl() when available
Date: Thu, 15 Oct 2026 11:37:19 +0100	[thread overview]
Message-ID: <716a13d4-9fd8-41bf-b475-08d0747ff442@citrix.com> (raw)
In-Reply-To: <9e48f405-4e99-4258-921e-2948f0d6754d@suse.com>

On 15/10/2026 10:10 am, Jan Beulich wrote:
> Use the respective compiler builtin when available; no need to play any
> alternatives games in such configurations.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> v4: Re-base (re-do).
>
> --- a/xen/arch/x86/include/asm/bitops.h
> +++ b/xen/arch/x86/include/asm/bitops.h
> @@ -500,6 +500,9 @@ static always_inline unsigned int arch_f
>  
>  unsigned int arch_generic_hweightl(unsigned long x);
>  
> +#ifdef __POPCNT__
> +#define arch_hweightl __builtin_popcountl
> +#else /* !__POPCNT__ */
>  static always_inline unsigned int arch_hweightl(unsigned long x)
>  {
>      unsigned int r;
> @@ -525,5 +528,6 @@ static always_inline unsigned int arch_h
>      return r;
>  }
>  #define arch_hweightl arch_hweightl
> +#endif /* __POPCNT__ */
>  
>  #endif /* _X86_BITOPS_H */
>

This is needlessly complex.

diff --git a/xen/arch/x86/include/asm/bitops.h
b/xen/arch/x86/include/asm/bitops.h
index 557cee03baeb..c38680e8888c 100644
--- a/xen/arch/x86/include/asm/bitops.h
+++ b/xen/arch/x86/include/asm/bitops.h
@@ -504,6 +504,10 @@ static always_inline unsigned int
arch_hweightl(unsigned long x)
 {
     unsigned int r;
 
+    /* If compiled with a suitable baseline ISA. */
+    if ( IS_ENABLED(__POPCNT__) )
+        return __builtin_popcountl(x);
+
     /*
      * arch_generic_hweightl() is written in ASM in order to preserve all
      * registers, as the compiler can't see the call.


~Andrew


  reply	other threads:[~2026-10-15 10:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  9:08 [PATCH v4 0/3] x86: allow Kconfig control over psABI level Jan Beulich
2026-10-15  9:09 ` [PATCH v4 1/3] x86: allow Kconfig control over psABI level to use Jan Beulich
2026-10-15  9:10 ` [PATCH v4 2/3] x86: use __builtin_popcountl() for arch_hweightl() when available Jan Beulich
2026-10-15 10:37   ` Andrew Cooper [this message]
2026-10-15 12:22     ` Jan Beulich
2026-10-15  9:11 ` [PATCH v4 3/3] x86: short-circuit certain cpu_has_* when x86-64-v{2,3} are in effect Jan Beulich
2026-10-19  9:34   ` Roger Pau Monné
2026-10-19  9:57     ` Alejandro Vallejo

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=716a13d4-9fd8-41bf-b475-08d0747ff442@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=jason.andryuk@amd.com \
    --cc=jbeulich@suse.com \
    --cc=roger@xenproject.org \
    --cc=teddy.astie@vates.tech \
    --cc=xen-devel@lists.xenproject.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.