Skip to content

Commit

Permalink
cmd/6g, cmd/8g: disable Duff's device on NaCl.
Browse files Browse the repository at this point in the history
Native Client forbids jumps/calls to arbitrary locations and
enforces a particular alignement, which makes the Duff's device
ineffective.

LGTM=khr
R=rsc, dave, khr
CC=golang-codereviews
https://golang.org/cl/84400043
  • Loading branch information
remyoudompheng committed Apr 4, 2014
1 parent e25d73d commit c6a41a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cmd/6g/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ sgen(Node *n, Node *ns, int64 w)
gins(ACLD, N, N);
} else {
// normal direction
if(q > 128) {
if(q > 128 || (nacl && q >= 4)) {
gconreg(movptr, q, D_CX);
gins(AREP, N, N); // repeat
gins(AMOVSQ, N, N); // MOVQ *(SI)+,*(DI)+
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/6g/ggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax)
for(i = 0; i < cnt; i += widthreg) {
p = appendpp(p, AMOVQ, D_AX, 0, D_SP+D_INDIR, frame+lo+i);
}
} else if(cnt <= 128*widthreg) {
} else if(!nacl && (cnt <= 128*widthreg)) {
p = appendpp(p, leaptr, D_SP+D_INDIR, frame+lo, D_DI, 0);
p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 2*(128-cnt/widthreg));
p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
Expand Down Expand Up @@ -1119,7 +1119,7 @@ clearfat(Node *nl)
savex(D_AX, &ax, &oldax, N, types[tptr]);
gconreg(AMOVL, 0, D_AX);

if(q > 128) {
if(q > 128 || (q >= 4 && nacl)) {
gconreg(movptr, q, D_CX);
gins(AREP, N, N); // repeat
gins(ASTOSQ, N, N); // STOQ AL,*(DI)+
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/8g/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ sgen(Node *n, Node *res, int64 w)
} else {
gins(ACLD, N, N); // paranoia. TODO(rsc): remove?
// normal direction
if(q > 128) {
if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX);
gins(AREP, N, N); // repeat
gins(AMOVSL, N, N); // MOVL *(SI)+,*(DI)+
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/8g/ggen.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ zerorange(Prog *p, vlong frame, vlong lo, vlong hi, uint32 *ax)
for(i = 0; i < cnt; i += widthreg) {
p = appendpp(p, AMOVL, D_AX, 0, D_SP+D_INDIR, frame+lo+i);
}
} else if(cnt <= 128*widthreg) {
} else if(!nacl && cnt <= 128*widthreg) {
p = appendpp(p, ALEAL, D_SP+D_INDIR, frame+lo, D_DI, 0);
p = appendpp(p, ADUFFZERO, D_NONE, 0, D_ADDR, 1*(128-cnt/widthreg));
p->to.sym = linksym(pkglookup("duffzero", runtimepkg));
Expand Down Expand Up @@ -176,7 +176,7 @@ clearfat(Node *nl)
agen(nl, &n1);
gconreg(AMOVL, 0, D_AX);

if(q > 128) {
if(q > 128 || (q >= 4 && nacl)) {
gconreg(AMOVL, q, D_CX);
gins(AREP, N, N); // repeat
gins(ASTOSL, N, N); // STOL AL,*(DI)+
Expand Down

0 comments on commit c6a41a3

Please sign in to comment.