SUMMARY: register variables

From: Cary Talbot <talbot_at_shazam.wes.army.mil>
Date: Mon, 23 Oct 1995 10:53:25 -0500 (CDT)

Original post:

> Anyone know how many register variables are available per function
> using
>
> 1) gcc
>
> 2) cc
>
> on Digital Unix 3.2A ?

Answers:

from Jason Yanowitz <yanowitz_at_eternity.cs.umass.edu>

you can't count on ansi c compilers paying attention to your register
declaration. I do know that cc (using -O3 or '-migrate -O5') produces
better code than gcc. cc has a better register allocator (in fact, it
has an excellent register allocator)(*). If it is critical to you that
certain variables stay in registers and the compiler isn't doing it
(use -S to geenrate assembly output, cc does the most beautiful
commenting of its assembly output too, by the way.. it's a work of
article really), that I would code those routines in assembler.

you can also try and psyche out the compiler by keeping some registers
live over greater portioons of your code (making them global) but then
of course, you up the chances they get spilled, which is what you are
trying to avoid.

[the alpha has 32 float and 32 int registers, though some of them are
reserved.]

from Selden E Ball Jr <SEB_at_LNS62.LNS.CORNELL.EDU>

Alphas have 32 64bit integer registers and 32 64bit floating point registers.
You should probably get a copy of the Alpha Architecture Handbook.

You cannot be guaranteed that register variables are actually kept
in machine registers.

Modern C compilers only use register declarations as hints
to help optimize program performance, otherwise your programs
would be uncompilable on different computer architectures with
fewer registers than your original system.

There are two different DEC Alpha architectures: EV4 and EV5.
EV5 has more functional units (integer and floating point units).
DEC's compilers can be told to optimize for one or the other or
to generate code which runs almost as well on both.
EV5 systems only started shipping relatively recently.

and from Brad Daniels <daniels_at_jabberwock.biles.com>

On most modern compilation systems, including the ones you mention, the
register keyword is useless at best, and at the worst, can actually degrade
performance. Modern optimizers do carfeul analysis of data flow to
determine which entities can be stored in registers, and at which points in
the code a register can be re-used. The register keyword sometimes
overrides the optimizer's analysis and keeps a value in a register even when
it's no longer used and the register is in fact free for use with another
value.

If you don't use the register keyword, the optimizer will decide when to put
things in registers and when (and even whether) variables need to be saved
on the stack.

Thanks for the replies.

_____________________________________________________________________
Cary A. Talbot, Hydraulic Engineer US Army Corps of Engineers
ATTN: CEWES-HH-G Waterways Experiment Station
3909 Halls Ferry Road
Vicksburg, Mississippi 39180
phone:(601)634-4286 fax:(601)634-4208 email:talbot_at_hl.wes.army.mil
Received on Mon Oct 23 1995 - 17:41:51 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:46 NZDT