Inline assembly, clobber registers, ask for help

Andrew Haley aph@redhat.com
Mon Jan 20 19:00:00 GMT 2003


> There is an inline assembly routine (x86, converted from Intel syntax),
> which has to be highly optimized. 
> The routine is using basicly all available
> registers(eax,ebx,ecx,edx,esi,edi), and have problems if I enable
> optimizations. (O0 -> Ok, O1..03->error, gcc3.2)
> 
> I see the following solution, and would be interested in your comments
> on these:
> 
> 1) Simple convert to GCC-syntax with using predefined registers (easy to
> maintain). Add some extra code for saving/loading registers (make gcc
> happy) as I was suggested... Accept worse performance caused by this
> extra operation...

The performance won't be worse.  If you clobber many registers then
gcc will have to save and restore them; it will generate code to do
so.  It makes no difference at all whether gcc generates this code or
you insert it yourself.  However, gcc can't do this at present because
you've left gcc no scratch registers.

> 2) Modify the code (hard to maintain parallel with the other
> Intel-syntax code) and let gcc select/optimize registers...  
>    Will this optimization problem disappear?

Probably not.  gcc still needs a scratch register or two.

>    The routine is using MMX/SSE2 instructions as well... Can gcc could
> optimize the MMX/XMM registers as well?

I think it can.  The constraint letter for SSE regs is 'x'.  I don't
think it would gain you anything, though.

> And a question:
> Which registers can be marked as clobbered registers? I tried eax, ebx
> with success, but e.g. ecx caused a compilation error (~Register can't
> be found within GENERAL_REGS). Which registers belongs to GENERAL_REGS?

Please show

 1.  What version of gcc you're using.
 2.  The *exact" error message you see.

I think that gcc is trying to generate code and it can't because it
has no registers left.

BTW, CX is a member of GENERAL_REGS.

Andrew.



More information about the Gcc-help mailing list