🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #13120

Re: Optimizing compiler's view on: no. of regs, aliasing, caller/callee save etc.

#13120
From: Gregory Smith
Date: Tue, 03 Mar 1987 00:15
50 lines
3367 bytes
In article <1283@ucbcad.berkeley.edu> faustus@ucbcad.berkeley.edu (Wayne A. Christopher) writes:
>WRT the discussion about whether the caller or the callee should save
>registers -- wouldn't the most efficient strategy be for the caller to
>pass the callee a mask of which registers are currently in use (by
>itself and previous functions)?  That way, the callee could AND its
>mask with the caller's mask and save those registers, and OR its mask
>and the caller's and pass that to any functions that it calls.  I think
>this should prevent any unnecessary saving of registers.

In article <1379@ncr-sd.SanDiego.NCR.COM> lodman@ncr-sd.UUCP (0000-Mike Lodman) writes:
>Wouldn't this force the linker to insert code to save and restore 
>registers?

No. It would require support in the architecture itself - a 'register-in-use'
word, with a bit for each register. *
At the top of each function would be an instruction with a register mask
field indicating which registers would be needed within that function.
This would be anded with the current mask to produce the set of registers
which must be pushed. The 'register-in-use' mask would be then be 'or-ed'
with this value to produce the new mask. The old mask would also have to
be pushed. ( can you say 'CISC'? ) The same instruction would of course
perform the usual stacrobatics (and make coffee if anybody wanted it).

On function exit there would be an instruction which would undo this. This
instruction would also contain the same mask that appeared in the entry
instruction.

The problem is, you wouldn't gain much. As you go deeper into the stack,
bits in the 'reg-in-use' word would become set, but would never be
cleared by anything but a function return. Once all of them become set,
you have gained nothing over a conventional (vax/68k/NS32K)
'push-specified-set' instruction, and you are pushing and popping an
extra word to boot.

Presumably, you could have a 'release-all-registers' instruction which
would push all the regs-in-use, and  the regs-in-use word, and clear
the regs-in-use word. A complementary instruction would pop them.
If a function A were to make many calls to a function B, and B needed
a lot of regs, it would then be advantageous for A to 'release-all-regs'
before the loop, so that the save/restore need only be done once.
But how to determine this?

* you could do this on an arbitrary machine with run-time code, but I
don't know of a machine with a push-specified-set op that allows a non-constant
set.

-- 
----------------------------------------------------------------------
Greg Smith     University of Toronto      UUCP: ..utzoo!utcsri!greg
Have vAX, will hack...
Technical Details
Message-ID: <4277@utcsri.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
References: <902@orcisi.UUCP> <1283@ucbcad.berkeley.edu> <1379@ncr-sd.SanDiego.NCR.COM>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP
Path: arc1-ca.pugleaf.net!utzoo!utcsri!greg
From: greg@utcsri.UUCP (Gregory Smith)
Newsgroups: comp.arch
Subject: Re: Optimizing compiler's view on: no. of regs, aliasing, caller/callee save etc.
Message-ID: <4277@utcsri.UUCP>
Date: Mon, 2-Mar-87 19:15:28 EST
Article-I.D.: utcsri.4277
Posted: Mon Mar  2 19:15:28 1987
Date-Received: Tue, 3-Mar-87 03:53:34 EST
References: <902@orcisi.UUCP> <1283@ucbcad.berkeley.edu> <1379@ncr-sd.SanDiego.NCR.COM>
Reply-To: greg@utcsri.UUCP (Gregory Smith)
Organization: CSRI, University of Toronto
Lines: 50