summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-11 16:26:12 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit1583f4bd329440a78f6d261cfad1043095439bbd (patch)
treeec42503fb37a34bfad87605fc6eda4308a638263
parentf6df9e55c53cbab88f8222e4c13390c7adf03e6f (diff)
downloadroux-1583f4bd329440a78f6d261cfad1043095439bbd.tar.gz
split store into store{w,l}
-rw-r--r--lisc/emit.c105
-rw-r--r--lisc/isel.c14
-rw-r--r--lisc/lisc.h3
-rw-r--r--lisc/parse.c5
-rw-r--r--lisc/spill.c13
5 files changed, 64 insertions, 76 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index cd82c0a..d72ea79 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -1,59 +1,25 @@
 #include "lisc.h"
 
 
-static char *rtoa[] = {
-	[RXX ] = "OH GOD!",
-	[RAX ] = "rax",
-	[RBX ] = "rbx",
-	[RCX ] = "rcx",
-	[RDX ] = "rdx",
-	[RSI ] = "rsi",
-	[RDI ] = "rdi",
-	[RBP ] = "rbp",
-	[RSP ] = "rsp",
-	[R8  ] = "r8",
-	[R9  ] = "r9",
-	[R10 ] = "r10",
-	[R11 ] = "r11",
-	[R12 ] = "r12",
-	[R13 ] = "r13",
-	[R14 ] = "r14",
-	[R15 ] = "r15",
-	[EAX ] = "eax",
-	[EBX ] = "ebx",
-	[ECX ] = "ecx",
-	[EDX ] = "edx",
-	[ESI ] = "esi",
-	[EDI ] = "edi",
-	[R8D ] = "r8d",
-	[R9D ] = "r9d",
-	[R10D] = "r10d",
-	[R11D] = "r11d",
-	[R12D] = "r12d",
-	[R13D] = "r13d",
-	[R14D] = "r14d",
-	[R15D] = "r15d",
-};
-
-enum { SShort, SByte };
-static char *rsub[][2] = {
-	[RXX] = {"OH GOD!", "OH NO!"},
-	[RAX] = {"ax", "al"},
-	[RBX] = {"bx", "bl"},
-	[RCX] = {"cx", "cl"},
-	[RDX] = {"dx", "dl"},
-	[RSI] = {"si", "sil"},
-	[RDI] = {"di", "dil"},
-	[RBP] = {"bp", "bpl"},
-	[RSP] = {"sp", "spl"},
-	[R8 ] = {"r8w", "r8b"},
-	[R9 ] = {"r9w", "r9b"},
-	[R10] = {"r10w", "r10b"},
-	[R11] = {"r11w", "r11b"},
-	[R12] = {"r12w", "r12b"},
-	[R13] = {"r13w", "r13b"},
-	[R14] = {"r14w", "r14b"},
-	[R15] = {"r15w", "r15b"},
+enum { SLong, SWord, SShort, SByte };
+static char *rsub[][4] = {
+	[RXX] = {"BLACK CAT", "BROKEN MIRROR", "666", "NOOOO!"},
+	[RAX] = {"rax", "eax", "ax", "al"},
+	[RBX] = {"rbx", "ebx", "bx", "bl"},
+	[RCX] = {"rcx", "ecx", "cx", "cl"},
+	[RDX] = {"rdx", "edx", "dx", "dl"},
+	[RSI] = {"rsi", "esi", "si", "sil"},
+	[RDI] = {"rdi", "edi", "di", "dil"},
+	[RBP] = {"rbp", "ebp", "bp", "bpl"},
+	[RSP] = {"rsp", "esp", "sp", "spl"},
+	[R8 ] = {"r8" , "r8d", "r8w", "r8b"},
+	[R9 ] = {"r9" , "r9d", "r9w", "r9b"},
+	[R10] = {"r10", "r10d", "r10w", "r10b"},
+	[R11] = {"r11", "r11d", "r11w", "r11b"},
+	[R12] = {"r12", "r12d", "r12w", "r12b"},
+	[R13] = {"r13", "r13d", "r13w", "r13b"},
+	[R14] = {"r14", "r14d", "r14w", "r14b"},
+	[R15] = {"r15", "r15d", "r15w", "r15b"},
 };
 
 static char *ctoa[NCmp] = {
@@ -65,6 +31,15 @@ static char *ctoa[NCmp] = {
 	[Cne ] = "ne",
 };
 
+static char *
+rtoa(int r)
+{
+	if (r < EAX)
+		return rsub[r][SLong];
+	else
+		return rsub[RBASE(r)][SWord];
+}
+
 static int
 cneg(int cmp)
 {
@@ -101,7 +76,7 @@ eref(Ref r, Fn *fn, FILE *f)
 {
 	switch (rtype(r)) {
 	case RReg:
-		fprintf(f, "%%%s", rtoa[r.val]);
+		fprintf(f, "%%%s", rtoa(r.val));
 		break;
 	case RSlot:
 		fprintf(f, "-%d(%%rbp)", 8 * r.val);
@@ -160,9 +135,10 @@ eins(Ins i, Fn *fn, FILE *f)
 		[OLoadub] = "movzb",
 	};
 	static char *stoa[] = {
-		[OStore  - OStore] = "l",
-		[OStores - OStore] = "w",
-		[OStoreb - OStore] = "b",
+		[OStorel - OStorel] = "q",
+		[OStorew - OStorel] = "l",
+		[OStores - OStorel] = "w",
+		[OStoreb - OStorel] = "b",
 	};
 	int r;
 
@@ -186,23 +162,16 @@ eins(Ins i, Fn *fn, FILE *f)
 		if (!req(i.arg[0], i.to))
 			eop("mov", i.arg[0], i.to, fn, f);
 		break;
-	case OStore:
-		/* todo, fix inconsistency */
-		if (rtype(i.arg[0]) == RCon)
-			fprintf(f, "\tmovl ");
-		else
-			fprintf(f, "\tmov ");
-		eref(i.arg[0], fn, f);
-	if (0) {
+	case OStorel:
+	case OStorew:
 	case OStores:
 	case OStoreb:
-		fprintf(f, "\tmov%s ", stoa[i.op - OStore]);
+		fprintf(f, "\tmov%s ", stoa[i.op - OStorel]);
 		if (rtype(i.arg[0]) == RReg) {
 			r = RBASE(i.arg[0].val);
-			fprintf(f, "%%%s", rsub[r][i.op - OStores]);
+			fprintf(f, "%%%s", rsub[r][i.op - OStorel]);
 		} else
 			eref(i.arg[0], fn, f);
-	}
 		fprintf(f, ", ");
 		emem(i.arg[1], fn, f);
 		fprintf(f, "\n");
diff --git a/lisc/isel.c b/lisc/isel.c
index 05f5f6e..e33c11e 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -115,7 +115,8 @@ sel(Ins i, Fn *fn)
 	case OAdd:
 	case OSub:
 	case OCopy:
-	case OStore:
+	case OStorel:
+	case OStorew:
 	case OStoreb:
 	case OStores:
 	case OLoad:
@@ -153,8 +154,15 @@ flagi(Ins *i0, Ins *i)
 		case OSub:
 			return i;
 		case OCopy: /* <arch> flag-transparent */
-		case OStore:
-		case OLoad:;
+		case OStorel:
+		case OStorew:
+		case OStoreb:
+		case OStores:
+		case OLoad:
+		case OLoadss:
+		case OLoadus:
+		case OLoadsb:
+		case OLoadub:;
 		}
 	return 0;
 }
diff --git a/lisc/lisc.h b/lisc/lisc.h
index e57582d..cd64e29 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -128,7 +128,8 @@ enum {
 	ORem,
 	OCmp,
 	OCmp1 = OCmp + NCmp-1,
-	OStore,
+	OStorel,
+	OStorew,
 	OStores,
 	OStoreb,
 	OLoad,
diff --git a/lisc/parse.c b/lisc/parse.c
index 507244c..104c2a2 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -16,7 +16,8 @@ OpDesc opdesc[NOp] = {
 	[OSub]    = { "sub",    2, 2 },
 	[ODiv]    = { "div",    2, 2 },
 	[ORem]    = { "rem",    2, 2 },
-	[OStore]  = { "store",  2, 0 },
+	[OStorel] = { "storel", 2, 0 },
+	[OStorew] = { "storew", 2, 0 },
 	[OStores] = { "stores", 2, 0 },
 	[OStoreb] = { "storeb", 2, 0 },
 	[OLoad]   = { "load",   1, 0 },
@@ -365,7 +366,7 @@ parseline(PState ps)
 		err("label or end of file expected");
 	switch (t) {
 	default:
-		if (t == OStore || t == OStores || t == OStoreb) {
+		if (OStorel <= t && t <= OStoreb) {
 			/* operations without result */
 			r = R;
 			op = t;
diff --git a/lisc/spill.c b/lisc/spill.c
index 14b33c5..6554316 100644
--- a/lisc/spill.c
+++ b/lisc/spill.c
@@ -184,6 +184,15 @@ emit(short op, Ref to, Ref arg0, Ref arg1)
 	*--curi = (Ins){op, to, {arg0, arg1}};
 }
 
+static void
+store(Ref r, int s)
+{
+	if (tmp[r.val].type == TLong)
+		emit(OStorel, R, r, SLOT(s));
+	else
+		emit(OStorew, R, r, SLOT(s));
+}
+
 static int
 limit(Bits *b, int k, Bits *fst)
 {
@@ -372,7 +381,7 @@ spill(Fn *fn)
 				BSET(w, i->arg[1].val);
 			j -= setloc(&i->arg[1], &v, &w);
 			if (s)
-				emit(OStore, R, i->to, SLOT(s));
+				store(i->to, s);
 			emit(i->op, i->to, i->arg[0], i->arg[1]);
 		}
 
@@ -383,7 +392,7 @@ spill(Fn *fn)
 				BCLR(v, t);
 				s = tmp[t].spill;
 				if (s)
-					emit(OStore, R, p->to, SLOT(s));
+					store(p->to, s);
 			} else
 				p->to = slot(p->to.val);
 		}