Re: register variables in C.

pardo@cs.washington.edu (David Keppel)
Fri, 1 May 1992 02:18:31 GMT

          From comp.compilers

Related articles
[2 earlier articles]
Re: register variables in C. moss@cs.umass.edu (1992-04-23)
Re: register variables in C. dd@mips.com (1992-04-23)
Re: register variables in C. dave.howell@ColumbiaSC.NCR.COM (Dave Howell) (1992-04-24)
Re: register variables in C. bart@cs.uoregon.edu (1992-04-29)
Re: register variables in C. jeff@dsp.sps.mot.com (1992-04-30)
Re: register variables in C. Brian.Scearce@Eng.Sun.COM (1992-04-30)
Re: register variables in C. pardo@cs.washington.edu (1992-05-01)
Re: register variables in C. metaware!miker@uunet.UU.NET (1992-05-01)
Re: register variables in C. preston@dawn.cs.rice.edu (1992-05-01)
Re: register variables in C. bliss@sp64.csrd.uiuc.edu (1992-05-01)
Re: register variables in C. ressler@cs.cornell.edu (1992-05-02)
Re: register variables in C. stephen@estragon.uchicago.edu (1992-05-04)
Re: register variables in C. macrakis@osf.org (1992-05-04)
[2 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: pardo@cs.washington.edu (David Keppel)
Keywords: registers, optimize, bibliography
Organization: Computer Science & Engineering, U. of Washington, Seattle
References: 92-04-125 92-04-161
Date: Fri, 1 May 1992 02:18:31 GMT

>[`register' declarations]


John Levine writes:
>[Use them, let the compiler decide with `-Dregister=auto'.]


You might want to define register to nothing in case `auto' forces vars to
memory for some reason. This approach is all-or-nothing which is
undesirable since different compilers & architectures have different
needs. I recommend `register' for the most important variables and and
use other #defines for the remainder [Cannon et. al]:


register int x1;
register int y1;
REGISTER int x2;
REGISTER int y2;


This approach can tell compiler A `x1' and `y1' belong in registers and
can tell compiler B that `x2' and `y2' also belong in registers. It also
avoids telling `A' that `x2' and `y2' belong in registers, which keeps
compiler A from being swamped with register declarations. That might be
important on machines with few registers. It also helps the person
porting/maintaining the code in deciding which things the original
programmer believes are most important.


In writing code for several platforms you may need to define REGISTER,
REGISTER2, etc., to cover the various targets.


I believe that C programmers who are tuning programs should use `register'
and REGISTER and so on because it works in practice and documents
performance tuning. `register' should be used when the situation demands
it; it shouldn't be used gratuitously (nor should `REGISTER' and so on).


I don't recall: the original question could have been ``should I use
`register'?'' or ``should my compiler recognize `register'?'' As a
programmer, I am willing to use a compiler that ignores register
declarations (e.g., GNU CC) because it does a good job in general and
because register allocation is just one of many tuning problems. I would
be happier still if it recognized `register', as I could always turn it
off (-Dregister) but could use it when the situation demands.


For the asbestos at heart:


[Cannon et. al]
L. W. Cannon, R. A. Elliot, L. W. Kirchhoff J. H. Miller,
J. M. Milner, R. W. Mitze, E. P. Schan, N. O. Whittington,
Henry Spencer, David Keppel, Mark S. Brader _Recommended C
Style and Coding Standards_. (Originally published as
_Indian Hill C Style and Coding Standards_, rewritten by the
last three authors.) ISBN 0-91615-46-8, 1990.


It's available via anonymous ftp from `cs.washington.edu' (128.95.1.4) in
`pub/cstyle.tar.Z', be sure to do the transfer in binary (image) mode.


;-D on ( The style pedant ) Pardo
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.