🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #12849

Re: Available no. of registers

#12849
From: Steve Correll
Date: Mon, 19 Jan 1987 08:06
44 lines
2860 bytes
In article <3810002@nucsrl.UUCP>, ram@nucsrl.UUCP (Raman Renu) writes:
>    This is my first posting in this newsgroup. So hold your flames if this
> is a dumb question.
> 
>    C allows "register ......" construct which instructs the compiler
> to reserve a machine register to store that value.  Now my question is,
> given a fixed number of registers, How many are effectively usable for
> the register declaration.  I know this is machine dependent.  Could
> somebody say how many register definitions I could use within a block
> of code say for a VAX.  And please go on to mention the CPU/Machine that
> allows the greatest number and smallest number of such declarations. 

Not a dumb question. The number of registers available depends
not only on the machine architecture, but also on which compiler you use,
and sometimes on the level of optimization you ask the compiler to
perform. Sometimes the compiler's documentation will answer your question.
Failing that, experimenting with the "-S" compiler option may reveal it.

A smart compiler will try to keep variables in registers whenever
possible, even without 'register' declarations, and will decide for
itself how best to use the available registers. But the use of pointers
can create 'aliases' (that is, you can refer to the same variable
either directly, or indirectly via a pointer). The compiler cannot in
general know which variable a pointer may be pointing to, and dares not
keep a variable in a register when a pointer reference may access the
'stale' copy of the variable in memory.

Given a smart compiler, it's often effective to put the 'register'
declaration on every variable which you happen to know won't be
referenced by a pointer.  Even if the compiler can't put them all in
registers, it can sometimes perform other optimizations as a result.

Given a not-so-smart compiler, which puts variables into registers only
on command, it's ususally harmless to give too many 'register'
declarations--but you'd probably better put the most important variables
first, lest the compiler run out of registers before getting to the
important ones.

I myself have encountered machines with as few as 0 or 1 registers (stack
machines, early minicomputers) and as many as 128. I suspect I haven't run
the gamut.

-- 
...decwrl!mips!sjc						Steve Correll
Technical Details
Message-ID: <926@mips.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!mit-eddie!genrad!panda!husc6!necntc!adelie!axiom!linus!philabs!prls!mips!sjc
References: <3810002@nucsrl.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!columbia!rutgers!mit-eddie!genrad!panda!husc6!necntc!adelie!axiom!linus!philabs!prls!mips!sjc
From: sjc@mips.UUCP (Steve Correll)
Newsgroups: comp.arch
Subject: Re: Available no. of registers
Message-ID: <926@mips.UUCP>
Date: Mon, 19-Jan-87 03:06:30 EST
Article-I.D.: mips.926
Posted: Mon Jan 19 03:06:30 1987
Date-Received: Wed, 21-Jan-87 22:18:47 EST
References: <3810002@nucsrl.UUCP>
Lines: 44