From: Luke Kenneth Casson Leighton Date: Tue, 26 Apr 2022 16:12:16 +0000 (+0100) Subject: split out bigdiv as separate function X-Git-Tag: opf_rfc_ls005_v1~2579 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=98183472267683bd5074a447e4a80ecaa697a7db;p=libreriscv.git split out bigdiv as separate function --- diff --git a/openpower/sv/biginteger/divgnu64.c b/openpower/sv/biginteger/divgnu64.c index 3c216eff8..762f8d965 100644 --- a/openpower/sv/biginteger/divgnu64.c +++ b/openpower/sv/biginteger/divgnu64.c @@ -70,6 +70,17 @@ void biglsh(unsigned s, unsigned vn[], unsigned const v[], int n) vn[0] = v[0] << s; } +long bigdiv(unsigned v, unsigned q[], unsigned const u[], int m) +{ + long long k = 0; // the case of a + for (int j = m - 1; j >= 0; j--) { // single-digit + unsigned long d2 = (k << 32) | u[j]; + q[j] = d2 / v; // divisor here. + k = d2 % v; + } + return k; +} + bool bigmul(unsigned long long qhat, unsigned product[], unsigned vn[], int m, int n) { @@ -166,11 +177,7 @@ int divmnu(unsigned q[], unsigned r[], const unsigned u[], const unsigned v[], return 1; // Return if invalid param. if (n == 1) { // Take care of - k = 0; // the case of a - for (j = m - 1; j >= 0; j--) { // single-digit - q[j] = (k * b + u[j]) / v[0]; // divisor here. - k = (k * b + u[j]) - q[j] * v[0]; - } + k = bigdiv(v[0], q, u, m); if (r != NULL) r[0] = k; return 0;