Re: Merit of callee-saved register



On Apr 22, 4:51 am, Tim Frink <plfr...@xxxxxxxx> wrote:
Hi,

I've a general question about calling conventions and the use of registers
across calls. In a book I found this:
"For a variable whose range of appearance spans many procedure calls,
the use of a callee-saved register is advantageous, because saving and
restoring once at the procedure entry and exit respectively are cheaper
than saving and restoring around each call."

What I don't understand is the term "cheaper". In my opinion cheaper must
mean less code (i.e. less instructions in the code) since when the same
function is invoked multiple times, there are just once the instructions
in this function for saving/restoring while in the case of register
saving/restoring around the each call for each call separate instructions
must be added.

Cheaper cannot mean faster execution because the number of executed
saving/restoring instructions would be the same for both approaches,
right?

Or do you understand this in another way?


The wording is particularly unclear, but the advantage of using a
callee save register in that case is that some (or many) of the called
routines might avoid using that register at all, and thus will not
have to save it. So instead of saving it around each call, it gets
saved only inside those calls that need the register. So you save
both static and dynamic instructions.

Now the tradeoff is not necessarily that simple - a register might not
need saving (just reloading), so it might well be better to not use a
callee save register and always just generate the reload.

The whole caller/callee save thing is an attempt at allowing
reasonable performance while maintaining a consistent convention.
Better compilers (or assembler programmers), often avoid using a fixed
division like that, except in external calls where the convention is
required.

.



Relevant Pages

  • Re: Caps Lock ... Grrrr!
    ... because for the first four years of my computing life (from age five to ... (The alternate register bank was lovely: ... occasionally running machine code without saving the newly written ... assembly source first because saving to tape took too long and I ...
    (uk.comp.os.linux)
  • Re: Vouchers available at FRC
    ... On Fri, 16 Jun 2006 15:57:00 GMT, Jeff wrote: ... pounds to register a name. ... Maybe not if one could be sure of saving £24 in fairly short order, ...
    (soc.genealogy.britain)
  • Re: appwsgi
    ... you are free to register yourself on wsgi.org and put a link to your ... It's a wiki, after all. ... I thought I better asked first, saving the time of others to delete it ... people don't mind ...
    (comp.lang.python)
  • MacLive Expo 2007
    ... Be one of the first 5,000 to register and you will receive a free ticket ... saving yourself £15.00 ... your registration details. ...
    (uk.comp.sys.mac)
  • Re: Optimization Questions
    ... cycles you'd save would be more than offset by the cycles you'd burn ... instructions go through port 0 and port 1. ... a 16-bit register, writing one afterwards will be fast. ... Pre-read the value in EAX ...
    (comp.lang.asm.x86)