aboutsummaryrefslogtreecommitdiff
path: root/src/lj_asm_arm64.h
diff options
context:
space:
mode:
authorMike Pall <mike>2023-09-11 16:35:28 +0200
committerMike Pall <mike>2023-09-11 16:35:28 +0200
commit1c33f46314cc4e3cb52ac83c5b27419bc06b5154 (patch)
treedc0a2609e21612839aa657cf9129009247bfc9c5 /src/lj_asm_arm64.h
parentf63bc569fab1450def4c817f100e580dddb425c5 (diff)
downloadluajit-1c33f46314cc4e3cb52ac83c5b27419bc06b5154.tar.gz
luajit-1c33f46314cc4e3cb52ac83c5b27419bc06b5154.tar.bz2
luajit-1c33f46314cc4e3cb52ac83c5b27419bc06b5154.zip
Windows/ARM64: Support Windows calling conventions.
Dear Microsoft: your butchering of the (perfectly fine) ARM64 ABI is a disgrace. Thanks to Peter Cawley. #593
Diffstat (limited to 'src/lj_asm_arm64.h')
-rw-r--r--src/lj_asm_arm64.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h
index 4dd6b711..c2b17737 100644
--- a/src/lj_asm_arm64.h
+++ b/src/lj_asm_arm64.h
@@ -432,6 +432,11 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
432 for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++) 432 for (gpr = REGARG_FIRSTGPR; gpr <= REGARG_LASTGPR; gpr++)
433 as->cost[gpr] = REGCOST(~0u, ASMREF_L); 433 as->cost[gpr] = REGCOST(~0u, ASMREF_L);
434 gpr = REGARG_FIRSTGPR; 434 gpr = REGARG_FIRSTGPR;
435#if LJ_HASFFI && LJ_ABI_WIN
436 if ((ci->flags & CCI_VARARG)) {
437 fpr = REGARG_LASTFPR+1;
438 }
439#endif
435 for (n = 0; n < nargs; n++) { /* Setup args. */ 440 for (n = 0; n < nargs; n++) { /* Setup args. */
436 IRRef ref = args[n]; 441 IRRef ref = args[n];
437 IRIns *ir = IR(ref); 442 IRIns *ir = IR(ref);
@@ -442,6 +447,11 @@ static void asm_gencall(ASMState *as, const CCallInfo *ci, IRRef *args)
442 "reg %d not free", fpr); /* Must have been evicted. */ 447 "reg %d not free", fpr); /* Must have been evicted. */
443 ra_leftov(as, fpr, ref); 448 ra_leftov(as, fpr, ref);
444 fpr++; 449 fpr++;
450#if LJ_HASFFI && LJ_ABI_WIN
451 } else if ((ci->flags & CCI_VARARG) && (gpr <= REGARG_LASTGPR)) {
452 Reg rf = ra_alloc1(as, ref, RSET_FPR);
453 emit_dn(as, A64I_FMOV_R_D, gpr++, rf & 31);
454#endif
445 } else { 455 } else {
446 Reg r = ra_alloc1(as, ref, RSET_FPR); 456 Reg r = ra_alloc1(as, ref, RSET_FPR);
447 int32_t al = spalign; 457 int32_t al = spalign;
@@ -1943,6 +1953,9 @@ static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
1943 int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR; 1953 int ngpr = REGARG_NUMGPR, nfpr = REGARG_NUMFPR;
1944 int spofs = 0, spalign = LJ_TARGET_OSX ? 0 : 7, nslots; 1954 int spofs = 0, spalign = LJ_TARGET_OSX ? 0 : 7, nslots;
1945 asm_collectargs(as, ir, ci, args); 1955 asm_collectargs(as, ir, ci, args);
1956#if LJ_ABI_WIN
1957 if ((ci->flags & CCI_VARARG)) nfpr = 0;
1958#endif
1946 for (i = 0; i < nargs; i++) { 1959 for (i = 0; i < nargs; i++) {
1947 int al = spalign; 1960 int al = spalign;
1948 if (!args[i]) { 1961 if (!args[i]) {
@@ -1954,7 +1967,9 @@ static Reg asm_setup_call_slots(ASMState *as, IRIns *ir, const CCallInfo *ci)
1954#endif 1967#endif
1955 } else if (irt_isfp(IR(args[i])->t)) { 1968 } else if (irt_isfp(IR(args[i])->t)) {
1956 if (nfpr > 0) { nfpr--; continue; } 1969 if (nfpr > 0) { nfpr--; continue; }
1957#if LJ_TARGET_OSX 1970#if LJ_ABI_WIN
1971 if ((ci->flags & CCI_VARARG) && ngpr > 0) { ngpr--; continue; }
1972#elif LJ_TARGET_OSX
1958 al |= irt_isnum(IR(args[i])->t) ? 7 : 3; 1973 al |= irt_isnum(IR(args[i])->t) ? 7 : 3;
1959#endif 1974#endif
1960 } else { 1975 } else {