shithub: scc

Download patch

ref: d3bf24974993f688e9666de0914519fdba97512a
parent: 7384036a2738f3f975eeebec10156eaea478e386
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Sep 22 05:37:34 EDT 2016

[cc2-qbe] Use specific load versions

There are versions of load for the different sizes and
with or without sign extension, because load was only
loading a full word (equivalent to loaduw).

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -13,9 +13,12 @@
 	ASSTS,
 	ASSTD,
 
-	ASLDB,
-	ASLDH,
-	ASLDW,
+	ASLDSB,
+	ASLDUB,
+	ASLDSH,
+	ASLDUH,
+	ASLDSW,
+	ASLDUW,
 	ASLDL,
 	ASLDS,
 	ASLDD,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -112,27 +112,35 @@
 load(Type *tp, Node *np, Node *new)
 {
 	int op;
+	int flags = tp->flags;
 
-	if (tp->flags & AGGRF) {
+	if (flags & AGGRF) {
 		*new = *np;
 		return new;
 	}
 	switch (tp->size) {
 	case 1:
-		op = ASLDB;
+		op = ASLDSB;
 		break;
 	case 2:
-		op = ASLDH;
+		op = ASLDSH;
 		break;
 	case 4:
-		op = (tp->flags & FLOATF) ? ASLDS : ASLDW;
+		op = (flags & FLOATF) ? ASLDS : ASLDSW;
 		break;
 	case 8:
-		op = (tp->flags & FLOATF) ? ASLDD : ASLDL;
+		op = (flags & FLOATF) ? ASLDD : ASLDL;
 		break;
 	default:
 		abort();
 	}
+	/*
+	 * unsigned version of operations are always +1 the
+	 * signed version
+	 */
+	if ((flags & (INTF|SIGNF)) == INTF && tp->size < 8)
+		++op;
+
 	code(op, tmpnode(new, tp), np, NULL);
 
 	return new;
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -18,12 +18,15 @@
 	char *txt;
 	char letter;
 } optbl [] = {
-	[ASLDB]   =  {.fun = unary,  .txt = "load", .letter = 'b'},
-	[ASLDH]   =  {.fun = unary,  .txt = "load", .letter = 'h'},
-	[ASLDW]   =  {.fun = unary,  .txt = "load", .letter = 'w'},
-	[ASLDL]   =  {.fun = unary,  .txt = "load", .letter = 'l'},
-	[ASLDS]   =  {.fun = unary,  .txt = "load", .letter = 's'},
-	[ASLDD]   =  {.fun = unary,  .txt = "load", .letter = 'd'},
+	[ASLDSB]  =  {.fun = unary,  .txt = "loadsb", .letter = 'w'},
+	[ASLDUB]  =  {.fun = unary,  .txt = "loadub", .letter = 'w'},
+	[ASLDSH]  =  {.fun = unary,  .txt = "loadsh", .letter = 'w'},
+	[ASLDUH]  =  {.fun = unary,  .txt = "loaduh", .letter = 'w'},
+	[ASLDSW]  =  {.fun = unary,  .txt = "loadsw", .letter = 'w'},
+	[ASLDUW]  =  {.fun = unary,  .txt = "loaduw", .letter = 'w'},
+	[ASLDL]   =  {.fun = unary,  .txt = "loadl", .letter = 'l'},
+	[ASLDS]   =  {.fun = unary,  .txt = "loads", .letter = 's'},
+	[ASLDD]   =  {.fun = unary,  .txt = "loadd", .letter = 'd'},
 
 	[ASCOPYW] =  {.fun = unary,  .txt = "copy", .letter = 'w'},