Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Mar 1999 21:43:56 -0800 (PST)
From:      "Richard J. Dawes" <rjdawes@physics.ucsd.edu>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        Andrew Reilly <andrew@lake.com.au>, "Stephen J. Roznowski" <sjr@home.net>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Use of "register" in code
Message-ID:  <Pine.SOL.3.96.990315211057.19848A-100000@huntington>
In-Reply-To: <199903160509.VAA06242@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 15 Mar 1999, Matthew Dillon wrote:

> Date: Mon, 15 Mar 1999 21:09:10 -0800 (PST)
> From: Matthew Dillon <dillon@apollo.backplane.com>
> To: Andrew Reilly <andrew@lake.com.au>,
>     "Stephen J. Roznowski" <sjr@home.net>, freebsd-hackers@FreeBSD.ORG
> Subject: Re: Use of "register" in code
> 
> 
> :
> :
> ::> :
> ::> :Thanks,
> ::> :-- 
> ::> :Stephen J. Roznowski    (sjr@home.net)
> ::> 
> ::>     The register declarations are useless historical artifacts.
> ::
> ::Why do you say that?  "register" in a declaration has a specific
> ::semantic meaning that isn't (to my knowledge) duplicated by any
> ::other language mechanism, and that is "this variable does not exist
> ::in the memory space, and so _cannot_ be de-referenced with "&" or
> ::modified by an asignment through a pointer."  Register pointer
> ::variables and temporaries are very important for preventing C
> ::compilers from producing pessimistic inner loop code.
> ::
> ::-- 
> ::Andrew
> :
> :    Firstly, that is not what register means.  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.
> :
> :    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.
> :
> :					-Matt
> :					Matthew Dillon 
> :					<dillon@backplane.com>
> 
>     Let me extend this with another example:  Protection against aliasing
>     is not usually an issue with stack variables.  On the otherhand, it is
>     something that would be much more useful with structural fields 
>     or globals.
> 
>     Try putting the 'register' keyword in front of a structural field or
>     global and you will wind up with a fist full of fatal compiler errors.
> 
>     I don't know a single programmer who uses 'register' to mean 'alias
>     protection'.

I agree.  Of course, there might not have been optimizing compilers
available when Stephen's games were written  (the ones from the ancient
BSD games collection?)  Now, the "register" specifier in userland code
can be eliminated without a second thought.  Andrew may well be refering
to a semantic he learned that might have been in use in that former,
perhaps pre-ANSI, day.

However, is 'register' not used to indicate candidacy for register allo-
cation when (in some rare instance) you don't trust a compiler's optimi-
zations?  Isn't that one reason gcc offers "-O0"?  (I'm sure what level
is the default.)  In that context, deeming 'register' to be a "useless
historical artifact" may be stating the case in terms that are too
strong.

I don't like to put my God hat on very often, but it's nice to know the
option of doing so is available should it be necessary.

========================================
Richard J. Dawes	rdawes@ucsd.edu
========================================




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?Pine.SOL.3.96.990315211057.19848A-100000>