summaryrefslogtreecommitdiff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-17 19:00:51 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit40d0582ee06232bf8290fafca476a3288488743d (patch)
tree7c3e4545237f662f5a40c2a0f42eb3aea7a94cad /lisc
parent5668e93147563c824e693255de5e58fdc398a36b (diff)
downloadroux-40d0582ee06232bf8290fafca476a3288488743d.tar.gz
add sign/zero extension operations
Diffstat (limited to 'lisc')
-rw-r--r--lisc/emit.c9
-rw-r--r--lisc/isel.c6
-rw-r--r--lisc/lisc.h2
-rw-r--r--lisc/parse.c2
-rw-r--r--lisc/test/collatz.ssa6
5 files changed, 23 insertions, 2 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index 9d59890..e9887ef 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -130,6 +130,8 @@ eins(Ins i, Fn *fn, FILE *f)
[OSub] = "sub",
[OMul] = "imul",
[OAnd] = "and",
+ [OSext] = "movslq",
+ [OZext] = "movzlq",
[OLoad] = "mov",
[OLoadss] = "movsw",
[OLoadus] = "movzw",
@@ -182,6 +184,13 @@ eins(Ins i, Fn *fn, FILE *f)
eop("mov", i.arg[0], i.to, fn, f);
eop(otoa[i.op], i.arg[1], i.to, fn, f);
break;
+ case OSext:
+ case OZext:
+ if (rtype(i.to) != RTmp || i.to.val >= EAX
+ || (rtype(i.arg[0]) == RTmp && i.arg[0].val < EAX))
+ diag("emit: invalid extension");
+ eop(otoa[i.op], i.arg[0], i.to, fn, f);
+ break;
case OCopy:
if (req(i.to, R))
break;
diff --git a/lisc/isel.c b/lisc/isel.c
index ac0159f..5fbe8d9 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -177,6 +177,10 @@ sel(Ins i, Fn *fn)
case OXTestl:
n = 2;
goto Emit;
+ case OSext:
+ case OZext:
+ n = 0;
+ goto Emit;
case OAdd:
case OSub:
case OMul:
@@ -279,6 +283,8 @@ flagi(Ins *i0, Ins *i)
case OAnd:
return i;
case OCopy: /* flag-transparent */
+ case OSext:
+ case OZext:
case OStorel:
case OStorew:
case OStoreb:
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 8159224..a70c7a5 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -127,6 +127,8 @@ enum Op {
ORem,
OMul,
OAnd,
+ OSext,
+ OZext,
OCmp,
OCmp1 = OCmp + NCmp-1,
OStorel,
diff --git a/lisc/parse.c b/lisc/parse.c
index ae9f27b..8ffdb74 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -18,6 +18,8 @@ OpDesc opdesc[NOp] = {
[ORem] = { "rem", 2, 2 },
[OMul] = { "mul", 2, 2 },
[OAnd] = { "and", 2, 2 },
+ [OSext] = { "sext", 1, 1 },
+ [OZext] = { "zext", 1, 1 },
[OStorel] = { "storel", 2, 0 },
[OStorew] = { "storew", 2, 0 },
[OStores] = { "stores", 2, 0 },
diff --git a/lisc/test/collatz.ssa b/lisc/test/collatz.ssa
index 9f1c7b5..419bbaf 100644
--- a/lisc/test/collatz.ssa
+++ b/lisc/test/collatz.ssa
@@ -32,13 +32,15 @@
%n3 =w div %n0, 2
jmp @cloop
@getmemo # get the count for n0 in mem
- %idx0 =l mul %n0, 4
+ %n0l =l sext %n0
+ %idx0 =l mul %n0l, 4
%loc0 =l add %idx0, %mem
%cn0 =w load %loc0
%c2 =w add %c0, %cn0
@endcl # store the count for n in mem
%c =w phi @getmemo %c2, @cloop %c0
- %idx1 =l mul %n, 4
+ %nl =l sext %n
+ %idx1 =l mul %nl, 4
%loc1 =l add %idx1, %mem
storew %c, %loc1
%n9 =w add 1, %n