Commit 42d89ac0 authored by Ken Thompson's avatar Ken Thompson

even more code improvement

R=r
OCL=21160
CL=21160
parent 23fc0ac0
...@@ -915,55 +915,96 @@ cgen_asop(Node *n) ...@@ -915,55 +915,96 @@ cgen_asop(Node *n)
{ {
Node n1, n2, n3, n4; Node n1, n2, n3, n4;
Node *nl, *nr; Node *nl, *nr;
Prog *p1;
Addr addr;
nl = n->left; nl = n->left;
nr = n->right; nr = n->right;
if(nl->addable && nr->op == OLITERAL) if(nr->ullman >= UINF && nl->ullman >= UINF) {
tempname(&n1, nr->type);
cgen(nr, &n1);
n2 = *n;
n2.right = &n1;
cgen_asop(&n2);
goto ret;
}
if(!isint[nl->type->etype])
goto hard;
if(!isint[nr->type->etype])
goto hard;
switch(n->etype) { switch(n->etype) {
case OADD: case OADD:
if(!isint[nl->type->etype]) if(smallintconst(nr))
break; if(mpgetfix(nr->val.u.xval) == 1) {
if(mpgetfix(nr->val.u.xval) != 1) if(nl->addable) {
break; gins(optoas(OINC, nl->type), N, nl);
gins(optoas(OINC, nl->type), N, nl); goto ret;
goto ret; }
if(sudoaddable(nl, nr->type, &addr)) {
p1 = gins(optoas(OINC, nl->type), N, N);
p1->to = addr;
sudoclean();
goto ret;
}
}
break;
case OSUB: case OSUB:
if(!isint[nl->type->etype]) if(smallintconst(nr))
break; if(mpgetfix(nr->val.u.xval) == 1) {
if(mpgetfix(nr->val.u.xval) != 1) if(nl->addable) {
break; gins(optoas(ODEC, nl->type), N, nl);
gins(optoas(ODEC, nl->type), N, nl); goto ret;
goto ret; }
if(sudoaddable(nl, nr->type, &addr)) {
p1 = gins(optoas(ODEC, nl->type), N, N);
p1->to = addr;
sudoclean();
goto ret;
}
}
break;
} }
if(nl->addable)
switch(n->etype) { switch(n->etype) {
case OADD:
case OSUB:
case OXOR: case OXOR:
case OAND: case OAND:
case OOR: case OOR:
case OADD: if(nl->addable) {
case OSUB: if(smallintconst(nr)) {
if(!isint[nl->type->etype]) gins(optoas(n->etype, nl->type), nr, nl);
break; goto ret;
if(!isint[nr->type->etype]) }
break; regalloc(&n2, nr->type, N);
regalloc(&n2, nr->type, N); cgen(nr, &n2);
cgen(nr, &n2); gins(optoas(n->etype, nl->type), &n2, nl);
gins(optoas(n->etype, nl->type), &n2, nl); regfree(&n2);
regfree(&n2); goto ret;
goto ret; }
} if(nr->ullman < UINF)
if(sudoaddable(nl, nr->type, &addr)) {
if(nr->ullman >= UINF && nl->ullman >= UINF) { if(smallintconst(nr)) {
tempname(&n1, nr->type); p1 = gins(optoas(n->etype, nl->type), nr, N);
cgen(nr, &n1); p1->to = addr;
n2 = *n; sudoclean();
n2.right = &n1; goto ret;
cgen_asop(&n2); }
goto ret; regalloc(&n2, nr->type, N);
cgen(nr, &n2);
p1 = gins(optoas(n->etype, nl->type), &n2, N);
p1->to = addr;
regfree(&n2);
sudoclean();
goto ret;
}
} }
hard:
if(nr->ullman > nl->ullman) { if(nr->ullman > nl->ullman) {
regalloc(&n2, nr->type, N); regalloc(&n2, nr->type, N);
cgen(nr, &n2); cgen(nr, &n2);
......
...@@ -199,7 +199,6 @@ void tempname(Node*, Type*); ...@@ -199,7 +199,6 @@ void tempname(Node*, Type*);
Plist* newplist(void); Plist* newplist(void);
int isfat(Type*); int isfat(Type*);
void setmaxarg(Type*); void setmaxarg(Type*);
int smallintconst(Node*);
void sudoclean(void); void sudoclean(void);
int sudoaddable(Node*, Type*, Addr*); int sudoaddable(Node*, Type*, Addr*);
......
...@@ -102,6 +102,19 @@ newplist(void) ...@@ -102,6 +102,19 @@ newplist(void)
return pl; return pl;
} }
static int resvd[] =
{
// D_DI, // for movstring
// D_SI, // for movstring
D_AX, // for divide
D_CX, // for shift
D_DX, // for divide
D_SP, // for stack
D_R14, // reserved for m
D_R15, // reserved for u
};
void void
ginit(void) ginit(void)
{ {
...@@ -114,15 +127,8 @@ ginit(void) ...@@ -114,15 +127,8 @@ ginit(void)
for(i=D_X0; i<=D_X7; i++) for(i=D_X0; i<=D_X7; i++)
reg[i] = 0; reg[i] = 0;
// reg[D_DI]++; // for movstring for(i=0; i<nelem(resvd); i++)
// reg[D_SI]++; // for movstring reg[resvd[i]]++;
reg[D_AX]++; // for divide
reg[D_CX]++; // for shift
reg[D_DX]++; // for divide
reg[D_SP]++; // for stack
reg[D_R14]++; // reserved for m
reg[D_R15]++; // reserved for u
} }
void void
...@@ -130,15 +136,8 @@ gclean(void) ...@@ -130,15 +136,8 @@ gclean(void)
{ {
int i; int i;
// reg[D_DI]--; // for movstring for(i=0; i<nelem(resvd); i++)
// reg[D_SI]--; // for movstring reg[resvd[i]]--;
reg[D_AX]--; // for divide
reg[D_CX]--; // for shift
reg[D_DX]--; // for divide
reg[D_SP]--; // for stack
reg[D_R14]--; // reserved for m
reg[D_R15]--; // reserved for u
for(i=D_AX; i<=D_R15; i++) for(i=D_AX; i<=D_R15; i++)
if(reg[i]) if(reg[i])
...@@ -1817,24 +1816,6 @@ dotoffset(Node *n, int *oary, Node **nn) ...@@ -1817,24 +1816,6 @@ dotoffset(Node *n, int *oary, Node **nn)
return i; return i;
} }
int
smallintconst(Node *n)
{
if(n->op == OLITERAL)
switch(simtype[n->type->etype]) {
case TINT8:
case TUINT8:
case TINT16:
case TUINT16:
case TINT32:
case TUINT32:
case TBOOL:
case TPTR32:
return 1;
}
return 0;
}
enum enum
{ {
ODynam = 1<<0, ODynam = 1<<0,
...@@ -1857,37 +1838,36 @@ sudoclean(void) ...@@ -1857,37 +1838,36 @@ sudoclean(void)
int int
sudoaddable(Node *n, Type *t, Addr *a) sudoaddable(Node *n, Type *t, Addr *a)
{ {
int et, o, i, w; int o, i, w;
int oary[10]; int oary[10];
vlong v; vlong v;
Node n0, n1, n2, *nn, *l, *r; Node n1, n2, *nn, *l, *r;
Node *reg, *reg1; Node *reg, *reg1;
Prog *p1; Prog *p1;
// make a cleanup slot
cleani += 2;
reg = &clean[cleani-1];
reg1 = &clean[cleani-2];
reg->op = OEMPTY;
reg1->op = OEMPTY;
if(n->type == T || t == T) if(n->type == T || t == T)
goto no; return 0;
et = simtype[n->type->etype];
if(et != simtype[t->etype])
goto no;
switch(n->op) { switch(n->op) {
default: default:
goto no; return 0;
case ODOT: case ODOT:
case ODOTPTR: case ODOTPTR:
cleani += 2;
reg = &clean[cleani-1];
reg1 = &clean[cleani-2];
reg->op = OEMPTY;
reg1->op = OEMPTY;
goto odot; goto odot;
case OINDEXPTR: case OINDEXPTR:
goto no;
case OINDEX: case OINDEX:
cleani += 2;
reg = &clean[cleani-1];
reg1 = &clean[cleani-2];
reg->op = OEMPTY;
reg1->op = OEMPTY;
goto oindex; goto oindex;
} }
...@@ -1895,15 +1875,6 @@ odot: ...@@ -1895,15 +1875,6 @@ odot:
o = dotoffset(n, oary, &nn); o = dotoffset(n, oary, &nn);
if(nn == N) if(nn == N)
goto no; goto no;
if(0) {
dump("\nXX", n);
dump("YY", nn);
for(i=0; i<o; i++)
print(" %d", oary[i]);
print("\n");
goto no;
}
regalloc(reg, types[tptr], N); regalloc(reg, types[tptr], N);
n1 = *reg; n1 = *reg;
...@@ -1931,7 +1902,7 @@ odot: ...@@ -1931,7 +1902,7 @@ odot:
oindex: oindex:
l = n->left; l = n->left;
r = n->right; r = n->right;
if(l->ullman >= UINF || r->ullman >= UINF) if(l->ullman >= UINF && r->ullman >= UINF)
goto no; goto no;
// set o to type of array // set o to type of array
...@@ -1950,8 +1921,6 @@ oindex: ...@@ -1950,8 +1921,6 @@ oindex:
} }
w = n->type->width; w = n->type->width;
if(w == 0)
fatal("index is zero width");
if(whatis(r) == Wlitint) if(whatis(r) == Wlitint)
goto oindex_const; goto oindex_const;
......
...@@ -540,3 +540,21 @@ cmpslit(Node *l, Node *r) ...@@ -540,3 +540,21 @@ cmpslit(Node *l, Node *r)
return +1; return +1;
return -1; return -1;
} }
int
smallintconst(Node *n)
{
if(n->op == OLITERAL)
switch(simtype[n->type->etype]) {
case TINT8:
case TUINT8:
case TINT16:
case TUINT16:
case TINT32:
case TUINT32:
case TBOOL:
case TPTR32:
return 1;
}
return 0;
}
...@@ -826,6 +826,7 @@ void convlit1(Node*, Type*, int); ...@@ -826,6 +826,7 @@ void convlit1(Node*, Type*, int);
void convlit(Node*, Type*); void convlit(Node*, Type*);
void evconst(Node*); void evconst(Node*);
int cmpslit(Node *l, Node *r); int cmpslit(Node *l, Node *r);
int smallintconst(Node*);
/* /*
* gen.c/gsubr.c/obj.c * gen.c/gsubr.c/obj.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