summary refs log tree commit diff
path: root/rv64
diff options
context:
space:
mode:
authorAlexey Yerin <yyp@disroot.org>2022-06-12 22:29:32 +0300
committerQuentin Carbonneaux <quentin@c9x.me>2022-06-14 09:12:19 +0200
commit1162359a198ab6a18a734cb9f7955d0b28e342b6 (patch)
treea4ec5b9c106bb9c2b14b87150b16dae2664e5565 /rv64
parentc9f04db881e8ec0bb0beeba6274a5755c46cb534 (diff)
downloadroux-1162359a198ab6a18a734cb9f7955d0b28e342b6.tar.gz
rv64: implement Oswap for floating-point types
Diffstat (limited to 'rv64')
-rw-r--r--rv64/all.h11
-rw-r--r--rv64/emit.c8
-rw-r--r--rv64/targ.c7
3 files changed, 15 insertions, 11 deletions
diff --git a/rv64/all.h b/rv64/all.h
index eb2daa9..a03973c 100644
--- a/rv64/all.h
+++ b/rv64/all.h
@@ -11,22 +11,25 @@ enum Rv64Reg {
 	S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11,
 
 	/* globally live */
-	FP, SP, GP, TP, RA, T6,
+	FP, SP, GP, TP, RA,
 
 	/* FP caller-save */
-	FT0, FT1, FT2, FT3, FT4, FT5, FT6, FT7, FT8, FT9, FT10, FT11,
+	FT0, FT1, FT2, FT3, FT4, FT5, FT6, FT7, FT8, FT9, FT10,
 	FA0, FA1, FA2, FA3, FA4, FA5, FA6, FA7,
 
 	/* FP callee-save */
 	FS0, FS1, FS2, FS3, FS4, FS5, FS6, FS7, FS8, FS9, FS10, FS11,
 
+	/* reserved (see rv64/emit.c) */
+	T6, FT11,
+
 	NFPR = FS11 - FT0 + 1,
-	NGPR = T6 - T0 + 1,
+	NGPR = RA - T0 + 1,
 	NGPS = A7 - T0 + 1,
 	NFPS = FA7 - FT0 + 1,
 	NCLR = (S11 - S1 + 1) + (FS11 - FS0 + 1),
 };
-MAKESURE(reg_not_tmp, FS11 < (int)Tmp0);
+MAKESURE(reg_not_tmp, FT11 < (int)Tmp0);
 
 struct Rv64Op {
 	char imm;
diff --git a/rv64/emit.c b/rv64/emit.c
index 841c555..2656c60 100644
--- a/rv64/emit.c
+++ b/rv64/emit.c
@@ -89,6 +89,7 @@ static struct {
 	{ Ocopy,   Ki, "mv %=, %0" },
 	{ Ocopy,   Ka, "fmv.%k %=, %0" },
 	{ Oswap,   Ki, "mv %?, %0\n\tmv %0, %1\n\tmv %1, %?" },
+	{ Oswap,   Ka, "fmv.%k %?, %0\n\tfmv.%k %0, %1\n\tfmv.%k %1, %?" },
 	{ Oreqz,   Ki, "seqz %=, %0" },
 	{ Ornez,   Ki, "snez %=, %0" },
 	{ Ocall,   Kw, "jalr %0" },
@@ -101,16 +102,17 @@ static char *rname[] = {
 	[GP] = "gp",
 	[TP] = "tp",
 	[RA] = "ra",
-	[T6] = "t6",
 	[T0] = "t0", "t1", "t2", "t3", "t4", "t5",
 	[A0] = "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
 	[S1] = "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8",
 	       "s9", "s10", "s11",
 	[FT0] = "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7",
-	        "ft8", "ft9", "ft10", "ft11",
+	        "ft8", "ft9", "ft10",
 	[FA0] = "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7",
 	[FS0] = "fs0", "fs1", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7",
 	        "fs8", "fs9", "fs10", "fs11",
+	[T6] = "t6",
+	[FT11] = "ft11",
 };
 
 static int64_t
@@ -162,7 +164,7 @@ emitf(char *s, Ins *i, Fn *fn, FILE *f)
 			if (KBASE(k) == 0)
 				fputs("t6", f);
 			else
-				abort();
+				fputs("ft11", f);
 			break;
 		case 'k':
 			if (i->cls != Kl)
diff --git a/rv64/targ.c b/rv64/targ.c
index d42d0a1..9360cf7 100644
--- a/rv64/targ.c
+++ b/rv64/targ.c
@@ -11,7 +11,7 @@ int rv64_rsave[] = {
 	A0, A1, A2, A3, A4, A5, A6, A7,
 	FA0, FA1, FA2,  FA3,  FA4, FA5, FA6, FA7,
 	FT0, FT1, FT2,  FT3,  FT4, FT5, FT6, FT7,
-	FT8, FT9, FT10, FT11,
+	FT8, FT9, FT10,
 	-1
 };
 int rv64_rclob[] = {
@@ -22,8 +22,7 @@ int rv64_rclob[] = {
 	-1
 };
 
-/* T6 used as swap register (TODO: is there a better choice?) */
-#define RGLOB (BIT(FP) | BIT(SP) | BIT(GP) | BIT(TP) | BIT(RA) | BIT(T6))
+#define RGLOB (BIT(FP) | BIT(SP) | BIT(GP) | BIT(TP) | BIT(RA))
 
 static int
 rv64_memargs(int op)
@@ -39,7 +38,7 @@ Target T_rv64 = {
 	.fpr0 = FT0,
 	.nfpr = NFPR,
 	.rglob = RGLOB,
-	.nrglob = 6,
+	.nrglob = 5,
 	.rsave = rv64_rsave,
 	.nrsave = {NGPS, NFPS},
 	.retregs = rv64_retregs,