regs[rd] = 0;
*flags |= CPU_DTRACE_DIVZERO;
} else {
+ int neg = 0;
+
/*
* We cannot simply do a 64-bit division, since
* gcc translates it into a call to a function
* regs[rd] = (int64_t)regs[r1] /
* (int64_t)regs[r2];
*/
- regs[rd] = (int64_t)regs[r1];
- do_div(regs[rd], (int64_t)regs[r2]);
+ if ((int64_t)regs[r1] < 0) {
+ neg = !neg;
+ regs[r1] = -(int64_t)regs[r1];
+ }
+ if ((int64_t)regs[r2] < 0) {
+ neg = !neg;
+ regs[r2] = -(int64_t)regs[r2];
+ }
+ regs[rd] = regs[r1];
+ do_div(regs[rd], regs[r2]);
+
+ if (neg)
+ regs[rd] = -(int64_t)regs[rd];
}
break;
regs[rd] = 0;
*flags |= CPU_DTRACE_DIVZERO;
} else {
+ int neg = 0;
+
/*
* We cannot simply do a 64-bit division, since
* gcc translates it into a call to a function
* regs[rd] = (int64_t)regs[r1] %
* (int64_t)regs[r2];
*/
- regs[rd] = (int64_t)regs[r1];
- regs[rd] = do_div(regs[rd], (int64_t)regs[r2]);
+ if ((int64_t)regs[r1] < 0) {
+ neg = !neg;
+ regs[r1] = -(int64_t)regs[r1];
+ }
+ if ((int64_t)regs[r2] < 0) {
+ neg = !neg;
+ regs[r2] = -(int64_t)regs[r2];
+ }
+ regs[rd] = regs[r1];
+ regs[rd] = do_div(regs[rd], regs[r2]);
+
+ if (neg)
+ regs[rd] = -(int64_t)regs[rd];
}
break;