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: FW: Inline assembly, clobber registers, ask for help


> Thanks for your comments.
> 
> I converted the code not to use predefined general registers, and it
> seems it is working now, even with optimizations. Apart from this, I
> would like to learn more about this topic.
> 
> You mentioned that gcc needs 1 or two registers for saving/restoring
> clobbered registers.  Why gcc tries to do this in every case?

It's because of the way reload works.  Whenever an instruction needs
some operands it's the job of reload to make sure they are in the
right registers.  In order to do its job, reload sometimes needs
temporary registers, and as a general rule we advise people to leave
one or two registers free in case reload decides it needs them.
Reload does not always generate optimal code and sometimes uses more
registers than a human programmer would.  

Generally speaking, the more registers are free, the better reload is
able to do its job, and therefore the better the code quality.

The great thing about allowing the compiler to do register allocation
rather than anming your won is that reload doesn't have to move things
around so much.

> I could imagine a lot of code, where an inline assembly routine
> could use registers and after it it has not to be
> restored. E.g. later initialized with a contant...

Oh, sure.  We try not to save register when it isn't necsaary.

> Another solution would be to use POPA/PUSHA if there are no general
> registers available. Currently gcc miscompiles the code in case of
> optimizations, if I understood/experience right.

It doesn't miscompile it, does it?  I thought it refused to compile it
at all.  If it was miscompiled that is a bug, but gcc is perfectly
entitled to refuse to compile an asm if it can't satisfy that asm's
constraints.

> In general, what kind of tasks are gcc doing prior/middle/after to
> an inline assembly code, when optimizations are enabled? (Is there
> any documentation to read more about this?

It's mostly reload moving things around to satisfy the requirements of
the inline asm.  To explain how it does this would require me to
explain reload, which is one of the most complex parts of gcc.  I
haven't the time to do that and I imagine you haven't the time to read
it either.

> I use gcc version 3.2.2 20030109. I assume ECX as a member of
> general register class, but gcc provides the following error
> message: "can't find a register in 'GENERAL_REGS while reloading
> asm".  EAX, EBX are fine ECX not.

Reload is complaining that it can't allocate a temporary register
because there are none left.

Andrew.


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