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
This commit is contained in:
Rémy Oudompheng 2012-12-21 23:46:16 +01:00
parent 3dcc63f750
commit 4d3cbfdefa
3 changed files with 18 additions and 4 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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
}