shithub: scc

Download patch

ref: ff6393ec18d14fbbbe747c7543f664bb97c0ca46
parent: 771e9d2c95cb83c6ee2c33e415da03b5b7b291a5
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 21 13:42:23 EDT 2016

[cc2-qbe] Add support for sign in comparisions

Signed types and unsigned types have a different opcode in qbe, so
we have to look the signess of the types to see what is the opcode
we have to use.

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -16,9 +16,13 @@
 	ASSHLW,
 	ASSHRW,
 	ASLTW,
+	ASULTW,
 	ASGTW,
+	ASUGTW,
 	ASLEW,
+	ASULEW,
 	ASGEW,
+	ASUGEW,
 	ASEQW,
 	ASNEW,
 	ASBANDW,
@@ -34,9 +38,13 @@
 	ASSHLL,
 	ASSHRL,
 	ASLTL,
+	ASULTL,
 	ASGTL,
+	ASUGTL,
 	ASLEL,
+	ASULEL,
 	ASGEL,
+	ASUGEL,
 	ASEQL,
 	ASNEL,
 	ASBANDL,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -122,7 +122,7 @@
 	Node *l, *r;
 	Symbol *sym;
 	Type *tp;
-	int op;
+	int op, off;
 	char *tbl;
 
 	if (!np)
@@ -142,6 +142,16 @@
 	case OMEM:
 	case OAUTO:
 		return np;
+	case OLT:
+	case OGT:
+	case OLE:
+	case OGE:
+		/*
+		 * unsigned version of operations are always +1 the
+		 * signed version
+		 */
+		off = (tp->flags & SIGNF) == 0;
+		goto binary;
 	case OADD:
 	case OSUB:
 	case OMUL:
@@ -149,10 +159,6 @@
 	case ODIV:
 	case OSHL:
 	case OSHR:
-	case OLT:
-	case OGT:
-	case OLE:
-	case OGE:
 	case OBAND:
 	case OBOR:
 	case OBXOR:
@@ -159,6 +165,8 @@
 	case OCPL:
 	case OEQ:
 	case ONE:
+		off = 0;
+	binary:
 		switch (tp->size) {
 		case 4:
 			tbl = (tp->flags & INTF) ? opasmw : opasms;
@@ -169,8 +177,7 @@
 		default:
 			abort();
 		}
-		op = tbl[np->op];
-	binary:
+		op = tbl[np->op] + off;
 		if ((l->flags & (ISTMP|ISCONS)) == 0)
 			l = np->left = load(l);
 		if ((r->flags & (ISTMP|ISCONS)) == 0)
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -26,10 +26,14 @@
 	[ASDIVW]  =  {.fun = binary, .txt = "div", .letter = 'w'},
 	[ASSHLW]  =  {.fun = binary, .txt = "shl", .letter = 'w'},
 	[ASSHRW]  =  {.fun = binary, .txt = "shr", .letter = 'w'},
-	[ASLTW]   =  {.fun = binary, .txt = "cltw", .letter = 'w'},
-	[ASGTW]   =  {.fun = binary, .txt = "cgtw", .letter = 'w'},
-	[ASLEW]   =  {.fun = binary, .txt = "clew", .letter = 'w'},
-	[ASGEW]   =  {.fun = binary, .txt = "cgew", .letter = 'w'},
+	[ASLTW]   =  {.fun = binary, .txt = "csltw", .letter = 'w'},
+	[ASULTW]  =  {.fun = binary, .txt = "cultw", .letter = 'w'},
+	[ASGTW]   =  {.fun = binary, .txt = "csgtw", .letter = 'w'},
+	[ASUGTW]  =  {.fun = binary, .txt = "cugtw", .letter = 'w'},
+	[ASLEW]   =  {.fun = binary, .txt = "cslew", .letter = 'w'},
+	[ASULEW]  =  {.fun = binary, .txt = "culew", .letter = 'w'},
+	[ASGEW]   =  {.fun = binary, .txt = "csgew", .letter = 'w'},
+	[ASUGEW]  =  {.fun = binary, .txt = "cugew", .letter = 'w'},
 	[ASEQW]   =  {.fun = binary, .txt = "ceqw", .letter = 'w'},
 	[ASNEW]   =  {.fun = binary, .txt = "cnew", .letter = 'w'},
 	[ASBANDW] =  {.fun = binary, .txt = "and", .letter = 'w'},
@@ -43,10 +47,14 @@
 	[ASDIVL]  =  {.fun = binary, .txt = "div", .letter = 'l'},
 	[ASSHLL]  =  {.fun = binary, .txt = "shl", .letter = 'l'},
 	[ASSHRL]  =  {.fun = binary, .txt = "shr", .letter = 'l'},
-	[ASLTL]   =  {.fun = binary, .txt = "cltl", .letter = 'w'},
-	[ASGTL]   =  {.fun = binary, .txt = "cgtl", .letter = 'w'},
-	[ASLEL]   =  {.fun = binary, .txt = "clel", .letter = 'w'},
-	[ASGEL]   =  {.fun = binary, .txt = "cgel", .letter = 'w'},
+	[ASLTL]   =  {.fun = binary, .txt = "csltl", .letter = 'w'},
+	[ASULTL]  =  {.fun = binary, .txt = "cultl", .letter = 'w'},
+	[ASGTL]   =  {.fun = binary, .txt = "csgtl", .letter = 'w'},
+	[ASUGTL]  =  {.fun = binary, .txt = "cugtl", .letter = 'w'},
+	[ASLEL]   =  {.fun = binary, .txt = "cslel", .letter = 'w'},
+	[ASULEL]  =  {.fun = binary, .txt = "culel", .letter = 'w'},
+	[ASGEL]   =  {.fun = binary, .txt = "csgel", .letter = 'w'},
+	[ASUGEL]  =  {.fun = binary, .txt = "cugel", .letter = 'w'},
 	[ASEQL]   =  {.fun = binary, .txt = "ceql", .letter = 'w'},
 	[ASNEL]   =  {.fun = binary, .txt = "cnel", .letter = 'w'},
 	[ASBANDL] =  {.fun = binary, .txt = "and", .letter = 'l'},