Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1a 12/4/83; site rlgvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.arch,net.lang.c Subject: Re: RISC perspective Message-ID: <1797@rlgvax.UUCP> Date: Fri, 9-Mar-84 22:07:21 EST Article-I.D.: rlgvax.1797 Posted: Fri Mar 9 22:07:21 1984 Date-Received: Sat, 10-Mar-84 14:19:15 EST References: <27900009@ucbesvax.UUCP> <26@utastro.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 29 This is a spinoff from a comment about speeding up C programs by advising the C compiler what to put into registers. The idea is good, but there's one problem with its current implementation; there's no way to make those hints truly "machine-independent". The problem is that you want to use all the registers you can (actually, there's even a tradeoff here; you get extra performance from instructions referencing registers, but you do have to save and restore those registers, and if you have complicated expressions you may run out of scratch registers and be forced to use temporaries in memory), but "all the registers you can" is machine-dependent. On the PDP-11, "all the registers you can" in the Ritchie and Johnson compilers is 3; on the VAX-11, it's 6, and on the M68000, it's (at least on our compiler) 6 registers not containing pointers and four registers containing pointers. Just declaring everything you can to be "register" wins only if 1) there are enough registers to satisfy your requests or 2) the variables that will cause the greatest improvement when put in registers are assigned to registers first, and the less important ones cause the compiler to ignore the "register" declaration. You can sort of rig it to work right, on compilers that assign "register" variables to registers in the order they encounter them in the source text, buy putting the "best" candidates first; however, 1) this means you may not be able to use the "register parameter" feature, 2) it makes your code a little less readable, and 3) most importantly, it requires you to know what the compiler does - but what happens if the compiler doesn't work that way? Writing portable code to use registers efficiently is tricky at times. Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy