summaryrefslogtreecommitdiff
path: root/lisc
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-08-16 14:19:54 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:31 -0400
commit7bbd361083db3f08e173bbf384e7369ab5ffee57 (patch)
treeac03cab8b793006864c97dff7b0fbe91c0129f98 /lisc
parent27f4eae43eebb4990bad59c8becdca41d2fb865d (diff)
downloadroux-7bbd361083db3f08e173bbf384e7369ab5ffee57.tar.gz
add the mul instruction
Diffstat (limited to 'lisc')
-rw-r--r--lisc/emit.c17
-rw-r--r--lisc/isel.c1
-rw-r--r--lisc/lisc.h1
-rw-r--r--lisc/parse.c1
-rw-r--r--lisc/test/collatz.ssa15
5 files changed, 26 insertions, 9 deletions
diff --git a/lisc/emit.c b/lisc/emit.c
index 22e9073..2f96c3c 100644
--- a/lisc/emit.c
+++ b/lisc/emit.c
@@ -137,6 +137,7 @@ eins(Ins i, Fn *fn, FILE *f)
static char *otoa[NOp] = {
[OAdd] = "add",
[OSub] = "sub",
+ [OMul] = "imul",
[OAnd] = "and",
[OLoad] = "mov",
[OLoadss] = "movsw",
@@ -154,10 +155,26 @@ eins(Ins i, Fn *fn, FILE *f)
[OStores - OStorel] = "w",
[OStoreb - OStorel] = "b",
};
+ Ref r0, r1;
int reg;
int64_t val;
switch (i.op) {
+ case OMul:
+ if (rtype(i.arg[1]) == RCon) {
+ r0 = i.arg[1];
+ r1 = i.arg[0];
+ } else {
+ r0 = i.arg[0];
+ r1 = i.arg[1];
+ }
+ if (rtype(r0) == RCon && rtype(r1) == RTmp) {
+ val = fn->con[r0.val].val;
+ fprintf(f, "\timul $%"PRId64", %%%s, %%%s\n",
+ val, rtoa(r1.val), rtoa(i.to.val));
+ break;
+ }
+ /* fall through */
case OAdd:
case OSub:
case OAnd:
diff --git a/lisc/isel.c b/lisc/isel.c
index c36773c..ac0159f 100644
--- a/lisc/isel.c
+++ b/lisc/isel.c
@@ -179,6 +179,7 @@ sel(Ins i, Fn *fn)
goto Emit;
case OAdd:
case OSub:
+ case OMul:
case OAnd:
case OCopy:
if (fn->tmp[i.to.val].type == TLong)
diff --git a/lisc/lisc.h b/lisc/lisc.h
index 6e9ce6c..8159224 100644
--- a/lisc/lisc.h
+++ b/lisc/lisc.h
@@ -125,6 +125,7 @@ enum Op {
OSub,
ODiv,
ORem,
+ OMul,
OAnd,
OCmp,
OCmp1 = OCmp + NCmp-1,
diff --git a/lisc/parse.c b/lisc/parse.c
index 07e1ad9..ae9f27b 100644
--- a/lisc/parse.c
+++ b/lisc/parse.c
@@ -16,6 +16,7 @@ OpDesc opdesc[NOp] = {
[OSub] = { "sub", 2, 2 },
[ODiv] = { "div", 2, 2 },
[ORem] = { "rem", 2, 2 },
+ [OMul] = { "mul", 2, 2 },
[OAnd] = { "and", 2, 2 },
[OStorel] = { "storel", 2, 0 },
[OStorew] = { "storew", 2, 0 },
diff --git a/lisc/test/collatz.ssa b/lisc/test/collatz.ssa
index 9696194..8918c76 100644
--- a/lisc/test/collatz.ssa
+++ b/lisc/test/collatz.ssa
@@ -32,8 +32,7 @@
jnz %p, @odd, @even
@odd
- %nn =w add %n0, %n0 # compute %n2 = 3 * %n0 + 1
- %n1 =w add %n0, %nn
+ %n1 =w mul 3, %n0 # compute %n2 = 3 * %n0 + 1
%n2 =w add %n1, 1
jmp @cloop
@@ -42,17 +41,15 @@
jmp @cloop
@getmemo
- %idx00 =l add %n0, %n0
- %idx0 =l add %idx00, %idx00
- %loc0 =l add %idx0, %mem
- %cn0 =w load %loc0
- %c2 =w add %c0, %cn0
+ %idx0 =l mul %n0, 4
+ %loc0 =l add %idx0, %mem
+ %cn0 =w load %loc0
+ %c2 =w add %c0, %cn0
@endcl
%c =w phi @getmemo %c2, @cloop %c0
- %idx10 =l add %n, %n
- %idx1 =l add %idx10, %idx10
+ %idx1 =l mul %n, 4
%loc1 =l add %idx1, %mem
storew %c, %loc1 # memorize the result
%n9 =w add 1, %n