From: Luke Kenneth Casson Leighton Date: Sun, 24 Apr 2022 17:35:18 +0000 (+0100) Subject: move bigadd out into separate function, use it X-Git-Tag: opf_rfc_ls005_v1~2605 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=44661f0f3a471df578e5c2b5470e501f91323177;p=libreriscv.git move bigadd out into separate function, use it --- diff --git a/openpower/sv/biginteger/divgnu64.c b/openpower/sv/biginteger/divgnu64.c index 593b126d3..ebb46d1cc 100644 --- a/openpower/sv/biginteger/divgnu64.c +++ b/openpower/sv/biginteger/divgnu64.c @@ -75,6 +75,20 @@ bool bigmul(unsigned long long qhat, unsigned product[], unsigned vn[], return carry != 0; } +bool bigadd(unsigned result[], unsigned vn[], unsigned un[], + int m, int n, bool ca) +{ + // VL = n + 1 + // sv.subfe un_j.v, product.v, un_j.v + for (int i = 0; i <= n; i++) + { + uint64_t value = (uint64_t)vn[i] + (uint64_t)un[i] + ca; + ca = value >> 32 != 0; + result[i] = value; + } + return ca; +} + bool bigsub(unsigned result[], unsigned vn[], unsigned un[], int m, int n, bool ca) { @@ -189,14 +203,7 @@ int divmnu(unsigned q[], unsigned r[], const unsigned u[], const unsigned v[], if (need_fixup) { // If we subtracted too q[j] = q[j] - 1; // much, add back. - k = 0; - for (i = 0; i < n; i++) - { - t = (unsigned long long)un[i + j] + vn[i] + k; - un[i + j] = t; - k = t >> 32; - } - un[j + n] = un[j + n] + k; + bigadd(un_j, vn, un_j, m, n, 0); } } // End j. // If the caller wants the remainder, unnormalize