]> Cypherpunks repositories - gostls13.git/commitdiff
fix division bug
authorRuss Cox <rsc@golang.org>
Wed, 5 Aug 2009 00:59:10 +0000 (17:59 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 5 Aug 2009 00:59:10 +0000 (17:59 -0700)
R=ken
OCL=32760
CL=32760

src/cmd/6g/ggen.c

index d0f9ab3f91ad6f418efefae11b05d7ffbd9d3753..f51839f49b2fa599598a13a2ecd535cae8cf4ad4 100644 (file)
@@ -534,21 +534,46 @@ dodiv(int op, Node *nl, Node *nr, Node *res, Node *ax, Node *dx)
 void
 cgen_div(int op, Node *nl, Node *nr, Node *res)
 {
-       Node ax, dx;
+       Node ax, dx, oldax, olddx;
        int rax, rdx;
 
+       if(nl->ullman >= UINF || nr->ullman >= UINF)
+               fatal("cgen_div UINF");
+
        rax = reg[D_AX];
        rdx = reg[D_DX];
-
+       
        nodreg(&ax, types[TINT64], D_AX);
        nodreg(&dx, types[TINT64], D_DX);
        regalloc(&ax, nl->type, &ax);
        regalloc(&dx, nl->type, &dx);
 
+       // save current ax and dx if they are live
+       memset(&oldax, 0, sizeof oldax);
+       memset(&olddx, 0, sizeof olddx);
+       if(rax > 0) {
+               regalloc(&oldax, nl->type, N);
+               gmove(&ax, &oldax);
+       }
+       if(rdx > 0) {
+               regalloc(&olddx, nl->type, N);
+               gmove(&dx, &olddx);
+       }
+
        dodiv(op, nl, nr, res, &ax, &dx);
 
        regfree(&ax);
        regfree(&dx);
+       
+       if(rax > 0) {
+               gmove(&oldax, &ax);
+               regfree(&oldax);
+       }
+       if(rdx > 0) {
+               gmove(&olddx, &dx);
+               regfree(&olddx);
+       }
+               
 }
 
 /*