From: Paul Shirley Newsgroups: comp.os.msdos.djgpp Subject: Re: Disabling use of registers Date: Mon, 10 Nov 1997 14:28:18 +0000 Organization: wot? me? Lines: 58 Distribution: world Message-ID: References: Reply-To: Paul Shirley NNTP-Posting-Host: chocolat.foobar.co.uk Mime-Version: 1.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article , Carolyn Kelly-Pajot 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; //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