summaryrefslogtreecommitdiff
path: root/amd64
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2022-12-12 17:36:15 +0100
committerQuentin Carbonneaux <quentin@c9x.me>2022-12-12 22:16:33 +0100
commitc0f25aeae3ef5d5f4b6bc5678f8d8ce40597d673 (patch)
tree26b78f6db8a8fd46005ce94835b0135a6df4eef7 /amd64
parent2ec355df6adc457303fcf2076b559fefd80ee593 (diff)
downloadroux-c0f25aeae3ef5d5f4b6bc5678f8d8ce40597d673.tar.gz
new rsval() helper for signed Refs
The .val field is signed in RSlot. Add a new dedicated function to fetch it as a signed int.
Diffstat (limited to 'amd64')
-rw-r--r--amd64/emit.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index 9e5996b..9b8bb5d 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -142,20 +142,19 @@ static char *rname[][4] = {
static int
-slot(int s, Fn *fn)
+slot(Ref r, Fn *fn)
{
- struct { int i:29; } x;
+ int s;
- /* sign extend s using a bitfield */
- x.i = s;
- assert(x.i <= fn->slot);
+ s = rsval(r);
+ assert(s <= fn->slot);
/* specific to NAlign == 3 */
- if (x.i < 0)
- return -4 * x.i;
+ if (s < 0)
+ return -4 * s;
else if (fn->vararg)
- return -176 + -4 * (fn->slot - x.i);
+ return -176 + -4 * (fn->slot - s);
else
- return -4 * (fn->slot - x.i);
+ return -4 * (fn->slot - s);
}
static void
@@ -286,14 +285,14 @@ Next:
fprintf(f, "%%%s", regtoa(ref.val, sz));
break;
case RSlot:
- fprintf(f, "%d(%%rbp)", slot(ref.val, fn));
+ fprintf(f, "%d(%%rbp)", slot(ref, fn));
break;
case RMem:
Mem:
m = &fn->mem[ref.val];
if (rtype(m->base) == RSlot) {
off.type = CBits;
- off.bits.i = slot(m->base.val, fn);
+ off.bits.i = slot(m->base, fn);
addcon(&m->offset, &off);
m->base = TMP(RBP);
}
@@ -338,7 +337,7 @@ Next:
case RMem:
goto Mem;
case RSlot:
- fprintf(f, "%d(%%rbp)", slot(ref.val, fn));
+ fprintf(f, "%d(%%rbp)", slot(ref, fn));
break;
case RCon:
off = fn->con[ref.val];