from functools import lru_cache
import os
from openpower.test.bigint.powmod import (
- PowModCases, python_divmod_algorithm, python_powmod_256_algorithm)
+ PowModCases, python_divmod_shift_sub_algorithm,
+ python_powmod_256_algorithm)
from openpower.test.runner import TestRunnerBase
class TestPythonAlgorithms(unittest.TestCase):
- def test_python_divmod_algorithm(self):
+ def test_python_divmod_shift_sub_algorithm(self):
for n, d in PowModCases.divmod_512x256_to_256x256_test_inputs():
q, r = divmod(n, d)
with self.subTest(n=f"{n:#_x}", d=f"{d:#_x}",
q=f"{q:#_x}", r=f"{r:#_x}"):
log_regex = n == 2 ** 511 - 1 and d == 2 ** 256 - 1
- out_q, out_r = python_divmod_algorithm(
+ out_q, out_r = python_divmod_shift_sub_algorithm(
n, d, log_regex=log_regex)
with self.subTest(out_q=f"{out_q:#_x}", out_r=f"{out_r:#_x}"):
self.assertEqual(out_q, q)
return y
-DIVMOD_512x256_TO_256x256_ASM = (
+DIVMOD_SHIFT_SUB_512x256_TO_256x256_ASM = (
# extremely slow and simplistic shift and subtract algorithm.
# a future task is to rewrite to use Knuth's Algorithm D,
# which is generally an order of magnitude faster
log("DIVMOD REGEX:", "".join(segments))
-def python_divmod_algorithm(n, d, width=256, log_regex=False):
+def python_divmod_shift_sub_algorithm(n, d, width=256, log_regex=False):
assert n >= 0 and d > 0 and width > 0 and n < (d << width), "invalid input"
do_log = _DivModRegsRegexLogger(enabled=log_regex).log
"sv.ld *14, -144(1)", # restore all callee-save registers
"bclr 20, 0, 0 # blr",
*MUL_256_X_256_TO_512_ASM,
- *DIVMOD_512x256_TO_256x256_ASM,
+ *DIVMOD_SHIFT_SUB_512x256_TO_256x256_ASM,
)
n -= d << 256
yield (n, d)
- def case_divmod_512x256_to_256x256(self):
+ def case_divmod_shift_sub_512x256_to_256x256(self):
for n, d in self.divmod_512x256_to_256x256_test_inputs():
q, r = divmod(n, d)
with self.subTest(n=f"{n:#_x}", d=f"{d:#_x}",
# write r in LE order to regs 8-11
e.intregs[8 + i] = (r >> (64 * i)) % 2**64
- self.call_case(DIVMOD_512x256_TO_256x256_ASM, e, initial_regs)
+ self.call_case(
+ DIVMOD_SHIFT_SUB_512x256_TO_256x256_ASM, e, initial_regs)
@staticmethod
def powmod_256_test_inputs():