shithub: scc

Download patch

ref: a4ef620605bf4c351c245fb921d898793e0a2470
parent: ff6393ec18d14fbbbe747c7543f664bb97c0ca46
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 20 21:41:43 EDT 2016

[cc2-qbe] Added signed/unsigned versions of div and rem

These two operators have different opcodes in qbe depending of the
signess of the types involved in the operation. It is a similar
situation to the comparisions.

--- a/cc2/arch/qbe/arch.h
+++ b/cc2/arch/qbe/arch.h
@@ -12,7 +12,9 @@
 	ASSUBW,
 	ASMULW,
 	ASMODW,
+	ASUMODW,
 	ASDIVW,
+	ASUDIVW,
 	ASSHLW,
 	ASSHRW,
 	ASLTW,
@@ -34,7 +36,9 @@
 	ASSUBL,
 	ASMULL,
 	ASMODL,
+	ASUMODL,
 	ASDIVL,
+	ASUDIVL,
 	ASSHLL,
 	ASSHRL,
 	ASLTL,
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
@@ -142,6 +142,8 @@
 	case OMEM:
 	case OAUTO:
 		return np;
+	case OMOD:
+	case ODIV:
 	case OLT:
 	case OGT:
 	case OLE:
@@ -155,8 +157,6 @@
 	case OADD:
 	case OSUB:
 	case OMUL:
-	case OMOD:
-	case ODIV:
 	case OSHL:
 	case OSHR:
 	case OBAND:
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -23,7 +23,9 @@
 	[ASSUBW]  =  {.fun = binary, .txt = "sub", .letter = 'w'},
 	[ASMULW]  =  {.fun = binary, .txt = "mul", .letter = 'w'},
 	[ASMODW]  =  {.fun = binary, .txt = "rem", .letter = 'w'},
+	[ASUMODW] =  {.fun = binary, .txt = "urem", .letter = 'w'},
 	[ASDIVW]  =  {.fun = binary, .txt = "div", .letter = 'w'},
+	[ASUDIVW] =  {.fun = binary, .txt = "udiv", .letter = 'w'},
 	[ASSHLW]  =  {.fun = binary, .txt = "shl", .letter = 'w'},
 	[ASSHRW]  =  {.fun = binary, .txt = "shr", .letter = 'w'},
 	[ASLTW]   =  {.fun = binary, .txt = "csltw", .letter = 'w'},
@@ -44,7 +46,9 @@
 	[ASSUBL]  =  {.fun = binary, .txt = "sub", .letter = 'l'},
 	[ASMULL]  =  {.fun = binary, .txt = "mul", .letter = 'l'},
 	[ASMODL]  =  {.fun = binary, .txt = "rem", .letter = 'l'},
+	[ASUMODL] =  {.fun = binary, .txt = "urem", .letter = 'l'},
 	[ASDIVL]  =  {.fun = binary, .txt = "div", .letter = 'l'},
+	[ASUDIVL] =  {.fun = binary, .txt = "udiv", .letter = 'l'},
 	[ASSHLL]  =  {.fun = binary, .txt = "shl", .letter = 'l'},
 	[ASSHRL]  =  {.fun = binary, .txt = "shr", .letter = 'l'},
 	[ASLTL]   =  {.fun = binary, .txt = "csltl", .letter = 'w'},