]> Cypherpunks repositories - gostls13.git/commitdiff
byte multiply
authorKen Thompson <ken@golang.org>
Fri, 7 Nov 2008 22:20:32 +0000 (14:20 -0800)
committerKen Thompson <ken@golang.org>
Fri, 7 Nov 2008 22:20:32 +0000 (14:20 -0800)
R=r
OCL=18807
CL=18807

src/cmd/6g/cgen.c
src/cmd/6g/gen.c
src/cmd/6g/gg.h

index e1b970b3236901858bc008241cf598bcf5f46971..4fb9e3415d6887b963c2e83517231acda8c07d17 100644 (file)
@@ -122,7 +122,10 @@ cgen(Node *n, Node *res)
        case OADD:
        case OMUL:
                a = optoas(n->op, nl->type);
-               goto sbop;
+               if(a != AIMULB)
+                       goto sbop;
+               cgen_bmul(n->op, nl, nr, res);
+               break;
 
        // asymmetric binary
        case OSUB:
index 1b4c7e6645dbd8c9f69db74fb7d0832b76cb6c77..b9f558a60859da48aec3decfe20d4481cb7d1a92 100644 (file)
@@ -1095,6 +1095,35 @@ ret:
        ;
 }
 
+void
+cgen_bmul(int op, Node *nl, Node *nr, Node *res)
+{
+       Node n1, n2;
+       Type *t;
+       int a;
+
+       t = types[TUINT16];
+       if(issigned[nl->type->etype])
+               t = types[TINT16];
+
+       if(nl->ullman >= nr->ullman) {
+               regalloc(&n1, t, nl);
+               cgen(nl, &n1);
+               regalloc(&n2, t, nr);
+               cgen(nr, &n2);
+       } else {
+               regalloc(&n2, t, nr);
+               cgen(nr, &n2);
+               regalloc(&n1, t, nl);
+               cgen(nl, &n1);
+       }
+       a = optoas(op, t);
+       gins(a, &n2, &n1);
+       gmove(&n1, res);
+       regfree(&n1);
+       regfree(&n2);
+}
+
 void
 checklabels(void)
 {
index a26ed819b14e9ad6467d6dcb30d397c32726eb21..594689bc76e2e8b8271a1a8d4e64b36640b1e61c 100644 (file)
@@ -138,6 +138,7 @@ void        cgen_callinter(Node*, Node*, int);
 void   cgen_proc(Node*);
 void   cgen_callret(Node*, Node*);
 void   cgen_div(int, Node*, Node*, Node*);
+void   cgen_bmul(int, Node*, Node*, Node*);
 void   cgen_shift(int, Node*, Node*, Node*);
 void   genpanic(void);
 int    needconvert(Type*, Type*);