From 37b0381ed51ceaeff119910ecba382884c443740 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 18 Apr 2022 11:02:34 -0700 Subject: [PATCH] add requested loop variants --- openpower/sv/bitmanip/divmnu64.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/openpower/sv/bitmanip/divmnu64.c b/openpower/sv/bitmanip/divmnu64.c index 1d3585eec..93735d802 100644 --- a/openpower/sv/bitmanip/divmnu64.c +++ b/openpower/sv/bitmanip/divmnu64.c @@ -9,6 +9,7 @@ machine which has a 64/64 division instruction. */ #include #include //To define "exit", req'd by XLC. #include +#include #define max(x, y) ((x) > (y) ? (x) : (y)) @@ -106,6 +107,7 @@ again: if (rhat < b) goto again; } +#ifdef ORIGINAL // Multiply and subtract. k = 0; for (i = 0; i < n; i++) { @@ -117,6 +119,36 @@ again: t = un[j+n] - k; un[j+n] = t; bool need_fixup = t < 0; +#elif defined(SUB_MUL_BORROW) + (void)p; // shut up unused variable warning + + // Multiply and subtract. + uint32_t borrow = 0; + for(int i = 0; i <= n; i++) { + uint32_t vn_i = i < n ? vn[i] : 0; + uint64_t value = un[i + j] - (uint64_t)qhat * vn_i - borrow; + borrow = -(uint32_t)(value >> 32); + un[i + j] = (uint32_t)value; + } + bool need_fixup = borrow != 0; +#elif defined(MUL_RSUB_CARRY) + (void)p; // shut up unused variable warning + + // Multiply and subtract. + uint32_t carry = 1; + for(int i = 0; i <= n; i++) { + uint32_t vn_i = i < n ? vn[i] : 0; + uint64_t result = un[i + j] + ~((uint64_t)qhat * vn_i) + carry; + uint32_t result_high = result >> 32; + if(carry <= 1) + result_high++; + carry = result_high; + un[i + j] = (uint32_t)result; + } + bool need_fixup = carry != 1; +#else +#error need to define one of ORIGINAL, SUB_MUL_BORROW, or MUL_RSUB_CARRY +#endif q[j] = qhat; // Store quotient digit. if (need_fixup) { // If we subtracted too -- 2.30.2