ref: ab7b0d214f1416e8743a9389d52343077fe7ce0c
parent: 273d2b3897a25a3e455f8fce38c604be060fc502
author: Ori Bernstein <[email protected]>
date: Mon Sep 22 07:52:39 EDT 2014
Fix flt32<->flt64 casts.
--- a/6/insns.def
+++ b/6/insns.def
@@ -69,6 +69,8 @@
Insn(Imovs, "\tmovs%1t %x,%x\n", Use(.l={1}), Def(.l={2}))
Insn(Icvttsd2si, "\tcvttsd2si%2t %x,%r\n", Use(.l={1}), Def(.l={2}))
Insn(Icvttsi2sd, "\tcvttsi2sd%2t %x,%f\n", Use(.l={1}), Def(.l={2}))
+Insn(Icvttsd2ss, "\tcvtsd2ss %x,%f\n", Use(.l={1}), Def(.l={2}))
+Insn(Icvttss2sd, "\tcvtss2sd %x,%f\n", Use(.l={1}), Def(.l={2}))
Insn(Iadds, "\tadds%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Isubs, "\tsubs%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
Insn(Imuls, "\tmuls%t %x,%f\n", Use(.l={1,2}), Def(.l={2}))
--- a/6/isel.c
+++ b/6/isel.c
@@ -186,7 +186,7 @@
assert(b->type == Locreg);
if (a->type == Locreg)
- l = locmem(0, b, Rnone, a->mode);
+ l = locmem(0, b, NULL, a->mode);
else
l = a;
if (isfloatmode(b->mode))
@@ -201,7 +201,7 @@
assert(a->type == Locreg || a->type == Loclit);
if (b->type == Locreg)
- l = locmem(0, b, Rnone, b->mode);
+ l = locmem(0, b, NULL, b->mode);
else
l = b;
if (isfloatmode(b->mode))
@@ -347,7 +347,7 @@
if (b->type != Locreg)
b = inr(s, b);
if (o->type == Loclit) {
- l = locmem(scale*o->lit, b, Rnone, m);
+ l = locmem(scale*o->lit, b, NULL, m);
} else {
b = inr(s, b);
o = inr(s, o);
@@ -356,7 +356,7 @@
} else {
l = selexpr(s, e);
l = inr(s, l);
- l = locmem(0, l, Rnone, m);
+ l = locmem(0, l, NULL, m);
}
assert(l != NULL);
return l;
@@ -703,6 +703,8 @@
al = alignto(1, args[0]->expr.type->sub[0]);
blit(s, a, r, 0, 0, args[2]->expr.args[0]->lit.intval, al);
break;
+
+ /* cast operators that actually modify the values */
case Otrunc:
a = selexpr(s, args[0]);
a = inr(s, a);
@@ -734,6 +736,15 @@
r = locreg(mode(n));
g(s, Icvttsd2si, a, b, NULL);
g(s, Imov, b, r, NULL);
+ break;
+
+ case Oflt2flt:
+ a = selexpr(s, args[0]);
+ r = locreg(mode(n));
+ if (a->mode == ModeD)
+ g(s, Icvttsd2ss, a, r, NULL);
+ else
+ g(s, Icvttss2sd, a, r, NULL);
break;
/* These operators should never show up in the reduced trees,
--- a/6/simp.c
+++ b/6/simp.c
@@ -1058,6 +1058,10 @@
r = mkexpr(val->line, Oflt2int, rval(s, val, NULL), NULL);
r->expr.type = to;
break;
+ case Tyflt32: case Tyflt64:
+ r = mkexpr(val->line, Oflt2flt, rval(s, val, NULL), NULL);
+ r->expr.type = to;
+ break;
default:
fatal(val->line, "Bad cast from %s to %s",
tystr(exprtype(val)), tystr(to));
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1409,7 +1409,7 @@
case Oslbase: case Osllen:
case Oblit: case Numops:
case Otrunc: case Oswiden: case Ozwiden:
- case Oint2flt: case Oflt2int:
+ case Oint2flt: case Oflt2int: case Oflt2flt:
case Ofadd: case Ofsub: case Ofmul: case Ofdiv: case Ofneg:
case Ofeq: case Ofne: case Ofgt: case Ofge: case Oflt: case Ofle:
case Oueq: case Oune: case Ougt: case Ouge: case Oult: case Oule:
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -68,6 +68,7 @@
O(Oswiden, 1) /* sign-extending widening cast */
O(Oflt2int, 1) /* float to int conversion */
O(Oint2flt, 1) /* int to float conversion */
+O(Oflt2flt, 1) /* flt32<->flt64 conversion */
O(Ofadd, 1)
O(Ofsub, 1)
O(Ofmul, 1)