arm64: use IP1 as scratch register

On Apple platforms x18 is not guaranteed
to be preserved across context switches.
So we now use IP1 as scratch register.

En passant, one dubious use of IP0 in
arm64/emit.c fixarg() was transitioned
to IP1. I believe the previous code could
clobber a user value if IP0 was live.
This commit is contained in:
Quentin Carbonneaux 2025-03-15 14:22:59 +01:00
parent ec5502645f
commit 86d13b93e8
2 changed files with 7 additions and 7 deletions

View File

@ -195,7 +195,7 @@ emitf(char *s, Ins *i, E *e)
goto Switch; goto Switch;
case '?': case '?':
if (KBASE(k) == 0) if (KBASE(k) == 0)
fputs(rname(R18, k), e->f); fputs(rname(IP1, k), e->f);
else else
fputs(k==Ks ? "s31" : "d31", e->f); fputs(k==Ks ? "s31" : "d31", e->f);
break; break;
@ -346,9 +346,9 @@ fixarg(Ref *pr, int sz, E *e)
if (rtype(r) == RSlot) { if (rtype(r) == RSlot) {
s = slot(r, e); s = slot(r, e);
if (s > sz * 4095u) { if (s > sz * 4095u) {
i = &(Ins){Oaddr, Kl, TMP(IP0), {r}}; i = &(Ins){Oaddr, Kl, TMP(IP1), {r}};
emitins(i, e); emitins(i, e);
*pr = TMP(IP0); *pr = TMP(IP1);
} }
} }
} }
@ -393,7 +393,7 @@ emitins(Ins *i, E *e)
if (rtype(i->to) == RSlot) { if (rtype(i->to) == RSlot) {
r = i->to; r = i->to;
if (!isreg(i->arg[0])) { if (!isreg(i->arg[0])) {
i->to = TMP(R18); i->to = TMP(IP1);
emitins(i, e); emitins(i, e);
i->arg[0] = i->to; i->arg[0] = i->to;
} }
@ -414,7 +414,7 @@ emitins(Ins *i, E *e)
emitins(i, e); emitins(i, e);
break; break;
default: default:
assert(i->to.val != R18); assert(i->to.val != IP1);
goto Table; goto Table;
} }
break; break;

View File

@ -16,7 +16,7 @@ int arm64_rclob[] = {
-1 -1
}; };
#define RGLOB (BIT(FP) | BIT(SP) | BIT(R18)) #define RGLOB (BIT(FP) | BIT(SP) | BIT(IP1) | BIT(R18))
static int static int
arm64_memargs(int op) arm64_memargs(int op)
@ -31,7 +31,7 @@ arm64_memargs(int op)
.fpr0 = V0, \ .fpr0 = V0, \
.nfpr = NFPR, \ .nfpr = NFPR, \
.rglob = RGLOB, \ .rglob = RGLOB, \
.nrglob = 3, \ .nrglob = 4, \
.rsave = arm64_rsave, \ .rsave = arm64_rsave, \
.nrsave = {NGPS, NFPS}, \ .nrsave = {NGPS, NFPS}, \
.retregs = arm64_retregs, \ .retregs = arm64_retregs, \