1
0
mirror of https://github.com/golang/go synced 2024-11-26 15:56:57 -07:00

code improvement

better calling of morestack

R=r
OCL=28179
CL=28179
This commit is contained in:
Ken Thompson 2009-05-01 18:07:33 -07:00
parent 4f18549c02
commit 1ed7f18165
2 changed files with 109 additions and 35 deletions

View File

@ -483,24 +483,34 @@ dostkoff(void)
Prog *p, *q, *q1; Prog *p, *q, *q1;
int32 autoffset, deltasp; int32 autoffset, deltasp;
int a, f, curframe, curbecome, maxbecome, pcsize; int a, f, curframe, curbecome, maxbecome, pcsize;
Prog *pmorestack; Prog *pmorestack00, *pmorestack01, *pmorestack10, *pmorestack11;
Sym *symmorestack; Sym *symmorestack00, *symmorestack01, *symmorestack10, *symmorestack11;
uint32 moreconst1, moreconst2;
pmorestack = P; pmorestack00 = P;
symmorestack = lookup("sys·morestack", 0); pmorestack01 = P;
pmorestack10 = P;
pmorestack11 = P;
symmorestack00 = lookup("sys·morestack00", 0);
symmorestack01 = lookup("sys·morestack01", 0);
symmorestack10 = lookup("sys·morestack10", 0);
symmorestack11 = lookup("sys·morestack11", 0);
if(symmorestack->type == STEXT)
for(p = firstp; p != P; p = p->link) { for(p = firstp; p != P; p = p->link) {
if(p->as == ATEXT) { if(p->as == ATEXT) {
if(p->from.sym == symmorestack) { if(p->from.sym == symmorestack00)
pmorestack = p; pmorestack00 = p;
p->from.scale |= NOSPLIT; if(p->from.sym == symmorestack01)
break; pmorestack01 = p;
} if(p->from.sym == symmorestack10)
pmorestack10 = p;
if(p->from.sym == symmorestack11)
pmorestack11 = p;
} }
} }
if(pmorestack == P) if(pmorestack00 == P || pmorestack01 == P || pmorestack10 == P || pmorestack11 == P)
diag("sys·morestack not defined"); diag("sys·morestack[01][01] not defined");
curframe = 0; curframe = 0;
curbecome = 0; curbecome = 0;
@ -583,14 +593,14 @@ dostkoff(void)
q = P; q = P;
q1 = P; q1 = P;
if(pmorestack != P)
if(!(p->from.scale & NOSPLIT)) { if(!(p->from.scale & NOSPLIT)) {
if(debug['K']) { if(debug['K']) {
// 6l -K means check not only for stack // 6l -K means check not only for stack
// overflow but stack underflow. // overflow but stack underflow.
// On underflow, INT 3 (breakpoint). // On underflow, INT 3 (breakpoint).
// Underflow itself is rare but this also // Underflow itself is rare but this also
// catches out-of-sync stack guard info. // catches out-of-sync stack guard info
p = appendp(p); p = appendp(p);
p->as = ACMPQ; p->as = ACMPQ;
p->from.type = D_INDIR+D_R15; p->from.type = D_INDIR+D_R15;
@ -646,33 +656,73 @@ dostkoff(void)
q = p; q = p;
} }
p = appendp(p);
p->as = AMOVQ;
p->from.type = D_CONST;
p->from.offset = 0;
p->to.type = D_AX;
if(q1) {
q1->pcond = p;
q1 = P;
}
/* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */ /* 160 comes from 3 calls (3*8) 4 safes (4*8) and 104 guard */
moreconst1 = 0;
if(autoffset+160 > 4096) if(autoffset+160 > 4096)
p->from.offset = (autoffset+160) & ~7LL; moreconst1 = (autoffset+160) & ~7LL;
p->from.offset |= textarg<<32; moreconst2 = textarg;
// four varieties (const1==0 cross const2==0)
p = appendp(p); p = appendp(p);
p->as = AMOVQ; if(moreconst1 == 0 && moreconst2 == 0) {
p->from.type = D_AX; p->as = ACALL;
p->to.type = D_INDIR+D_R14; p->to.type = D_BRANCH;
p->to.offset = 8; p->pcond = pmorestack00;
p->to.sym = symmorestack00;
if(q1) {
q1->pcond = p;
q1 = P;
}
} else
if(moreconst1 != 0 && moreconst2 == 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst1;
p->to.type = D_AX;
if(q1) {
q1->pcond = p;
q1 = P;
}
p = appendp(p); p = appendp(p);
p->as = ACALL; p->as = ACALL;
p->to.type = D_BRANCH; p->to.type = D_BRANCH;
p->pcond = pmorestack; p->pcond = pmorestack10;
p->to.sym = symmorestack; p->to.sym = symmorestack10;
} else
if(moreconst1 == 0 && moreconst2 != 0) {
p->as = AMOVL;
p->from.type = D_CONST;
p->from.offset = moreconst2;
p->to.type = D_AX;
if(q1) {
q1->pcond = p;
q1 = P;
}
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack01;
p->to.sym = symmorestack01;
} else {
p->as = AMOVQ;
p->from.type = D_CONST;
p->from.offset = (uint64)moreconst2 << 32;
p->from.offset |= moreconst1;
p->to.type = D_AX;
if(q1) {
q1->pcond = p;
q1 = P;
}
p = appendp(p);
p->as = ACALL;
p->to.type = D_BRANCH;
p->pcond = pmorestack11;
p->to.sym = symmorestack11;
}
} }
if(q != P) if(q != P)

View File

@ -87,6 +87,30 @@ TEXT gosave(SB), 7, $0
* support for morestack * support for morestack
*/ */
// morestack trampolines
TEXT sys·morestack00+0(SB),7,$0
MOVQ $0, AX
MOVQ AX, 8(R14)
MOVQ $sys·morestack+0(SB), AX
JMP AX
TEXT sys·morestack01+0(SB),7,$0
SHLQ $32, AX
MOVQ AX, 8(R14)
MOVQ $sys·morestack+0(SB), AX
JMP AX
TEXT sys·morestack10+0(SB),7,$0
MOVLQZX AX, AX
MOVQ AX, 8(R14)
MOVQ $sys·morestack+0(SB), AX
JMP AX
TEXT sys·morestack11+0(SB),7,$0
MOVQ AX, 8(R14)
MOVQ $sys·morestack+0(SB), AX
JMP AX
// return point when leaving new stack. save AX, jmp to lessstack to switch back // return point when leaving new stack. save AX, jmp to lessstack to switch back
TEXT retfromnewstack(SB), 7, $0 TEXT retfromnewstack(SB), 7, $0
MOVQ AX, 16(R14) // save AX in m->cret MOVQ AX, 16(R14) // save AX in m->cret