Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Last active November 5, 2018 11:11
Show Gist options
  • Save jniemann66/f0b6b47ee5421e928623e4619fe8d583 to your computer and use it in GitHub Desktop.
Save jniemann66/f0b6b47ee5421e928623e4619fe8d583 to your computer and use it in GitHub Desktop.
64-bit Calling-conventions
#ifdef _MSVC
/* MSVC: 4 params in registers, remainder on stack) */
// x86-64 msvc (note:long = 32bit, long long = 64-bit)
long long add(int rcx, int rdx, int r8d, int r9d, int rsp40, int rsp48, int rsp56, int rsp64) {
return rcx + rdx + r8d + r9d + rsp40 + rsp48 + rsp56 + rsp64; // xmm0
}
double add(double xmm0, double xmm1, double xmm2, double xmm3, int rsp40, int rsp48, int rsp56, int rsp64) {
return xmm0 + xmm1 + xmm2 + xmm3 + rsp40, rsp48, rsp56, rsp64; // rax
}
#else
// x86-64 gcc / clang
// (long = 64-bit)
/* 6 params in registers, remainder on stack */
long add(int edi, int esi, int edx, int ecx, int r8d, int r9d, int rsp8, int rsp16) {
return edi + esi + edx + ecx + r8d + r9d + rsp8 + rsp16; // -> rax
}
/* 8 params in xmm registers */
double add(double xmm0, double xmm1, double xmm2, double xmm3, double xmm4, double xmm5, double xmm6, double xmm7) {
return xmm0 + xmm1 + xmm2 + xmm3 + xmm4 + xmm5 + xmm6 + xmm7; // -> xmm0
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment