Path: chuka.playstation.co.uk!news From: Craig Graham Newsgroups: scee.yaroze.programming.codewarrior Subject: Re: register variables again :-) Date: Tue, 14 Apr 1998 11:33:25 +0100 Organization: Intelligent Research Lines: 67 Message-ID: <35333B75.F180F59A@hinge.mistral.co.uk> References: <01bd6477$65581880$c20f93c3@default> <352EAEA6.5C225F79@ndirect.co.uk> <01bd659f$e094de60$780c93c3@default> NNTP-Posting-Host: 194.131.235.3 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; I) The MIPS (SGI) R3000 manual has a recommended register allocation list. The registers themselves are general purpose - some assemblers such as the GNU one simply reffer to them as $0 - $31, but there is a naming and allocation convention that most compilers (Codewarrior included) use. You can find this in the R3000 manual.....I cann't offhand remember the exact details but roughly: 4 parameter registers (a0-a3) (if a function has 4 parms or less they all use register parameter passing) stack (sp) global data pointer (gp) return address register (ra) temporary data registers (you don't need to stack them on function entry) t0-t4 load's of general purpose regs that you DO have to stack on function entry if your using them. Also, a decent compiler should spot variable persistance and re-use registers anyway eg. void test(int parm) // parm will be passed in parameter register a0 { int a,b; a=10; // a is auto-allocated to register t0, t0=10 a+=parm; // t0=t0+a0 // a isn't used beyond this point, so we can re-use reg t0 b=30; // t0=30 b*=parm; // t0=t0*a0 } Craig. Jon Prestidge (alias Moose) wrote: > Cheers for the reply Alex... > > I wonder how many spare registers there are roughly. I'll have to try > some dissasembling too to see what's typical ... unless anyone knows off > hand --- someone from MetroWerks perhaps..(hint, hint!). > > Also is there just one type of register in this CPU or are they split > betwen address and data registers .. if so presumably that would determin > how pointers or integers etc. get assigned to each spare register. > > The reason I'm interested is that if you know roughly how many register > variables are available you can code accordingly.... eg. if you have a few > at your disposal you can use a few meaningful variable names to help make > the code more readable and still get the speed advantage ... but if you > only had one spare you might want to keep reusing the same variable within > a routine and call it 'temp' or somthing ... if you see what I mean. > > Alex Herbert wrote in article > <352EAEA6.5C225F79@ndirect.co.uk>... > > I don't actually know the answer to this question, but, if you switch the > > optimisation to it's highest level, CW seems to 'convert' as many local > > variables as posible into register vars. I haven't really checked this > out, > > but when dissasembling, it certainly looked that way. Can anyone verify > this? > > > > Alex (alias Herbs)