Re: [PATCH 14/20] x86/barrier: Use alternative_io() in 32-bit barrier functions
From: Josh Poimboeuf
Date: Tue Mar 18 2025 - 18:29:45 EST
On Tue, Mar 18, 2025 at 10:06:05PM +0000, David Laight wrote:
> > > So with:
> > > #define __asm_call(qual, alt, out, in, clobber) \
> > > asm("zzz", ARG out, ARG in, ARG clobber)
> > >
> > > __asm_call(qual, ALT(), \
> > > ([var] "+m" (__my_cpu_var(_var)), "+a" (old__.low), \
> > > "+d" (old__.high)), \
> > > ("b" (new__.low), "c" (new__.high), "S" (&(_var))), \
> > > ("memory"));
> > >
> > > would get expanded the same as the line below.
> >
> > Interesting idea, though I still prefer the self-documenting ASM_OUTPUT
> > / ASM_INPUT / ASM_CLOBBER macros which are self-documenting and make it
> > easier to read and visually distinguish the constraint lists.
>
> Except that non of this really makes it easier to get out/in in the correct
> order or to use the right constraints.
At least it's still no worse than asm() itself in that respect.
> So are you just adding 'syntactic sugar' for no real gain?
Some wrappers need to modify their constraint lists, so the sugar does
have a functional purpose. The new alternative_io() (or whatever it
will be called) interface will especially be needed for the followup to
this patch set which introduces asm_call() to try to fix an
ASM_CALL_CONSTRAINT mess.
> Looking back at one of the changes:
> -#define mb() asm volatile(ALTERNATIVE("lock addl $0,-4(%%esp)", "mfence", \
> - X86_FEATURE_XMM2) ::: "memory", "cc")
> +#define mb() alternative_io("lock addl $0,-4(%%esp)", \
> + "mfence", X86_FEATURE_XMM2, \
> + ARG(), \
> + ARG(), \
> + ARG("memory", "cc"))
>
> is it really an improvement?
The motivation here is to use the alternative*() wrappers whenever
possible. It helps achieve consistent behaviors and also removes the
ugly nested ALTERNATIVE() macro.
In fact, the change in your example actually improves code generation:
it changes the asm() to asm_inline() which prevents GCC from doing crazy
things due to the exploded size of the asm string.
--
Josh