Commit 01ef6dbf authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/5g, cmd/6g, cmd/8g, cmd/9g: use a register to zero in componentgen

Using a zero register results in shorter, faster code.
5g already did this. Bring 6g, 8g, and 9g up to speed.
Reduces godoc binary size by 0.29% using 6g.

This CL includes cosmetic changes to 5g and 8g.
With those cosmetic changes included, componentgen is now
character-for-character equivalent across the four architectures.

Change-Id: I0e13dd48374bad830c725b117a1c86d4197d390c
Reviewed-on: https://go-review.googlesource.com/2606Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
parent 8f734d4e
...@@ -1626,6 +1626,8 @@ cadable(Node *n) ...@@ -1626,6 +1626,8 @@ cadable(Node *n)
/* /*
* copy a composite value by moving its individual components. * copy a composite value by moving its individual components.
* Slices, strings and interfaces are supported. * Slices, strings and interfaces are supported.
* Small structs or arrays with elements of basic type are
* also supported.
* nr is N when assigning a zero value. * nr is N when assigning a zero value.
* return 1 if can do, 0 if cant. * return 1 if can do, 0 if cant.
*/ */
...@@ -1700,7 +1702,6 @@ componentgen(Node *nr, Node *nl) ...@@ -1700,7 +1702,6 @@ componentgen(Node *nr, Node *nl)
freer = 1; freer = 1;
} }
// nl and nr are 'cadable' which basically means they are names (variables) now. // nl and nr are 'cadable' which basically means they are names (variables) now.
// If they are the same variable, don't generate any code, because the // If they are the same variable, don't generate any code, because the
// VARDEF we generate will mark the old value as dead incorrectly. // VARDEF we generate will mark the old value as dead incorrectly.
......
...@@ -1539,7 +1539,7 @@ cadable(Node *n) ...@@ -1539,7 +1539,7 @@ cadable(Node *n)
int int
componentgen(Node *nr, Node *nl) componentgen(Node *nr, Node *nl)
{ {
Node nodl, nodr; Node nodl, nodr, tmp;
Type *t; Type *t;
int freel, freer; int freel, freer;
vlong fldcount; vlong fldcount;
...@@ -1599,6 +1599,12 @@ componentgen(Node *nr, Node *nl) ...@@ -1599,6 +1599,12 @@ componentgen(Node *nr, Node *nl)
igen(nr, &nodr, N); igen(nr, &nodr, N);
freer = 1; freer = 1;
} }
} else {
// When zeroing, prepare a register containing zero.
nodconst(&tmp, nl->type, 0);
regalloc(&nodr, types[TUINT], N);
gmove(&tmp, &nodr);
freer = 1;
} }
// nl and nr are 'cadable' which basically means they are names (variables) now. // nl and nr are 'cadable' which basically means they are names (variables) now.
...@@ -1635,8 +1641,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1635,8 +1641,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1645,8 +1650,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1645,8 +1650,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_cap-Array_nel; nodl.xoffset += Array_cap-Array_nel;
...@@ -1655,8 +1659,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1655,8 +1659,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_cap-Array_nel; nodr.xoffset += Array_cap-Array_nel;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1670,8 +1673,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1670,8 +1673,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1680,8 +1682,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1680,8 +1682,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1695,8 +1696,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1695,8 +1696,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1705,8 +1705,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1705,8 +1705,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
......
...@@ -1373,13 +1373,15 @@ cadable(Node *n) ...@@ -1373,13 +1373,15 @@ cadable(Node *n)
/* /*
* copy a composite value by moving its individual components. * copy a composite value by moving its individual components.
* Slices, strings and interfaces are supported. * Slices, strings and interfaces are supported.
* Small structs or arrays with elements of basic type are
* also supported.
* nr is N when assigning a zero value. * nr is N when assigning a zero value.
* return 1 if can do, 0 if can't. * return 1 if can do, 0 if can't.
*/ */
int int
componentgen(Node *nr, Node *nl) componentgen(Node *nr, Node *nl)
{ {
Node nodl, nodr; Node nodl, nodr, tmp;
Type *t; Type *t;
int freel, freer; int freel, freer;
vlong fldcount; vlong fldcount;
...@@ -1439,6 +1441,12 @@ componentgen(Node *nr, Node *nl) ...@@ -1439,6 +1441,12 @@ componentgen(Node *nr, Node *nl)
igen(nr, &nodr, N); igen(nr, &nodr, N);
freer = 1; freer = 1;
} }
} else {
// When zeroing, prepare a register containing zero.
nodconst(&tmp, nl->type, 0);
regalloc(&nodr, types[TUINT], N);
gmove(&tmp, &nodr);
freer = 1;
} }
// nl and nr are 'cadable' which basically means they are names (variables) now. // nl and nr are 'cadable' which basically means they are names (variables) now.
...@@ -1475,8 +1483,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1475,8 +1483,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1485,8 +1492,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1485,8 +1492,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_cap-Array_nel; nodl.xoffset += Array_cap-Array_nel;
...@@ -1495,8 +1501,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1495,8 +1501,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_cap-Array_nel; nodr.xoffset += Array_cap-Array_nel;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1510,8 +1515,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1510,8 +1515,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1520,8 +1524,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1520,8 +1524,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1535,8 +1538,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1535,8 +1538,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1545,8 +1547,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1545,8 +1547,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
......
...@@ -1554,7 +1554,7 @@ cadable(Node *n) ...@@ -1554,7 +1554,7 @@ cadable(Node *n)
int int
componentgen(Node *nr, Node *nl) componentgen(Node *nr, Node *nl)
{ {
Node nodl, nodr; Node nodl, nodr, tmp;
Type *t; Type *t;
int freel, freer; int freel, freer;
vlong fldcount; vlong fldcount;
...@@ -1614,6 +1614,12 @@ componentgen(Node *nr, Node *nl) ...@@ -1614,6 +1614,12 @@ componentgen(Node *nr, Node *nl)
igen(nr, &nodr, N); igen(nr, &nodr, N);
freer = 1; freer = 1;
} }
} else {
// When zeroing, prepare a register containing zero.
nodconst(&tmp, nl->type, 0);
regalloc(&nodr, types[TUINT], N);
gmove(&tmp, &nodr);
freer = 1;
} }
// nl and nr are 'cadable' which basically means they are names (variables) now. // nl and nr are 'cadable' which basically means they are names (variables) now.
...@@ -1650,8 +1656,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1650,8 +1656,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1660,8 +1665,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1660,8 +1665,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_cap-Array_nel; nodl.xoffset += Array_cap-Array_nel;
...@@ -1670,8 +1674,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1670,8 +1674,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_cap-Array_nel; nodr.xoffset += Array_cap-Array_nel;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1685,8 +1688,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1685,8 +1688,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1695,8 +1697,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1695,8 +1697,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
...@@ -1710,8 +1711,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1710,8 +1711,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_array; nodr.xoffset += Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
nodl.xoffset += Array_nel-Array_array; nodl.xoffset += Array_nel-Array_array;
...@@ -1720,8 +1720,7 @@ componentgen(Node *nr, Node *nl) ...@@ -1720,8 +1720,7 @@ componentgen(Node *nr, Node *nl)
if(nr != N) { if(nr != N) {
nodr.xoffset += Array_nel-Array_array; nodr.xoffset += Array_nel-Array_array;
nodr.type = nodl.type; nodr.type = nodl.type;
} else }
nodconst(&nodr, nodl.type, 0);
gmove(&nodr, &nodl); gmove(&nodr, &nodl);
goto yes; goto yes;
......
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