for (j = m - n; j >= 0; j--)
{ // Main loop.
- // Compute estimate qhat of q[j] from top 2 digits
- uint64_t dig2 = ((uint64_t)un[j + n] << 32) | un[j + n - 1];
- qhat = dig2 / vn[n - 1];
- rhat = dig2 % vn[n - 1];
+ // Compute estimate qhat of q[j] from top 2 digits.
+ // do as 2 separate divs to demo that 64/32 div/rem would
+ // be perfectly fine.
+ uint64_t dig1 = (uint64_t)un[j + n];
+ qhat = dig1 / vn[n - 1];
+ rhat = dig1 % vn[n - 1];
+ uint64_t dig2 = ((uint64_t)rhat << 32) | un[j + n - 1];
+ qhat = dig2 / vn[n - 1] | (qhat<<32);
+ rhat = dig2 % vn[n - 1] | (rhat<<32);
again:
// use 3rd-from-top digit to obtain better accuracy
if (qhat >= b || qhat * vn[n - 2] > b * rhat + un[j + n - 2])