Mail Archives: djgpp/1997/11/13/07:45:22
In article <O6EQDcF78GA DOT 198 AT upnetnews03>, Carolyn Kelly-Pajot
<dehacked72 AT hotmail DOT com> writes
>Is there a way of making GCC not use a certain register? I'm trying to use some
>registers to speed up code, and want to make sure they are not used by the rest
>of my code.
>
>
Have a look at info /gcc/C extensions/Explicit reg vars/Global reg
vars/.
I believe GForth uses global registers for a large speedup, in most
normal code its hard to think of a case where it would be useful on
intel cpu's. I assume you know what you're doing but don't forget to
check wether the code actually runs faster: you could easily lose more
performance from register starvation than you gain.
Don't allocate eax, I'm not sure which other registers are preserved
across library calls. You must compile *all* modules with the same
global register settings *OR* take special care to explicitly
save/restore those registers at every external interface. Also you must
define global registers *before* any function prototypes or the compiler
chokes (because some machines may want to use those registers for
parameter passing I assume)
This is the code we use in DN3D (MIPS R3000 but it shows what you need
to do):
-------
register OPCODE *insptr asm ("s0");
register OPCODE *script__ asm ("s1");
register void *__s2 asm ("s2");
register void *__s3 asm ("s3");
register void *__s4 asm ("s4");
void execute(short i,short p,long x)
{
//save all global registers
OPCODE *insptr_bak = insptr; //##PS## must explicitly save insptr
OPCODE *script_bak = script__; //##PS## must explicitly save insptr
void *old_s2 = __s2;
void *old_s3 = __s3;
void *old_s4 = __s4;
<lots of NDA'd code I can't show you ;) >
//restore all touched global registers
insptr = insptr_bak; //##PS## must explicitly restore insptr
script__ = script_bak; //##PS## must explicitly save insptr
__s2 = old_s2;
__s3 = old_s3;
__s4 = old_s4;
}
---
Paul Shirley: my email address is 'obvious'ly anti-spammed
- Raw text -