]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.power64] cmd/9g: introduce ginscon2 for CMP/CMPU, use ginscon to ADD constants
authorShenghou Ma <minux@golang.org>
Wed, 13 Aug 2014 03:57:02 +0000 (23:57 -0400)
committerShenghou Ma <minux@golang.org>
Wed, 13 Aug 2014 03:57:02 +0000 (23:57 -0400)
LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/125170043

src/cmd/9g/cgen.c
src/cmd/9g/gg.h
src/cmd/9g/gsubr.c

index 3644ebf8f60ad931060036f73200088e9fe376ba..f8078aece3652afea1b91835580dab088334a44e 100644 (file)
@@ -690,8 +690,7 @@ agenr(Node *n, Node *a, Node *res)
                                        n1.xoffset = Array_nel;
                                        regalloc(&n4, n1.type, N);
                                        gmove(&n1, &n4);
-                                       nodconst(&n2, types[TUINT64], v);
-                                       gins(optoas(OCMP, types[TUINT64]), &n4, &n2);
+                                       ginscon2(optoas(OCMP, types[TUINT64]), &n4, v);
                                        regfree(&n4);
                                        p1 = gbranch(optoas(OGT, types[TUINT64]), T, +1);
                                        ginscall(panicindex, 0);
@@ -706,8 +705,7 @@ agenr(Node *n, Node *a, Node *res)
                        }
 
                        if (v*w != 0) {
-                               nodconst(&n2, types[tptr], v*w);
-                               gins(optoas(OADD, types[tptr]), &n2, &n3);
+                               ginscon(optoas(OADD, types[tptr]), v*w, &n3);
                        }
                        *a = n3;
                        break;
index 2b95dc7a6ff862a10775b9b000bb1551bc1abdf9..319702200c675edd2efa56e0921b7590bfd23a0e 100644 (file)
@@ -87,6 +87,7 @@ Node* nodarg(Type*, int);
 void   nodreg(Node*, Type*, int);
 void   nodindreg(Node*, Type*, int);
 void   ginscon(int, vlong, Node*);
+void   ginscon2(int, Node*, vlong);
 void   buildtxt(void);
 Plist* newplist(void);
 int    isfat(Type*);
index 0e5df5c6dc45dbb4478642af7252d07607fac985..a5ce5f141f67d98427d733a8339b4ad5f78f12cf 100644 (file)
@@ -562,6 +562,40 @@ ginscon(int as, vlong c, Node *n2)
        gins(as, &n1, n2);
 }
 
+/*
+ * generate
+ *     as n, $c (CMP/CMPU)
+ */
+void
+ginscon2(int as, Node *n2, vlong c)
+{
+       Node n1, ntmp;
+
+       nodconst(&n1, types[TINT64], c);
+
+       switch(as) {
+       default:
+               fatal("ginscon2");
+       case ACMP:
+               if(-BIG <= c && c <= BIG) {
+                       gins(as, n2, &n1);
+                       return;
+               }
+               break;
+       case ACMPU:
+               if(0 <= c && c <= 2*BIG) {
+                       gins(as, n2, &n1);
+                       return;
+               }
+               break;
+       }
+       // MOV n1 into register first
+       regalloc(&ntmp, types[TINT64], N);
+       gins(AMOVD, &n1, &ntmp);
+       gins(as, n2, &ntmp);
+       regfree(&ntmp);
+}
+
 #define        CASE(a,b)       (((a)<<16)|((b)<<0))
 /*c2go int CASE(int, int); */