Udostępnij za pośrednictwem


Return Values (C++)

A return value that can fit into 64 bits is returned through RAX—this includes __m64 types, but __m128, __m128i, __m128d, floats, and doubles are returned in XMM0. If the return value is a user-defined type that does not fit in 64 bits, then the caller assumes the responsibility of allocating and passing a pointer for the return value as the first argument. Subsequent arguments are then shifted one argument to the right. That same pointer must be returned by the callee in RAX. User-defined types to be returned directly must be 1, 2, 4, 8, 16, 32, or 64 bits in length.

Example of return value 1 – 64 bit result

__int64 func1(int a, float b, int c, int d, int e);
// Caller passes a in RCX, b in XMM1, c in R8, d in R9, e pushed on stack,
// callee returns __int64 result in RAX.

Example of return value 2 – 128 bit result

__m128 func2(float a, double b, int c, __m64 d); 
// Caller passes a in XMM0, b in XMM1, c in R8, d in R9, 
// callee returns __m128 result in XMM0.

Example of return value 3 – user type result

struct1 func3(int a, double b, int c, float d); 
// Caller allocates memory for struct1 returned and passes pointer in RCX, 
// a in RDX, b in XMM2, c in R9, d pushed on the stack, 
// callee returns pointer to struct1 result in RAX.

See Also

Reference

Calling Convention