This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Use of constraints when mapping C variables to ASM symbolic names?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]