This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Use of constraints when mapping C variables to ASM symbolic names?
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Jeffrey Walton <noloader at gmail dot com>
- Cc: David Brown <david at westcontrol dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Fri, 21 Aug 2015 11:29:57 -0500
- Subject: Re: Use of constraints when mapping C variables to ASM symbolic names?
- Authentication-results: sourceware.org; auth=none
- References: <CAH8yC8mZN0_LcsuOD87JHszVC-qW1eow8kKWNPGNcrH3qXpYhQ at mail dot gmail dot com> <55D72E1E dot 8070208 at westcontrol dot com> <CAH8yC8=XRu8FQsVButzL1EdG5Bz1eeTuCy10gZyp0eeO1vbLGA at mail dot gmail dot com>
On Fri, Aug 21, 2015 at 11:38:13AM -0400, Jeffrey Walton wrote:
> > Second, you are trying to do pushes, pops, register allocations, etc.,
> > manually in your assembly. Don't do that - let gcc's inline assembly do
> > it. It is much safer (it will work regardless of other code, inlining,
> > optimisations, etc.), easier, and clearer.
Sound advice.
> Actually, in a multi-line extended ASM block, it may not.
>
> There's no way to tell the assembler when the reading and writing of
> operands should occur.
Assembler? Do you mean compiler?
All input operands are written into whatever their constraints say, all
before your inline asm. All output operands are read from their
respective constraints, all after the inline asm. If your asm might
write an output while it is not done with the inputs (and that output
can overlap some input) you need to mark that output as earlyclobber.
You didn't provide any useful code (only snippets with the essential
parts missing), so it is hard to give any more targeted advice.
> > It is common for inline assembly in gcc to have nothing more than a
> > single instruction such as "cpuid" - all the "housekeeping" register and
> > variable manipulation is generated by the compiler. Note that this is
> > in contrast to inferior compilers such as MSVC, where you are expected
> > to re-invent the wheel for inline assembly (with no guarantee that the
> > same wheel will fit on the next version of the compiler).
>
> Well, there's a lot to be said about those inferior compilers that
> "just work" :)
Write plain assembler if you want that. You'll have to deal with ABIs
and all that, but you say you don't mind, so okay :-)
> What should be done for earlier versions of GCC that don't provide
> cpuid.h?
4.3 and later have it, it seems (that's from 2007).
> And what if its a different compiler that's not fully
> compatible with GCC
Then you probably cannot use inline asm at all.
Segher