From: Luke Kenneth Casson Leighton Date: Mon, 25 Apr 2022 20:12:19 +0000 (+0100) Subject: https://bugs.libre-soc.org/show_bug.cgi?id=817#c31 X-Git-Tag: opf_rfc_ls005_v1~2590 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cd637a98ce7fdffcbbeffe8426dee0e8c8c37475;p=libreriscv.git https://bugs.libre-soc.org/show_bug.cgi?id=817#c31 use 2-step 64/32 divides (experiment) --- diff --git a/openpower/sv/biginteger/divmnu64.c b/openpower/sv/biginteger/divmnu64.c index c77d9b780..a243bcd96 100644 --- a/openpower/sv/biginteger/divmnu64.c +++ b/openpower/sv/biginteger/divmnu64.c @@ -125,10 +125,15 @@ int divmnu(unsigned q[], unsigned r[], const unsigned u[], const unsigned v[], 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])