Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!jade!eris!mwm From: mwm@eris.BERKELEY.EDU (Mike Meyer) Newsgroups: comp.lang.c Subject: Re: Available No. of Registers Message-ID: <2250@jade.BERKELEY.EDU> Date: Sun, 18-Jan-87 18:52:22 EST Article-I.D.: jade.2250 Posted: Sun Jan 18 18:52:22 1987 Date-Received: Mon, 19-Jan-87 20:37:22 EST References: <3950004@nucsrl.UUCP> <83@ucdavis.UUCP> Sender: usenet@jade.BERKELEY.EDU Reply-To: mwm@eris.BERKELEY.EDU (Mike Meyer) Organization: Missionaria Phonibalonica Lines: 33 In article <83@ucdavis.UUCP> cccmark@deneb.UUCP (Mark Nagel) writes: >On the machines I've worked on, the register declaration will use up to >the total available registers on the CPU and then it is ignored (i.e. no >error, just no register declaration either). Depending on the compiler, >the register declaration will do anything from telling the compiler to put >this variable in an available register or else (Macintosh w/Lightspeed C) >to strongly advising the compiler to possibly put the variable in a register >if it wouldn't be too much trouble (VAX/VMS C). I am not sure of exact >numbers offhand, but they will vary according to compiler as well as CPU. There is a false implication in the above: that it doesn't hurt to add register declerations. There is at least one compiler out there that effectively allocates registers from the last declared instead of the first, so that blindly adding registers to code can slow the generatred code down. The algorithm I use for allocating registers is as follows: Assign one register to each heavily-used variable. While there are fewer registers than N, and there are variables that are touched in loops, or more than a few times outside of loops, repeat for the next least heavily-used variables. N depends on the expected target machines. Since I'm writing for 68K's and VAXen these days, it's 6. When I wrote for 11's and 4004 family machines, it was 3. Three isn't enough; I don't very often need more than 6, though. If you feel that you need speed badly enough to want to KNOW which variables go into registers, and can't afford to pull the overhead of a subroutine, you probably oughta be hand-coding that routine in assembler for speed anyway.