This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PROPOSAL: Extend inline asm syntax with size spec
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Ingo Molnar <mingo at kernel dot org>
- Cc: Michael Matz <matz at suse dot de>, Borislav Petkov <bp at alien8 dot de>, gcc at gcc dot gnu dot org, Richard Biener <rguenther at suse dot de>, Nadav Amit <namit at vmware dot com>, Ingo Molnar <mingo at redhat dot com>, linux-kernel at vger dot kernel dot org, x86 at kernel dot org, Masahiro Yamada <yamada dot masahiro at socionext dot com>, Sam Ravnborg <sam at ravnborg dot org>, Alok Kataria <akataria at vmware dot com>, Christopher Li <sparse at chrisli dot org>, Greg Kroah-Hartman <gregkh at linuxfoundation dot org>, "H. Peter Anvin" <hpa at zytor dot com>, Jan Beulich <JBeulich at suse dot com>, Josh Poimboeuf <jpoimboe at redhat dot com>, Juergen Gross <jgross at suse dot com>, Kate Stewart <kstewart at linuxfoundation dot org>, Kees Cook <keescook at chromium dot org>, linux-sparse at vger dot kernel dot org, Peter Zijlstra <peterz at infradead dot org>, Philippe Ombredanne <pombredanne at nexb dot com>, Thomas Gleixner <tglx at linutronix dot de>, virtualization at lists dot linux-foundation dot org, Linus Torvalds <torvalds at linux-foundation dot org>, Chris Zankel <chris at zankel dot net>, Max Filippov <jcmvbkbc at gmail dot com>, linux-xtensa at linux-xtensa dot org
- Date: Mon, 8 Oct 2018 03:18:57 -0500
- Subject: Re: PROPOSAL: Extend inline asm syntax with size spec
- References: <20181003213100.189959-1-namit@vmware.com> <20181007091805.GA30687@zn.tnic> <20181007132228.GJ29268@gate.crashing.org> <alpine.LSU.2.21.1810071534220.7867@wotan.suse.de> <20181008061323.GB66819@gmail.com>
On Mon, Oct 08, 2018 at 08:13:23AM +0200, Ingo Molnar wrote:
> * Michael Matz <matz@suse.de> wrote:
> > (without an built-in assembler which hopefully noone proposes).
> There are disadvantages (the main one is having to implement it), but a built-in assembler has
> numerous advantages as well:
>
> - Better optimizations: for example -Os could more accurately estimate true instruction size.
GCC already knows the exact instruction size in almost all cases, for most
backends. It is an advantage to not *have to* keep track of exact insn
size in all cases.
> - Better inlining: as the examples in this thread are showing.
That's a red herring, the actual issue is inlining makes some spectacularly
wrong decisions for code involving asm currently. That would not be solved
by outputting binary code instead of assembler code. All those decisions
are done long before code is output.
> - Better padding/alignment: right now GCC has no notion about the precise cache layout of the
> assembly code it generates and the code alignment options it has are crude.
This isn't true. Maybe some targets do not care.
And of course GCC only knows this as far as it knows the alignments of the
sections it outputs into; for example, ASLR is a nice performance killer
at times. And if your linker scripts align sections to less than a cache
line things do not look rosy either, etc.
> It got away with
> this so far because the x86 rule of thumb is that dense code is usually the right choice.
> - Better compiler performance: it would be faster as well to immediately emit assembly
> instructions, just like GCC's preprocessor library use speeds up compilation *significantly*
> instead of creating a separate preprocessor task.
So how much faster do you think it would be? Do you have actual numbers?
And no, -O0 does not count.
> - Better future integration of assembly blocks: GCC could begin to actually understand the
> assembly statements in inline asm and allow more user-friendly extensions to its
> historically complex and difficult to master inline asm syntax.
If you want to add a different kind of inline assembler, you can already.
There is no need for outputting binary code for that.
> I mean, it's a fact that the GNU project has *already* defined their own assembly syntax which
> departs from decades old platform assembly syntax
GCC's asm syntax is over three decades old itself. When it was defined
all other C inline assembler syntaxes were much younger than that. I don't
see what your argument is here.
> - and how the assembler is called by the
> compiler is basically an implementation detail, not a conceptual choice.
But the *format* of the interface representation, in this case textual
assembler code, is quite fundamental.
> The random
> multi-process unidirectional assembler choice of the past should not be treated as orthodoxy.
Then I have good news for you: no assembler works that way these days, and
that has been true for decades.
Segher