Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are AVX registers handled by the common calling conventions?

I could not find any document defining how YMM registers are handled by the caller and by the callee.

To focus my question, here is what I would like to know:

  1. Which YMM registers must be restored by the callee before returning to the caller?
  2. Since there are differences for XMM registers in Linux and Windows, i assume that also YMM registers do not follow the same rules. what are the rules for each of the OSes?

EDIT: Thanks to the answer below I was able to scavenge the answer in the mentioned doc for Win64. I am quite sure that Linux follows similar rules:

"...
The YMM registers do not have callee-save status, except for the lower half
of YMM6-YMM15 in 64-bit Windows, where XMM6-XMM15 have callee-save status.
Possible future extensions of the vector registers to 512 bits or more will not have calleesave
status.
..."
like image 560
zr. Avatar asked Jan 13 '12 08:01

zr.


People also ask

What is the purpose of the calling convention?

Calling conventions specify how arguments are passed to a function, how return values are passed back out of a function, how the function is called, and how the function manages the stack and its stack frame. In short, the calling convention specifies how a function call in C or C++ is converted into assembly language.

What registers are the caller saved registers?

The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile (caller-saved). The registers RBX, RBP, RDI, RSI, RSP, R12, R13, R14, and R15 are considered nonvolatile (callee-saved).

What are the different calling conventions C language on x86 processor?

It uses registers RCX, RDX, R8, R9 for the first four integer or pointer arguments (in that order), and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments are pushed onto the stack (right to left). Integer return values (similar to x86) are returned in RAX if 64 bits or less.

What is caller callee convention and why is it needed?

Callee vs caller saved is a convention for who is responsible for saving and restoring the value in a register across a call. ALL registers are "global" in that any code anywhere can see (or modify) a register and those modifications will be seen by any later code anywhere.


1 Answers

The answer to both of your questions (assuming that you're talking about calling convention in C++) is in the great optimization guide by Agner Fog:

Calling conventions for different C++ compilers and operating systems.

See section 6 (Register usage) on page 10. Also section 7.2 (Passing and returning SIMD types) on page 22 might be relevant.

like image 114
Norbert P. Avatar answered Sep 17 '22 11:09

Norbert P.