summary refs log tree commit diff
path: root/lisc
diff options
context:
space:
mode:
Diffstat (limited to 'lisc')
-rw-r--r--lisc/emit.c2
-rw-r--r--lisc/isel.c8
-rw-r--r--lisc/lisc.h4
-rw-r--r--lisc/parse.c11
-rw-r--r--lisc/test/cup.ssa4
5 files changed, 22 insertions, 7 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index 1025ace..1867097 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -68,6 +68,8 @@ static char *rbtoa[] = {
 static char *ctoa[NCmp] = {
 	[Ceq] = "e",
 	[Csle] = "le",
+	[Csgt] = "g",
+	[Cne] = "ne",
 };
 
 static void
diff --git a/lisc/isel.c b/lisc/isel.c
index 6fdf5ff..faea3b5 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -87,8 +87,14 @@ sel(Ins i, Fn *fn)
 	default:
 		if (OCmp <= i.op && i.op <= OCmp1) {
 			c = i.op - OCmp;
+			if (rtype(i.arg[0]) == RCon) {
+				r0 = i.arg[0];
+				i.arg[0] = i.arg[1];
+				i.arg[1] = r0;
+				c = CNEG(c);
+			}
 			emit(OXSet+c, i.to, R, R);
-			emit(OXCmp, R, i.arg[0], i.arg[1]);
+			emit(OXCmp, R, i.arg[1], i.arg[0]);
 			break;
 		}
 		diag("isel: non-exhaustive implementation");
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 1291fea..4e150db 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -108,9 +108,13 @@ static inline int rtype(Ref r)
 enum {
 	Ceq,
 	Csle,
+	Csgt, /* mirror opposite cmps! */
+	Cne,
 	NCmp,
 };
 
+#define CNEG(c) (NCmp-1 - c)
+
 enum {
 	OXXX,
 	/* public instruction */
diff --git a/lisc/parse.c b/lisc/parse.c
index d504113..ae7cb8c 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -25,10 +25,13 @@ OpDesc opdesc[OLast] = {
 	[OXDiv]   = { "xdiv",  1, U },
 	[OXCmp]   = { "xcmp",  2, U },
 
-	[OCmp+Ceq]   = { "ceq",    2, U },
-	[OCmp+Csle]  = { "csle",   2, U },
-	[OXSet+Ceq]  = { "xsete",  0, U },
-	[OXSet+Csle] = { "xsetle", 0, U },
+	#define I(X) X(eq), X(sle), X(sgt), X(ne)
+	#define CMP(c) [OCmp+C##c]  = { "c"    #c, 2, U }
+	#define SET(c) [OXSet+C##c] = { "xset" #c, 0, U }
+	I(CMP), I(SET)
+	#undef CMP
+	#undef SET
+	#undef I
 };
 
 typedef enum {
diff --git a/lisc/test/cup.ssa b/lisc/test/cup.ssa
index 64f2ab4..2626d26 100644
--- a/lisc/test/cup.ssa
+++ b/lisc/test/cup.ssa
@@ -4,7 +4,7 @@
 @loop
 	%n0  =w phi @start -1988, @loop %n1
 	%n1  =w add 1, %n0
-	%cmp =w csle %n1, 1000
-	jez %cmp, @end, @loop
+	%cmp =w csle 1990, %n1
+	jez %cmp, @loop, @end
 @end
 	ret