mirror of
https://github.com/golang/go
synced 2024-11-21 20:44:39 -07:00
start of better addressing of
arrays/slices in structures R=rsc CC=golang-dev https://golang.org/cl/190077
This commit is contained in:
parent
4d45dd3268
commit
dfc0ed9559
@ -1709,11 +1709,6 @@ sudoaddable(int as, Node *n, Addr *a)
|
||||
goto odot;
|
||||
|
||||
case OINDEX:
|
||||
cleani += 2;
|
||||
reg = &clean[cleani-1];
|
||||
reg1 = &clean[cleani-2];
|
||||
reg->op = OEMPTY;
|
||||
reg1->op = OEMPTY;
|
||||
goto oindex;
|
||||
}
|
||||
return 0;
|
||||
@ -1782,7 +1777,7 @@ oindex:
|
||||
l = n->left;
|
||||
r = n->right;
|
||||
if(l->ullman >= UINF && r->ullman >= UINF)
|
||||
goto no;
|
||||
return 0;
|
||||
|
||||
// set o to type of array
|
||||
o = 0;
|
||||
@ -1799,7 +1794,7 @@ oindex:
|
||||
|
||||
switch(w) {
|
||||
default:
|
||||
goto no;
|
||||
return 0;
|
||||
case 1:
|
||||
case 2:
|
||||
case 4:
|
||||
@ -1807,6 +1802,15 @@ oindex:
|
||||
break;
|
||||
}
|
||||
|
||||
// if(sudoaddable(as, l, a))
|
||||
// goto oindex_sudo;
|
||||
|
||||
cleani += 2;
|
||||
reg = &clean[cleani-1];
|
||||
reg1 = &clean[cleani-2];
|
||||
reg->op = OEMPTY;
|
||||
reg1->op = OEMPTY;
|
||||
|
||||
// load the array (reg)
|
||||
if(l->ullman > r->ullman) {
|
||||
regalloc(reg, types[tptr], N);
|
||||
@ -1876,12 +1880,21 @@ oindex_const:
|
||||
// can check statically and
|
||||
// can multiply by width statically
|
||||
|
||||
if((o & ODynam) == 0)
|
||||
if(sudoaddable(as, l, a))
|
||||
goto oindex_const_sudo;
|
||||
|
||||
cleani += 2;
|
||||
reg = &clean[cleani-1];
|
||||
reg1 = &clean[cleani-2];
|
||||
reg->op = OEMPTY;
|
||||
reg1->op = OEMPTY;
|
||||
|
||||
regalloc(reg, types[tptr], N);
|
||||
agen(l, reg);
|
||||
|
||||
v = mpgetfix(r->val.u.xval);
|
||||
if(o & ODynam) {
|
||||
|
||||
if(!debug['B'] && !n->etype) {
|
||||
n1 = *reg;
|
||||
n1.op = OINDREG;
|
||||
@ -1918,6 +1931,17 @@ oindex_const:
|
||||
naddr(&n2, a, 1);
|
||||
goto yes;
|
||||
|
||||
oindex_const_sudo:
|
||||
v = mpgetfix(r->val.u.xval);
|
||||
if(v < 0) {
|
||||
yyerror("out of bounds on array");
|
||||
} else
|
||||
if(v >= l->type->bound) {
|
||||
yyerror("out of bounds on array");
|
||||
}
|
||||
a->offset += v*w;
|
||||
goto yes;
|
||||
|
||||
yes:
|
||||
return 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user