shithub: scc

Download patch

ref: dbb8b774527a030a3b83b8a422234755fc928ed3
parent: 89ce7731fc48c5e3d374ef3082da7958a0e4bc49
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Mar 31 09:57:49 EDT 2022

cc2/qbe: Add support for sign in float casts

Float casts were missing the unsigned version of the operators.

--- a/src/cmd/cc/cc2/target/qbe/arch.h
+++ b/src/cmd/cc/cc2/target/qbe/arch.h
@@ -100,14 +100,22 @@
 	ASUEXTWL,
 
 	ASSTOL,
+	ASSTOUL,
 	ASSTOW,
+	ASSTOUW,
 	ASDTOL,
+	ASDTOUL,
 	ASDTOW,
+	ASDTOUW,
 
 	ASSWTOD,
+	ASUWTOD,
 	ASSWTOS,
+	ASUWTOS,
 	ASSLTOD,
+	ASULTOD,
 	ASSLTOS,
+	ASULTOS,
 
 	ASEXTS,
 	ASTRUNCD,
--- a/src/cmd/cc/cc2/target/qbe/cgen.c
+++ b/src/cmd/cc/cc2/target/qbe/cgen.c
@@ -258,7 +258,11 @@
 		default:
 			abort();
 		}
-		/* TODO: Add signess */
+		/*
+		 * unsigned version of operations are always +1 the
+		 * signed version
+		 */
+		op += (td->flags & SIGNF) == 0;
 	} else if (s_isint) {
 		/* conversion from int to float */
 		switch (ts->size) {
@@ -275,7 +279,11 @@
 		default:
 			abort();
 		}
-		/* TODO: Add signess */
+		/*
+		 * unsigned version of operations are always +1 the
+		 * signed version
+		 */
+		op += (ts->flags & SIGNF) == 0;
 	} else {
 		/* conversion from float to float */
 		op = (td->size == 4) ? ASEXTS : ASTRUNCD;
--- a/src/cmd/cc/cc2/target/qbe/code.c
+++ b/src/cmd/cc/cc2/target/qbe/code.c
@@ -125,14 +125,22 @@
 	[ASUEXTWL]=  {.fun = unary, .txt = "extuw", .letter = 'l'},
 
 	[ASSTOL] = {.fun = unary, .txt = "stosi", .letter = 'l'},
+	[ASSTOUL] = {.fun = unary, .txt = "stoui", .letter = 'l'},
 	[ASSTOW] = {.fun = unary, .txt = "stosi", .letter = 'w'},
+	[ASSTOUW] = {.fun = unary, .txt = "stoui", .letter = 'w'},
 	[ASDTOL] = {.fun = unary, .txt = "dtosi", .letter = 'l'},
+	[ASDTOUL] = {.fun = unary, .txt = "dtoui", .letter = 'l'},
 	[ASDTOW] = {.fun = unary, .txt = "dtosi", .letter = 'w'},
+	[ASDTOUW] = {.fun = unary, .txt = "dtoui", .letter = 'w'},
 
 	[ASSWTOD] = {.fun = unary, .txt = "swtof", .letter = 'd'},
+	[ASUWTOD] = {.fun = unary, .txt = "uwtof", .letter = 'd'},
 	[ASSWTOS] = {.fun = unary, .txt = "swtof", .letter = 's'},
+	[ASUWTOS] = {.fun = unary, .txt = "uwtof", .letter = 's'},
 	[ASSLTOD] = {.fun = unary, .txt = "sltof", .letter = 'd'},
+	[ASULTOD] = {.fun = unary, .txt = "ultof", .letter = 'd'},
 	[ASSLTOS] = {.fun = unary, .txt = "sltof", .letter = 's'},
+	[ASULTOS] = {.fun = unary, .txt = "ultof", .letter = 's'},
 
 	[ASEXTS] = {.fun = unary, .txt = "exts", .letter = 'd'},
 	[ASTRUNCD] = {.fun = unary, .txt = "truncd", .letter = 's'},