summaryrefslogtreecommitdiff
path: root/sys/src/cmd/6c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-06-09 23:12:46 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-06-09 23:12:46 +0200
commita00b6bdbfa72a1688a866edf5f825720c9874ada (patch)
tree82b2e1a62cc75c007039fe07663300706947f381 /sys/src/cmd/6c
parent5cdabc5eb16db432abcf61dc126bfb7f9b2978c1 (diff)
8c, 6c: native ROL (cyclic shift) instruction support, improve peephole optimizers
introduce rolor() function to subsitute (a << c) | (a >> (bits(a) - c)) with (a <<< c) where <<< is cyclic rotation and c is constant. this almost doubles the speed of chacha encryption of 386 and amd64. the peephole optimizer used to stop when it hit a shift or rol instruction when attempting to eleminate moves by register substitution. but we do not have to as long as the shift count operand is not CX (which cannot be substituted) and CX is not a subject for substitution.
Diffstat (limited to 'sys/src/cmd/6c')
-rw-r--r--sys/src/cmd/6c/cgen.c1
-rw-r--r--sys/src/cmd/6c/peep.c28
-rw-r--r--sys/src/cmd/6c/sgen.c11
-rw-r--r--sys/src/cmd/6c/txt.c10
4 files changed, 36 insertions, 14 deletions
diff --git a/sys/src/cmd/6c/cgen.c b/sys/src/cmd/6c/cgen.c
index 2cfbfbe66..d43d1d366 100644
--- a/sys/src/cmd/6c/cgen.c
+++ b/sys/src/cmd/6c/cgen.c
@@ -159,6 +159,7 @@ cgen(Node *n, Node *nn)
regfree(&nod);
break;
+ case OROL:
case OLSHR:
case OASHL:
case OASHR:
diff --git a/sys/src/cmd/6c/peep.c b/sys/src/cmd/6c/peep.c
index 7096ce958..9c2b3c429 100644
--- a/sys/src/cmd/6c/peep.c
+++ b/sys/src/cmd/6c/peep.c
@@ -370,15 +370,11 @@ subprop(Reg *r0)
break;
p = r->prog;
switch(p->as) {
- case ACALL:
- return 0;
-
case AIMULL:
case AIMULQ:
case AIMULW:
if(p->to.type != D_NONE)
break;
-
case ADIVB:
case ADIVL:
case ADIVQ:
@@ -393,6 +389,19 @@ subprop(Reg *r0)
case AMULQ:
case AMULW:
+ case ACWD:
+ case ACDQ:
+ case ACQO:
+
+ case AREP:
+ case AREPN:
+ case ALOOP:
+ case ALOOPEQ:
+ case ALOOPNE:
+
+ case ACALL:
+ return 0;
+
case AROLB:
case AROLL:
case AROLQ:
@@ -417,14 +426,9 @@ subprop(Reg *r0)
case ASHRL:
case ASHRQ:
case ASHRW:
-
- case AREP:
- case AREPN:
-
- case ACWD:
- case ACDQ:
- case ACQO:
- return 0;
+ if(p->from.type == D_CX && v1->type == D_CX)
+ return 0;
+ break;
case AORL:
case AORQ:
diff --git a/sys/src/cmd/6c/sgen.c b/sys/src/cmd/6c/sgen.c
index a7d751c0f..14e5f3c7e 100644
--- a/sys/src/cmd/6c/sgen.c
+++ b/sys/src/cmd/6c/sgen.c
@@ -120,7 +120,6 @@ xcom(Node *n)
*l = *(n->left);
l->xoffset += r->vconst;
n->left = l;
- r = n->right;
goto brk;
}
break;
@@ -212,7 +211,6 @@ xcom(Node *n)
if(g >= 0) {
n->left = r;
n->right = l;
- l = r;
r = n->right;
}
g = vlog(r);
@@ -288,6 +286,12 @@ xcom(Node *n)
indexshift(n);
break;
+ case OOR:
+ xcom(l);
+ xcom(r);
+ rolor(n);
+ break;
+
default:
if(l != Z)
xcom(l);
@@ -298,6 +302,8 @@ xcom(Node *n)
brk:
if(n->addable >= 10)
return;
+ l = n->left;
+ r = n->right;
if(l != Z)
n->complex = l->complex;
if(r != Z) {
@@ -344,6 +350,7 @@ brk:
}
break;
+ case OROL:
case OLSHR:
case OASHL:
case OASHR:
diff --git a/sys/src/cmd/6c/txt.c b/sys/src/cmd/6c/txt.c
index 5239b5633..861cdfde4 100644
--- a/sys/src/cmd/6c/txt.c
+++ b/sys/src/cmd/6c/txt.c
@@ -1305,6 +1305,16 @@ gopcode(int o, Type *ty, Node *f, Node *t)
a = ASALQ;
break;
+ case OROL:
+ a = AROLL;
+ if(et == TCHAR || et == TUCHAR)
+ a = AROLB;
+ if(et == TSHORT || et == TUSHORT)
+ a = AROLW;
+ if(et == TVLONG || et == TUVLONG || et == TIND)
+ a = AROLQ;
+ break;
+
case OFUNC:
a = ACALL;
break;