summary refs log tree commit diff
path: root/lisc/emit.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-05 21:46:15 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:30 -0400
commite5983ba1a2174fe7fd004692a427aae5bfc0dc4c (patch)
treeb763a06abb664a8a2b0a3c89818897d30e0837f4 /lisc/emit.c
parent7cb3e8587f7dbcbe795114f9ea5584009842ea29 (diff)
downloadroux-e5983ba1a2174fe7fd004692a427aae5bfc0dc4c.tar.gz
fix 2 bad bugs in rega and improve substraction
The substraction contrained the register allocator
to allocate a different register for the result and
the second operand, now, we use a neg trick to compile
it down.  The machinery that was setup is, regardless,
interesting and will have to be used for floating
point computations (division).

The first bug in rega made broke the explicited loop
invariant:  we were using register allocation unavailable
information from other blocks.  It's still unclear
how we got wrong results from that considering mappings
are all 0-initialized.

The second bug is a stupid one, one sizeof operator was
missing from a memcpy...
Diffstat (limited to 'lisc/emit.c')
-rw-r--r--lisc/emit.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index 1867097..a1a70c4 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -128,7 +128,12 @@ eins(Ins i, Fn *fn, FILE *f)
 	case OAdd:
 	case OSub:
 		if (req(i.to, i.arg[1])) {
-			if (!opdesc[i.op].comm)
+			if (i.op == OSub) {
+				eop("neg", i.to, R, fn, f);
+				eop("add", i.arg[0], i.to, fn, f);
+				break;
+			}
+			if (opdesc[i.op].comm != T)
 				diag("emit: unhandled instruction (1)");
 			i.arg[1] = i.arg[0];
 			i.arg[0] = i.to;