* [PATCH] x86/local: Remove trailing semicolon from _ASM_XADD in local_add_return()
@ 2026-02-12 10:51 Uros Bizjak
2026-02-15 0:54 ` H. Peter Anvin
0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2026-02-12 10:51 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, H. Peter Anvin
Remove the trailing semicolon from the inline assembly statement in
local_add_return().
The _ASM_XADD macro already expands to a complete instruction, making
the extra semicolon unnecessary. More importantly, the stray semicolon
causes GCC to treat the inline asm as containing multiple instructions,
which can skew its internal instruction count estimation and affect
optimization heuristics.
No functional change intended.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/include/asm/local.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
index 59aa966dc212..4957018fef3e 100644
--- a/arch/x86/include/asm/local.h
+++ b/arch/x86/include/asm/local.h
@@ -106,7 +106,7 @@ static inline bool local_add_negative(long i, local_t *l)
static inline long local_add_return(long i, local_t *l)
{
long __i = i;
- asm volatile(_ASM_XADD "%0, %1;"
+ asm volatile(_ASM_XADD "%0, %1"
: "+r" (i), "+m" (l->a.counter)
: : "memory");
return i + __i;
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/local: Remove trailing semicolon from _ASM_XADD in local_add_return()
2026-02-12 10:51 [PATCH] x86/local: Remove trailing semicolon from _ASM_XADD in local_add_return() Uros Bizjak
@ 2026-02-15 0:54 ` H. Peter Anvin
2026-02-15 16:43 ` Uros Bizjak
0 siblings, 1 reply; 3+ messages in thread
From: H. Peter Anvin @ 2026-02-15 0:54 UTC (permalink / raw)
To: Uros Bizjak, x86, linux-kernel
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
On February 12, 2026 2:51:02 AM PST, Uros Bizjak <ubizjak@gmail.com> wrote:
>Remove the trailing semicolon from the inline assembly statement in
>local_add_return().
>
>The _ASM_XADD macro already expands to a complete instruction, making
>the extra semicolon unnecessary. More importantly, the stray semicolon
>causes GCC to treat the inline asm as containing multiple instructions,
>which can skew its internal instruction count estimation and affect
>optimization heuristics.
>
>No functional change intended.
>
>Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
>Cc: Thomas Gleixner <tglx@kernel.org>
>Cc: Ingo Molnar <mingo@kernel.org>
>Cc: Borislav Petkov <bp@alien8.de>
>Cc: Dave Hansen <dave.hansen@linux.intel.com>
>Cc: "H. Peter Anvin" <hpa@zytor.com>
>---
> arch/x86/include/asm/local.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
>index 59aa966dc212..4957018fef3e 100644
>--- a/arch/x86/include/asm/local.h
>+++ b/arch/x86/include/asm/local.h
>@@ -106,7 +106,7 @@ static inline bool local_add_negative(long i, local_t *l)
> static inline long local_add_return(long i, local_t *l)
> {
> long __i = i;
>- asm volatile(_ASM_XADD "%0, %1;"
>+ asm volatile(_ASM_XADD "%0, %1"
> : "+r" (i), "+m" (l->a.counter)
> : : "memory");
> return i + __i;
Are you sure that gcc treats an empty statement or line as something that should be counted? It is awkward as heck if so, and really ought to be fixed in gcc.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/local: Remove trailing semicolon from _ASM_XADD in local_add_return()
2026-02-15 0:54 ` H. Peter Anvin
@ 2026-02-15 16:43 ` Uros Bizjak
0 siblings, 0 replies; 3+ messages in thread
From: Uros Bizjak @ 2026-02-15 16:43 UTC (permalink / raw)
To: H. Peter Anvin
Cc: x86, linux-kernel, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen
On Sun, Feb 15, 2026 at 1:55 AM H. Peter Anvin <hpa@zytor.com> wrote:
>
> On February 12, 2026 2:51:02 AM PST, Uros Bizjak <ubizjak@gmail.com> wrote:
> >Remove the trailing semicolon from the inline assembly statement in
> >local_add_return().
> >
> >The _ASM_XADD macro already expands to a complete instruction, making
> >the extra semicolon unnecessary. More importantly, the stray semicolon
> >causes GCC to treat the inline asm as containing multiple instructions,
> >which can skew its internal instruction count estimation and affect
> >optimization heuristics.
> >
> >No functional change intended.
> >
> >Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> >Cc: Thomas Gleixner <tglx@kernel.org>
> >Cc: Ingo Molnar <mingo@kernel.org>
> >Cc: Borislav Petkov <bp@alien8.de>
> >Cc: Dave Hansen <dave.hansen@linux.intel.com>
> >Cc: "H. Peter Anvin" <hpa@zytor.com>
> >---
> > arch/x86/include/asm/local.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> >diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
> >index 59aa966dc212..4957018fef3e 100644
> >--- a/arch/x86/include/asm/local.h
> >+++ b/arch/x86/include/asm/local.h
> >@@ -106,7 +106,7 @@ static inline bool local_add_negative(long i, local_t *l)
> > static inline long local_add_return(long i, local_t *l)
> > {
> > long __i = i;
> >- asm volatile(_ASM_XADD "%0, %1;"
> >+ asm volatile(_ASM_XADD "%0, %1"
> > : "+r" (i), "+m" (l->a.counter)
> > : : "memory");
> > return i + __i;
>
> Are you sure that gcc treats an empty statement or line as something that should be counted? It is awkward as heck if so, and really ought to be fixed in gcc.
Unfortunately, it is.
GCC does not parse asm template at all, and the insn estimator is very crude:
{
int count = 1;
if (!*templ)
return 0;
for (; *templ; templ++)
if (IS_ASM_LOGICAL_LINE_SEPARATOR (*templ, templ)
|| *templ == '\n')
count++;
return count;
}
with:
#define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == ';')
The size (in bytes) of asm is determined as the number of insns * the
length of the longest instruction supported by that processor (defined
to 16 for x86) [1]. So, the estimated byte size difference between
"mnemonic" and "mnemonic;" is 16 bytes, which can and will affect
inlining decisions for small utility functions.
There was a long debate about this, and as a result, the compiler
implemented "asm inline" to mitigate the effects of pseudo
instructions in asm templates. For other asms, they should use line
separators with care, to keep the estimated size of the asm at least
somehow sane.
[1] https://gcc.gnu.org/onlinedocs/gcc/Size-of-an-asm.html
Uros.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-02-15 16:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-12 10:51 [PATCH] x86/local: Remove trailing semicolon from _ASM_XADD in local_add_return() Uros Bizjak
2026-02-15 0:54 ` H. Peter Anvin
2026-02-15 16:43 ` Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®