shithub: scc

Download patch

ref: 51512afa27c440847be65034b0d9b333348006db
parent: 9207b9207c803a7af47b567badd3d5eb22ebfa3f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Apr 22 17:04:30 EDT 2016

[cc2-qbe] Add conversions from float to float

These conversions were lost in the previous commit, and they
were dealt like float to int conversions.

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -124,5 +124,8 @@
 	ASSWTOD,
 	ASSWTOS,
 	ASSLTOD,
-	ASSLTOS
+	ASSLTOS,
+
+	ASEXTS,
+	ASTRUNCD
 };
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -168,6 +168,10 @@
 		default:
 			abort();
 		}
+		/*
+		 * unsigned version of operations are always +1 the
+		 * signed version
+		 */
 		op += (td->flags & SIGNF) == 0;
 	} else if (disint) {
 		/* conversion from float to int */
@@ -182,7 +186,7 @@
 			abort();
 		}
 		/* TODO: Add signess */
-	} else {
+	} else if (sisint) {
 		/* conversion from int to float */
 		switch (ts->size) {
 		case 1:
@@ -201,6 +205,9 @@
 			abort();
 		}
 		/* TODO: Add signess */
+	} else {
+		/* conversion from float to float */
+		op = (td->size == 4) ? ASEXTS : ASTRUNCD;
 	}
 	code(op, tmpnode(nd), ns, NULL);
 	return nd;
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -118,6 +118,9 @@
 	[ASSWTOS] = {.fun = unary, .txt = "swtof", .letter = 's'},
 	[ASSLTOD] = {.fun = unary, .txt = "sltof", .letter = 'd'},
 	[ASSLTOS] = {.fun = unary, .txt = "sltof", .letter = 's'},
+
+	[ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
+	[ASSLTOS]= {.fun = unary, .txt = "truncd", .letter = 's'},
 };
 
 /*
--