Commit d169dcee authored by Russ Cox's avatar Russ Cox

fix division bug

R=ken
OCL=32760
CL=32760
parent abaf6046
......@@ -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);
}
}
/*
......
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