summary refs log tree commit diff
path: root/rv64
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 /rv64
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 'rv64')
-rw-r--r--rv64/emit.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/rv64/emit.c b/rv64/emit.c
index f9e58da..f9df146 100644
--- a/rv64/emit.c
+++ b/rv64/emit.c
@@ -116,9 +116,11 @@ static char *rname[] = {
 };
 
 static int64_t
-slot(int s, Fn *fn)
+slot(Ref r, Fn *fn)
 {
-	s = ((int32_t)s << 3) >> 3;
+	int s;
+
+	s = rsval(r);
 	assert(s <= fn->slot);
 	if (s < 0)
 		return 8 * -s;
@@ -214,7 +216,7 @@ emitf(char *s, Ins *i, Fn *fn, FILE *f)
 				}
 				break;
 			case RSlot:
-				offset = slot(r.val, fn);
+				offset = slot(r, fn);
 				assert(offset >= -2048 && offset <= 2047);
 				fprintf(f, "%d(fp)", (int)offset);
 				break;
@@ -286,7 +288,7 @@ fixmem(Ref *pr, Fn *fn, FILE *f)
 		}
 	}
 	if (rtype(r) == RSlot) {
-		s = slot(r.val, fn);
+		s = slot(r, fn);
 		if (s < -2048 || s > 2047) {
 			fprintf(f, "\tli t6, %"PRId64"\n", s);
 			fprintf(f, "\tadd t6, fp, t6\n");
@@ -369,7 +371,7 @@ emitins(Ins *i, Fn *fn, FILE *f)
 	case Oaddr:
 		assert(rtype(i->arg[0]) == RSlot);
 		rn = rname[i->to.val];
-		s = slot(i->arg[0].val, fn);
+		s = slot(i->arg[0], fn);
 		if (-s < 2048) {
 			fprintf(f, "\tadd %s, fp, %"PRId64"\n", rn, s);
 		} else {