Re: Merit of callee-saved register



Tim Frink <plfriko@xxxxxxxx> wrote in part:
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."

I'm a native english speaker and I don't understand either.
Cheaper can mean shorter or quicker (cheaper on cycles)
which are often the same for once-thru code.

To me, register preservation is a matter of conventions
without any ideal answer: only the caller knows which regs
need saving, and only the callee knows which registers will
be trampled. Often, no regs need saving.

In x86, the arch is allegedly short of registers so the
usual presumption is all will get trampled. This leads to
caller-save conventions. But note that ESP and EBP usually
are callee-save . Since procedures have non-zero overhead,
they should be reserved for "significant" code that makes
the trampling more likely.

-- Robert

.



Relevant Pages

  • Re: Merits of callee-saved registers
    ... with no intermediate instructions to pop it out or push it back in. ... Let's say the callee is invoked 5x from different places, ... only those registers that it uses. ... In the caller saving model, the compiler is able to save only the registers ...
    (comp.programming)
  • Re: stack overflow on Sparc64
    ... The callee can do this even for non-variable argument lists. ... It's like a set of pre-allocated stack slots for those incoming ... argument registers when reloading under register pressure. ...
    (Linux-Kernel)
  • [PATCH RFC WIP] x86/paravirt: add register-saving thunks to reduce caller register pressure
    ... Here's a patch to wrap certain paravirt functions in register save/restore thunks, so that the callee code can be normal gcc-generated code, but the caller code doesn't need to worry about the arg or scratch registers getting trashed. ... I wasn't sure if it needs a register saving thunk to wrap the calls, or if they're guaranteed to not trash anything other than eax/rax. ... static void vsmp_restore_fl ...
    (Linux-Kernel)
  • [PATCH 0 of 7] x86/paravirt: optimise pvop calls and register use
    ... caller-save registers were saved. ... The C calling convention lists which registers the caller can ... callee-clobberable; the callee must preserve all other registers, ... This makes the callsites for these functions clobber many fewer ...
    (Linux-Kernel)
  • Re: stack overflow on Sparc64
    ... registers arguments into it's own frame like on AMD64 (then this space ... argument registers when reloading under register pressure. ... In my opinion it is better to put this onus on the callee because only ... I'll take a look at the gcc sparc backend and the ABI specification ...
    (Linux-Kernel)