Date: Tue, 16 Mar 1999 16:17:20 +1100 (EST) From: "Andrew Reilly" <andrew@lake.com.au> To: dillon@apollo.backplane.com Cc: andrew@lake.com.au, sjr@home.net, freebsd-hackers@FreeBSD.ORG Subject: Re: Use of "register" in code Message-ID: <19990316051721.40605.qmail@areilly.bpc-users.org> In-Reply-To: <199903160431.UAA05835@apollo.backplane.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Matthew Dillon said: > Firstly, that is not what register means. Well, I'm not a language lawyer, but it's certainly been my experience. Even the version of gcc shipped as cc with FreeBSD will say foo.c:3: warning: address of register variable `i' requested if you try something like: {register int i; int *p; p = & i;} > Secondly, all modern C > compilers that I know about, including one I wrote years ago, can > trivially detect the stack locality of a variable and put it in a > register as part of standard optimizations. It's one of the *easiest* > optimizations a C compiler can do, in fact. Naturally. You'd hope so. But if your routine takes the address of _any_ auto variable, and hands that to a function or writes to some run-time computed index of it, then the compiler has to assume that any of the other auto variables in the stack frame could have been modified, and so it has to re-fetch any auto variables after such a write. It doesn't have to do that for register variables. > Some compilers will add a little weight to the potential optimization > if you use the 'register' keyword, but modern compilers tend to do a > better job without the manual weighting. One old compiler I've used won't ever put a variable into a register unless you tell it to, but neither example has a bearing on whether "register" has a specific meaning wrt aliasing. The closest reference I've found on the net is http://www.lysator.liu.se/c/rat/c5.html#3-5 3.5.1, which says: " Because the address of a register variable cannot be taken, objects of storage class register effectively exist in a space distinct from other objects. (Functions occupy yet a third address space). This makes them candidates for optimal placement, the usual reason for declaring registers, but it also makes them candidates for more aggressive optimization. The practice of representing register variables as wider types (as when register char is quietly changed to register int) is no longer acceptable. " which seems to back up my assertion. In any case, what does taking the register keyword out buy you? -- Andrew To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990316051721.40605.qmail>