Commit 837c204a authored by Russ Cox's avatar Russ Cox

6l, 8l: avoid recursion in asmandsz

The old code said

	if(x) {
		handle a
		return
	}
	aa = *a
	rewrite aa to make x true
	recursivecall(&aa)

The new code says

	params = copy out of a
	if(!x) {
		rewrite params to make x true
	}
	handle params

but it's hard to see that in the Rietveld diffs because
it gets confused by changes in indentation.

Avoiding the recursion makes other changes easier.

R=ken2
CC=golang-dev
https://golang.org/cl/2533041
parent be2c2120
...@@ -531,11 +531,11 @@ oclass(Adr *a) ...@@ -531,11 +531,11 @@ oclass(Adr *a)
} }
void void
asmidx(Adr *a, int base) asmidx(int scale, int index, int base)
{ {
int i; int i;
switch(a->index) { switch(index) {
default: default:
goto bad; goto bad;
...@@ -560,10 +560,10 @@ asmidx(Adr *a, int base) ...@@ -560,10 +560,10 @@ asmidx(Adr *a, int base)
case D_BP: case D_BP:
case D_SI: case D_SI:
case D_DI: case D_DI:
i = reg[(int)a->index] << 3; i = reg[index] << 3;
break; break;
} }
switch(a->scale) { switch(scale) {
default: default:
goto bad; goto bad;
case 1: case 1:
...@@ -609,7 +609,7 @@ bas: ...@@ -609,7 +609,7 @@ bas:
*andptr++ = i; *andptr++ = i;
return; return;
bad: bad:
diag("asmidx: bad address %D", a); diag("asmidx: bad address %d/%d/%d", scale, index, base);
*andptr++ = 0; *andptr++ = 0;
return; return;
} }
...@@ -689,65 +689,78 @@ static void ...@@ -689,65 +689,78 @@ static void
asmandsz(Adr *a, int r, int rex, int m64) asmandsz(Adr *a, int r, int rex, int m64)
{ {
int32 v; int32 v;
int t; int t, scale;
Adr aa;
rex &= (0x40 | Rxr); rex &= (0x40 | Rxr);
v = a->offset; v = a->offset;
t = a->type; t = a->type;
if(a->index != D_NONE) { if(a->index != D_NONE) {
if(t >= D_INDIR) { if(t < D_INDIR) {
switch(t) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
t = D_NONE;
v = vaddr(a);
break;
case D_AUTO:
case D_PARAM:
t = D_SP;
break;
}
} else
t -= D_INDIR; t -= D_INDIR;
rexflag |= (regrex[(int)a->index] & Rxx) | (regrex[t] & Rxb) | rex; rexflag |= (regrex[(int)a->index] & Rxx) | (regrex[t] & Rxb) | rex;
if(t == D_NONE) { if(t == D_NONE) {
*andptr++ = (0 << 6) | (4 << 0) | (r << 3); *andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
put4(v); put4(v);
return; return;
} }
if(v == 0 && t != D_BP && t != D_R13) { if(v == 0 && t != D_BP && t != D_R13) {
*andptr++ = (0 << 6) | (4 << 0) | (r << 3); *andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
return; return;
} }
if(v >= -128 && v < 128) { if(v >= -128 && v < 128) {
*andptr++ = (1 << 6) | (4 << 0) | (r << 3); *andptr++ = (1 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
*andptr++ = v; *andptr++ = v;
return; return;
} }
*andptr++ = (2 << 6) | (4 << 0) | (r << 3); *andptr++ = (2 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
put4(v); put4(v);
return; return;
} }
switch(t) { if(t >= D_AL && t <= D_X0+15) {
if(v)
goto bad;
*andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3);
rexflag |= (regrex[t] & (0x40 | Rxb)) | rex;
return;
}
scale = a->scale;
if(t < D_INDIR) {
switch(a->type) {
default: default:
goto bad; goto bad;
case D_STATIC: case D_STATIC:
case D_EXTERN: case D_EXTERN:
aa.type = D_NONE+D_INDIR; t = D_NONE;
v = vaddr(a);
break; break;
case D_AUTO: case D_AUTO:
case D_PARAM: case D_PARAM:
aa.type = D_SP+D_INDIR; t = D_SP;
break; break;
} }
aa.offset = vaddr(a); scale = 1;
aa.index = a->index; } else
aa.scale = a->scale;
asmandsz(&aa, r, rex, m64);
return;
}
if(t >= D_AL && t <= D_X0+15) {
if(v)
goto bad;
*andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3);
rexflag |= (regrex[t] & (0x40 | Rxb)) | rex;
return;
}
if(t >= D_INDIR) {
t -= D_INDIR; t -= D_INDIR;
rexflag |= (regrex[t] & Rxb) | rex; rexflag |= (regrex[t] & Rxb) | rex;
if(t == D_NONE || (D_CS <= t && t <= D_GS)) { if(t == D_NONE || (D_CS <= t && t <= D_GS)) {
if(asmode != 64){ if(asmode != 64){
...@@ -764,17 +777,17 @@ asmandsz(Adr *a, int r, int rex, int m64) ...@@ -764,17 +777,17 @@ asmandsz(Adr *a, int r, int rex, int m64)
if(t == D_SP || t == D_R12) { if(t == D_SP || t == D_R12) {
if(v == 0) { if(v == 0) {
*andptr++ = (0 << 6) | (reg[t] << 0) | (r << 3); *andptr++ = (0 << 6) | (reg[t] << 0) | (r << 3);
asmidx(a, t); asmidx(scale, D_NONE, t);
return; return;
} }
if(v >= -128 && v < 128) { if(v >= -128 && v < 128) {
*andptr++ = (1 << 6) | (reg[t] << 0) | (r << 3); *andptr++ = (1 << 6) | (reg[t] << 0) | (r << 3);
asmidx(a, t); asmidx(scale, D_NONE, t);
*andptr++ = v; *andptr++ = v;
return; return;
} }
*andptr++ = (2 << 6) | (reg[t] << 0) | (r << 3); *andptr++ = (2 << 6) | (reg[t] << 0) | (r << 3);
asmidx(a, t); asmidx(scale, D_NONE, t);
put4(v); put4(v);
return; return;
} }
...@@ -793,25 +806,7 @@ asmandsz(Adr *a, int r, int rex, int m64) ...@@ -793,25 +806,7 @@ asmandsz(Adr *a, int r, int rex, int m64)
put4(v); put4(v);
return; return;
} }
goto bad;
}
switch(a->type) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
aa.type = D_NONE+D_INDIR;
break;
case D_AUTO:
case D_PARAM:
aa.type = D_SP+D_INDIR;
break;
}
aa.index = D_NONE;
aa.scale = 1;
aa.offset = vaddr(a);
asmandsz(&aa, r, rex, m64);
return;
bad: bad:
diag("asmand: bad address %D", a); diag("asmand: bad address %D", a);
return; return;
......
...@@ -405,11 +405,11 @@ oclass(Adr *a) ...@@ -405,11 +405,11 @@ oclass(Adr *a)
} }
void void
asmidx(Adr *a, int base) asmidx(int scale, int index, int base)
{ {
int i; int i;
switch(a->index) { switch(index) {
default: default:
goto bad; goto bad;
...@@ -424,10 +424,10 @@ asmidx(Adr *a, int base) ...@@ -424,10 +424,10 @@ asmidx(Adr *a, int base)
case D_BP: case D_BP:
case D_SI: case D_SI:
case D_DI: case D_DI:
i = reg[a->index] << 3; i = reg[index] << 3;
break; break;
} }
switch(a->scale) { switch(scale) {
default: default:
goto bad; goto bad;
case 1: case 1:
...@@ -463,7 +463,7 @@ bas: ...@@ -463,7 +463,7 @@ bas:
*andptr++ = i; *andptr++ = i;
return; return;
bad: bad:
diag("asmidx: bad address %D", a); diag("asmidx: bad address %d,%d,%d", scale, index, base);
*andptr++ = 0; *andptr++ = 0;
return; return;
} }
...@@ -530,62 +530,76 @@ void ...@@ -530,62 +530,76 @@ void
asmand(Adr *a, int r) asmand(Adr *a, int r)
{ {
int32 v; int32 v;
int t; int t, scale;
Adr aa;
v = a->offset; v = a->offset;
t = a->type; t = a->type;
if(a->index != D_NONE) { if(a->index != D_NONE) {
if(t >= D_INDIR && t < 2*D_INDIR) { if(t < D_INDIR || t >= 2*D_INDIR) {
switch(t) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
t = D_NONE;
v = vaddr(a);
break;
case D_AUTO:
case D_PARAM:
t = D_SP;
break;
}
} else
t -= D_INDIR; t -= D_INDIR;
if(t == D_NONE) { if(t == D_NONE) {
*andptr++ = (0 << 6) | (4 << 0) | (r << 3); *andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
put4(v); put4(v);
return; return;
} }
if(v == 0 && t != D_BP) { if(v == 0 && t != D_BP) {
*andptr++ = (0 << 6) | (4 << 0) | (r << 3); *andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
return; return;
} }
if(v >= -128 && v < 128) { if(v >= -128 && v < 128) {
*andptr++ = (1 << 6) | (4 << 0) | (r << 3); *andptr++ = (1 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
*andptr++ = v; *andptr++ = v;
return; return;
} }
*andptr++ = (2 << 6) | (4 << 0) | (r << 3); *andptr++ = (2 << 6) | (4 << 0) | (r << 3);
asmidx(a, t); asmidx(a->scale, a->index, t);
put4(v); put4(v);
return; return;
} }
switch(t) { if(t >= D_AL && t <= D_F0+7) {
if(v)
goto bad;
*andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3);
return;
}
scale = a->scale;
if(t < D_INDIR || t >= 2*D_INDIR) {
switch(a->type) {
default: default:
goto bad; goto bad;
case D_STATIC: case D_STATIC:
case D_EXTERN: case D_EXTERN:
aa.type = D_NONE+D_INDIR; t = D_NONE;
v = vaddr(a);
break; break;
case D_AUTO: case D_AUTO:
case D_PARAM: case D_PARAM:
aa.type = D_SP+D_INDIR; t = D_SP;
break; break;
} }
aa.offset = vaddr(a); scale = 1;
aa.index = a->index; } else
aa.scale = a->scale;
asmand(&aa, r);
return;
}
if(t >= D_AL && t <= D_F0+7) {
if(v)
goto bad;
*andptr++ = (3 << 6) | (reg[t] << 0) | (r << 3);
return;
}
if(t >= D_INDIR && t < 2*D_INDIR) {
t -= D_INDIR; t -= D_INDIR;
if(t == D_NONE || (D_CS <= t && t <= D_GS)) { if(t == D_NONE || (D_CS <= t && t <= D_GS)) {
*andptr++ = (0 << 6) | (5 << 0) | (r << 3); *andptr++ = (0 << 6) | (5 << 0) | (r << 3);
put4(v); put4(v);
...@@ -594,17 +608,17 @@ asmand(Adr *a, int r) ...@@ -594,17 +608,17 @@ asmand(Adr *a, int r)
if(t == D_SP) { if(t == D_SP) {
if(v == 0) { if(v == 0) {
*andptr++ = (0 << 6) | (4 << 0) | (r << 3); *andptr++ = (0 << 6) | (4 << 0) | (r << 3);
asmidx(a, D_SP); asmidx(scale, D_NONE, t);
return; return;
} }
if(v >= -128 && v < 128) { if(v >= -128 && v < 128) {
*andptr++ = (1 << 6) | (4 << 0) | (r << 3); *andptr++ = (1 << 6) | (4 << 0) | (r << 3);
asmidx(a, D_SP); asmidx(scale, D_NONE, t);
*andptr++ = v; *andptr++ = v;
return; return;
} }
*andptr++ = (2 << 6) | (4 << 0) | (r << 3); *andptr++ = (2 << 6) | (4 << 0) | (r << 3);
asmidx(a, D_SP); asmidx(scale, D_NONE, t);
put4(v); put4(v);
return; return;
} }
...@@ -623,25 +637,7 @@ asmand(Adr *a, int r) ...@@ -623,25 +637,7 @@ asmand(Adr *a, int r)
put4(v); put4(v);
return; return;
} }
goto bad;
}
switch(a->type) {
default:
goto bad;
case D_STATIC:
case D_EXTERN:
aa.type = D_NONE+D_INDIR;
break;
case D_AUTO:
case D_PARAM:
aa.type = D_SP+D_INDIR;
break;
}
aa.index = D_NONE;
aa.scale = 1;
aa.offset = vaddr(a);
asmand(&aa, r);
return;
bad: bad:
diag("asmand: bad address %D", a); diag("asmand: bad address %D", a);
return; return;
......
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