summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2017-06-06 10:09:31 -0400
committerQuentin Carbonneaux <quentin@c9x.me>2017-06-06 10:09:31 -0400
commit5dcf8c14cbefb3f96262e5fbe5168cfe48e6fd3a (patch)
tree0261a28ea1457d1c1841c3530ef10470f4487a0f
parent66288673cdce588bf81612c0599047665afefce7 (diff)
downloadroux-5dcf8c14cbefb3f96262e5fbe5168cfe48e6fd3a.tar.gz
fix floating-point division
It never worked until today.
-rw-r--r--amd64/emit.c10
-rw-r--r--amd64/isel.c2
2 files changed, 12 insertions, 0 deletions
diff --git a/amd64/emit.c b/amd64/emit.c
index cd485bb..4d4d3be 100644
--- a/amd64/emit.c
+++ b/amd64/emit.c
@@ -405,6 +405,16 @@ emitins(Ins i, Fn *fn, FILE *f)
 			break;
 		}
 		goto Table;
+	case Odiv:
+		/* adjust the instruction when the conversion to
+		 * a 2-address division is impossible */
+		if (req(i.to, i.arg[1])) {
+			i.arg[1] = TMP(XMM0+15);
+			emitf("mov%k %=, %1", &i, fn, f);
+			emitf("mov%k %0, %=", &i, fn, f);
+			i.arg[0] = i.to;
+		}
+		goto Table;
 	case Ocopy:
 		/* make sure we don't emit useless copies,
 		 * also, we can use a trick to load 64-bits
diff --git a/amd64/isel.c b/amd64/isel.c
index 39fc9e8..180439b 100644
--- a/amd64/isel.c
+++ b/amd64/isel.c
@@ -200,6 +200,8 @@ sel(Ins i, ANum *an, Fn *fn)
 	case Orem:
 	case Oudiv:
 	case Ourem:
+		if (KBASE(k) == 1)
+			goto Emit;
 		if (i.op == Odiv || i.op == Oudiv)
 			r0 = TMP(RAX), r1 = TMP(RDX);
 		else