summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--all.h6
-rw-r--r--emit.c8
-rw-r--r--fold.c14
-rw-r--r--isel.c6
-rw-r--r--parse.c6
-rw-r--r--test/fpcnv.ssa4
6 files changed, 24 insertions, 20 deletions
diff --git a/all.h b/all.h
index 7f64360..29e8574 100644
--- a/all.h
+++ b/all.h
@@ -251,8 +251,10 @@ enum Op {
 
 	Oexts,
 	Otruncd,
-	Oftosi,
-	Ositof,
+	Ostosi,
+	Odtosi,
+	Oswtof,
+	Osltof,
 	Ocast,
 
 	Oalloc,
diff --git a/emit.c b/emit.c
index 77fc1d4..2c0b3cc 100644
--- a/emit.c
+++ b/emit.c
@@ -78,10 +78,10 @@ static struct {
 
 	{ Oexts,   Kd, "cvtss2sd %0, %=" },  /* see if factorization is possible */
 	{ Otruncd, Ks, "cvttsd2ss %0, %=" },
-	{ Oftosi,  Kw, "cvttss2si %0, %=" },
-	{ Oftosi,  Kl, "cvttsd2si %0, %=" },
-	{ Ositof,  Ks, "cvtsi2ss %W0, %=" },
-	{ Ositof,  Kd, "cvtsi2sd %L0, %=" },
+	{ Ostosi,  Ki, "cvttss2si%k %0, %=" },
+	{ Odtosi,  Ki, "cvttsd2si%k %0, %=" },
+	{ Oswtof,  Ka, "cvtsi2%k %W0, %=" },
+	{ Osltof,  Ka, "cvtsi2%k %L0, %=" },
 	{ Ocast,   Ki, "movq %D0, %L=" },
 	{ Ocast,   Ka, "movq %L0, %D=" },
 
diff --git a/fold.c b/fold.c
index 923029e..da566ab 100644
--- a/fold.c
+++ b/fold.c
@@ -374,12 +374,8 @@ foldint(Con *res, int op, int w, Con *cl, Con *cr)
 	case Oextuh: x = (uint16_t)l.u; break;
 	case Oextsw: x = (int32_t)l.u;  break;
 	case Oextuw: x = (uint32_t)l.u; break;
-	case Oftosi:
-		if (w)
-			x = (int64_t)cl->bits.d;
-		else
-			x = (int32_t)cl->bits.s;
-		break;
+	case Ostosi: x = w ? (int64_t)cl->bits.s : (int32_t)cl->bits.s; break;
+	case Odtosi: x = w ? (int64_t)cl->bits.d : (int32_t)cl->bits.d; break;
 	case Ocast:
 		x = l.u;
 		if (cl->type == CAddr)
@@ -457,7 +453,8 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr)
 		case Osub: xd = ld - rd; break;
 		case Odiv: xd = ld / rd; break;
 		case Omul: xd = ld * rd; break;
-		case Ositof: xd = cl->bits.i; break;
+		case Oswtof: xd = (int32_t)cl->bits.i; break;
+		case Osltof: xd = (int64_t)cl->bits.i; break;
 		case Oexts: xd = cl->bits.s; break;
 		case Ocast: xd = ld; break;
 		default: die("unreachable");
@@ -471,7 +468,8 @@ foldflt(Con *res, int op, int w, Con *cl, Con *cr)
 		case Osub: xs = ls - rs; break;
 		case Odiv: xs = ls / rs; break;
 		case Omul: xs = ls * rs; break;
-		case Ositof: xs = cl->bits.i; break;
+		case Oswtof: xs = (int32_t)cl->bits.i; break;
+		case Osltof: xs = (int64_t)cl->bits.i; break;
 		case Otruncd: xs = cl->bits.d; break;
 		case Ocast: xs = ls; break;
 		default: die("unreachable");
diff --git a/isel.c b/isel.c
index bebc47e..dd12da1 100644
--- a/isel.c
+++ b/isel.c
@@ -286,8 +286,10 @@ sel(Ins i, ANum *an, Fn *fn)
 	case Oor:
 	case Oxor:
 	case Oxtest:
-	case Oftosi:
-	case Ositof:
+	case Ostosi:
+	case Odtosi:
+	case Oswtof:
+	case Osltof:
 	case Oexts:
 	case Otruncd:
 	case Ocast:
diff --git a/parse.c b/parse.c
index 272db45..d4ed3f8 100644
--- a/parse.c
+++ b/parse.c
@@ -45,8 +45,10 @@ OpDesc opdesc[NOp] = {
 	[Oextub]  = { "extub",    0, {A(w,w,e,e), A(x,x,e,e)}, 0, 1, 1 },
 	[Oexts]   = { "exts",     0, {A(e,e,e,s), A(e,e,e,x)}, 0, 1, 1 },
 	[Otruncd] = { "truncd",   0, {A(e,e,d,e), A(e,e,x,e)}, 0, 1, 1 },
-	[Oftosi]  = { "ftosi",    0, {A(s,d,e,e), A(x,x,e,e)}, 0, 1, 1 },
-	[Ositof]  = { "sitof",    0, {A(e,e,w,l), A(e,e,x,x)}, 0, 1, 1 },
+	[Ostosi]  = { "stosi",    0, {A(s,s,e,e), A(x,x,e,e)}, 0, 1, 1 },
+	[Odtosi]  = { "dtosi",    0, {A(d,d,e,e), A(x,x,e,e)}, 0, 1, 1 },
+	[Oswtof]  = { "swtof",    0, {A(e,e,w,w), A(e,e,x,x)}, 0, 1, 1 },
+	[Osltof]  = { "sltof",    0, {A(e,e,l,l), A(e,e,x,x)}, 0, 1, 1 },
 	[Ocast]   = { "cast",     0, {A(s,d,w,l), A(x,x,x,x)}, 0, 1, 1 },
 	[Ocopy]   = { "copy",     1, {A(w,l,s,d), A(x,x,x,x)}, 0, 1, 0 },
 	[Onop]    = { "nop",      0, {A(x,x,x,x), A(x,x,x,x)}, 0, 1, 0 },
diff --git a/test/fpcnv.ssa b/test/fpcnv.ssa
index 06d2478..d9851d8 100644
--- a/test/fpcnv.ssa
+++ b/test/fpcnv.ssa
@@ -12,8 +12,8 @@ function s $fneg(s %f) {
 export
 function d $ftrunc(d %f) {
 @ftrunc
-	%l0 =l ftosi %f
-	%rt =d sitof %l0
+	%l0 =w dtosi %f
+	%rt =d swtof %l0
 	ret %rt
 }