summary refs log tree commit diff
path: root/lisc/isel.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-16 11:30:57 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-16 11:30:57 -0400
commitce7fd0cb49fc1864eb1ef290cd835a64ce25efbf (patch)
treed2883910b90a7e9c187bb3a1b5aec7c7b2cab5da /lisc/isel.c
parentdb6f7ad72dda70f5dd3b34a3faea1e08537e77be (diff)
downloadroux-ce7fd0cb49fc1864eb1ef290cd835a64ce25efbf.tar.gz
add unsigned division and remainder
Diffstat (limited to 'lisc/isel.c')
-rw-r--r--lisc/isel.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/lisc/isel.c b/lisc/isel.c
index da7e946..8752012 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -221,7 +221,9 @@ sel(Ins i, ANum *an, Fn *fn)
 	switch (i.op) {
 	case ODiv:
 	case ORem:
-		if (i.op == ODiv)
+	case OUDiv:
+	case OURem:
+		if (i.op == ODiv || i.op == OUDiv)
 			r0 = TMP(RAX), r1 = TMP(RDX);
 		else
 			r0 = TMP(RDX), r1 = TMP(RAX);
@@ -234,8 +236,13 @@ sel(Ins i, ANum *an, Fn *fn)
 			r0 = newtmp("isel", fn);
 		} else
 			r0 = i.arg[1];
-		emit(OXDiv, k, R, r0, R);
-		emit(OSign, k, TMP(RDX), TMP(RAX), R);
+		if (i.op == ODiv || i.op == ORem) {
+			emit(OXIDiv, k, R, r0, R);
+			emit(OSign, k, TMP(RDX), TMP(RAX), R);
+		} else {
+			emit(OXDiv, k, R, r0, R);
+			emit(OCopy, k, TMP(RDX), CON_Z, R);
+		}
 		emit(OCopy, k, TMP(RAX), i.arg[0], R);
 		if (rtype(i.arg[1]) == RCon)
 			emit(OCopy, k, r0, i.arg[1], R);