1
0
mirror of https://github.com/golang/go synced 2024-11-21 16:34:42 -07:00

5c, 6c, 8c: support 64-bit switch value

For real this time. :-)

R=rsc, ken
CC=golang-dev
https://golang.org/cl/5486061
This commit is contained in:
Anthony Martin 2011-12-14 17:30:40 -05:00 committed by Russ Cox
parent 8fbeb945db
commit d89b7173c2
7 changed files with 66 additions and 17 deletions

View File

@ -304,6 +304,7 @@ void gpseudo(int, Sym*, Node*);
int swcmp(const void*, const void*);
void doswit(Node*);
void swit1(C1*, int, int32, Node*);
void swit2(C1*, int, int32, Node*);
void newcase(void);
void bitload(Node*, Node*, Node*, Node*, Node*);
void bitstore(Node*, Node*, Node*, Node*, Node*);

View File

@ -28,11 +28,30 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "gc.h"
void
swit1(C1 *q, int nc, int32 def, Node *n)
{
Node nreg;
if(typev[n->type->etype]) {
regsalloc(&nreg, n);
nreg.type = types[TVLONG];
cgen(n, &nreg);
swit2(q, nc, def, &nreg);
return;
}
regalloc(&nreg, n, Z);
nreg.type = types[TLONG];
cgen(n, &nreg);
swit2(q, nc, def, &nreg);
regfree(&nreg);
}
void
swit2(C1 *q, int nc, int32 def, Node *n)
{
C1 *r;
int i;
@ -65,12 +84,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
sp = p;
gopcode(OEQ, nodconst(r->val), n, Z); /* just gen the B.EQ */
patch(p, r->label);
swit1(q, i, def, n);
swit2(q, i, def, n);
if(debug['W'])
print("case < %.8ux\n", r->val);
patch(sp, pc);
swit1(r+1, nc-i-1, def, n);
swit2(r+1, nc-i-1, def, n);
return;
direct:

View File

@ -299,6 +299,7 @@ void gpseudo(int, Sym*, Node*);
int swcmp(const void*, const void*);
void doswit(Node*);
void swit1(C1*, int, int32, Node*);
void swit2(C1*, int, int32, Node*);
void newcase(void);
void bitload(Node*, Node*, Node*, Node*, Node*);
void bitstore(Node*, Node*, Node*, Node*, Node*);

View File

@ -32,6 +32,21 @@
void
swit1(C1 *q, int nc, int32 def, Node *n)
{
Node nreg;
regalloc(&nreg, n, Z);
if(typev[n->type->etype])
nreg.type = types[TVLONG];
else
nreg.type = types[TLONG];
cgen(n, &nreg);
swit2(q, nc, def, &nreg);
regfree(&nreg);
}
void
swit2(C1 *q, int nc, int32 def, Node *n)
{
C1 *r;
int i;
@ -58,12 +73,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
gbranch(OGOTO);
p->as = AJEQ;
patch(p, r->label);
swit1(q, i, def, n);
swit2(q, i, def, n);
if(debug['W'])
print("case < %.8llux\n", r->val);
patch(sp, pc);
swit1(r+1, nc-i-1, def, n);
swit2(r+1, nc-i-1, def, n);
}
void

View File

@ -304,6 +304,7 @@ void gpseudo(int, Sym*, Node*);
int swcmp(const void*, const void*);
void doswit(Node*);
void swit1(C1*, int, int32, Node*);
void swit2(C1*, int, int32, Node*);
void newcase(void);
void bitload(Node*, Node*, Node*, Node*, Node*);
void bitstore(Node*, Node*, Node*, Node*, Node*);

View File

@ -32,6 +32,26 @@
void
swit1(C1 *q, int nc, int32 def, Node *n)
{
Node nreg;
if(typev[n->type->etype]) {
regsalloc(&nreg, n);
nreg.type = types[TVLONG];
cgen(n, &nreg);
swit2(q, nc, def, &nreg);
return;
}
regalloc(&nreg, n, Z);
nreg.type = types[TLONG];
cgen(n, &nreg);
swit2(q, nc, def, &nreg);
regfree(&nreg);
}
void
swit2(C1 *q, int nc, int32 def, Node *n)
{
C1 *r;
int i;
@ -58,12 +78,12 @@ swit1(C1 *q, int nc, int32 def, Node *n)
gbranch(OGOTO);
p->as = AJEQ;
patch(p, r->label);
swit1(q, i, def, n);
swit2(q, i, def, n);
if(debug['W'])
print("case < %.8ux\n", r->val);
patch(sp, pc);
swit1(r+1, nc-i-1, def, n);
swit2(r+1, nc-i-1, def, n);
}
void

View File

@ -293,7 +293,7 @@ loop:
complex(l);
if(l->type == T)
break;
if(!typeword[l->type->etype] || l->type->etype == TIND) {
if(!typechlvp[l->type->etype] || l->type->etype == TIND) {
diag(n, "switch expression must be integer");
break;
}
@ -320,15 +320,7 @@ loop:
}
patch(sp, pc);
regalloc(&nod, l, Z);
/* always signed */
if(typev[l->type->etype])
nod.type = types[TVLONG];
else
nod.type = types[TLONG];
cgen(l, &nod);
doswit(&nod);
regfree(&nod);
doswit(l);
patch(spb, pc);
cases = cn;