ref: 97635cb8850d14b42c4e6882d0d7b6aa05485271
parent: 47188c33df351d338a569e99006bd5761bddc715
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Oct 2 14:52:17 EDT 2013
Fix floating point comparison.
We now generate appropriate assembly. Hopefully.
--- a/6/insns.def
+++ b/6/insns.def
@@ -62,7 +62,7 @@
Insn(Icvttsi2sd, "\tcvttsd2si%2t %x,%r\n", Use(.l={1}), Def(.l={2})) Insn(Ifdiv, "\tdiv%t %x,%r\n", Use(.l={1},.r={Reax,Redx}), Def(.r={Reax,Redx})) Insn(Ifmul, "\tmul%t %x,%r\n", Use(.l={1,2}), Def(.l={2}))-Insn(Icomi, "\tcomi%d %x,%r\n", Use(.l={1,2}), Def())+Insn(Icomi, "\tcomi%t %x,%r\n", Use(.l={1,2}), Def())/* branch instructions */
Insn(Icall, "\tcall %v\n", Use(.l={1}), Def(.r={Rrax}))--- a/6/isel.c
+++ b/6/isel.c
@@ -40,17 +40,18 @@
/* used to decide which operator is appropriate
* for implementing various conditional operators */
struct {- AsmOp test;
+ AsmOp itest;
+ AsmOp fptest;
AsmOp jmp;
AsmOp getflag;
} reloptab[Numops] = {- [Olnot] = {Itest, Ijz, Isetz},- [Oeq] = {Icmp, Ijz, Isetz},- [One] = {Icmp, Ijnz, Isetnz},- [Ogt] = {Icmp, Ijg, Isetg},- [Oge] = {Icmp, Ijge, Isetge},- [Olt] = {Icmp, Ijl, Isetl},- [Ole] = {Icmp, Ijle, Isetle}+ [Olnot] = {Itest, 0, Ijz, Isetz}, /* lnot invalid for floats */+ [Oeq] = {Icmp, Icomi, Ijz, Isetz},+ [One] = {Icmp, Icomi, Ijnz, Isetnz},+ [Ogt] = {Icmp, Icomi, Ijg, Isetg},+ [Oge] = {Icmp, Icomi, Ijge, Isetge},+ [Olt] = {Icmp, Icomi, Ijl, Isetl},+ [Ole] = {Icmp, Icomi, Ijle, Isetle}};
static Mode mode(Node *n)
@@ -221,6 +222,14 @@
return inr(s, a);
}
+static int floatcompare(Node *e)
+{+ if (exprop(e) == Ovar || exprop(e) == Olit)
+ return floatnode(e);
+ assert(e->expr.nargs > 0);
+ return floatnode(e->expr.args[0]);
+}
+
/* If we're testing equality, etc, it's a bit silly
* to generate the test, store it to a bite, expand it
* to the right width, and then test it again. Try to optimize
@@ -236,7 +245,10 @@
Loc *l1, *l2;
AsmOp cond, jmp;
- cond = reloptab[exprop(args[0])].test;
+ if (floatcompare(args[0]))
+ cond = reloptab[exprop(args[0])].fptest;
+ else
+ cond = reloptab[exprop(args[0])].itest;
jmp = reloptab[exprop(args[0])].jmp;
/* if we have a cond, we're knocking off the redundant test,
* and want to eval the children */
@@ -542,7 +554,8 @@
a = inr(s, selexpr(s, args[0]));
b = locreg(ModeB);
r = locreg(mode(n));
- g(s, reloptab[exprop(n)].test, a, a, NULL);
+ /* lnot only valid for integer-like values */
+ g(s, reloptab[exprop(n)].itest, a, a, NULL);
g(s, reloptab[exprop(n)].getflag, b, NULL);
movz(s, b, r);
break;
@@ -553,7 +566,10 @@
a = inr(s, a);
c = locreg(ModeB);
r = locreg(mode(n));
- g(s, reloptab[exprop(n)].test, b, a, NULL);
+ if (floatnode(args[0]))
+ g(s, reloptab[exprop(n)].fptest, b, a, NULL);
+ else
+ g(s, reloptab[exprop(n)].itest, b, a, NULL);
g(s, reloptab[exprop(n)].getflag, c, NULL);
movz(s, c, r);
return r;
--
⑨