Commit 4d3cbfde authored by Rémy Oudompheng's avatar Rémy Oudompheng

cmd/8g: introduce temporaries in byte multiplication.

Also restore the smallintconst case for binary ops.

Fixes #3835.

R=daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6999043
parent 3dcc63f7
......@@ -395,7 +395,15 @@ sbop: // symmetric binary
}
abop: // asymmetric binary
if(nl->ullman >= nr->ullman) {
if(smallintconst(nr)) {
mgen(nl, &n1, res);
regalloc(&n2, nl->type, &n1);
gmove(&n1, &n2);
gins(a, nr, &n2);
gmove(&n2, res);
regfree(&n2);
mfree(&n1);
} else if(nl->ullman >= nr->ullman) {
tempname(&nt, nl->type);
cgen(nl, &nt);
mgen(nr, &n2, N);
......
......@@ -748,7 +748,7 @@ cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res)
void
cgen_bmul(int op, Node *nl, Node *nr, Node *res)
{
Node n1, n2, *tmp;
Node n1, n2, nt, *tmp;
Type *t;
int a;
......@@ -764,10 +764,12 @@ cgen_bmul(int op, Node *nl, Node *nr, Node *res)
nr = tmp;
}
tempname(&nt, nl->type);
cgen(nl, &nt);
regalloc(&n1, t, res);
cgen(nl, &n1);
cgen(nr, &n1);
regalloc(&n2, t, N);
cgen(nr, &n2);
gmove(&nt, &n2);
a = optoas(op, t);
gins(a, &n2, &n1);
regfree(&n2);
......
......@@ -333,3 +333,7 @@ func ChainDivConst(a int) int {
17 / 17 / 17 / 17 /
17 / 17 / 17 / 17
}
func ChainMulBytes(a, b, c byte) byte {
return a*(a*(a*(a*(a*(a*(a*(a*(a*b+c)+c)+c)+c)+c)+c)+c)+c) + c
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment