From: Jacob Lifshay Date: Thu, 28 Sep 2023 02:48:50 +0000 (-0700) Subject: test python_divmod_algorithm X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cef908de99773b7b8dfb4defc1abe013386416b7;p=openpower-isa.git test python_divmod_algorithm --- diff --git a/src/openpower/decoder/isa/test_caller_svp64_powmod.py b/src/openpower/decoder/isa/test_caller_svp64_powmod.py index 37da2b72..68afdf8f 100644 --- a/src/openpower/decoder/isa/test_caller_svp64_powmod.py +++ b/src/openpower/decoder/isa/test_caller_svp64_powmod.py @@ -14,9 +14,22 @@ related bugs: import unittest from functools import lru_cache import os -from openpower.test.bigint.powmod import PowModCases +from openpower.test.bigint.powmod import PowModCases, python_divmod_algorithm from openpower.test.runner import TestRunnerBase + +class TestPythonAlgorithms(unittest.TestCase): + def test_python_divmod_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}"): + out_q, out_r = python_divmod_algorithm(n, d) + with self.subTest(out_q=f"{out_q:#_x}", out_r=f"{out_r:#_x}"): + self.assertEqual(out_q, q) + self.assertEqual(out_r, r) + + # writing the test_caller invocation this way makes it work with pytest diff --git a/src/openpower/test/bigint/powmod.py b/src/openpower/test/bigint/powmod.py index 057f4520..3e97eef2 100644 --- a/src/openpower/test/bigint/powmod.py +++ b/src/openpower/test/bigint/powmod.py @@ -212,8 +212,8 @@ class PowModCases(TestAccumulatorBase): self.call_case(MUL_256_X_256_TO_512_ASM, e, initial_regs) - @skip_case("FIXME: wip -- currently broken") - def case_divmod_512x256_to_256x256(self): + @staticmethod + def divmod_512x256_to_256x256_test_inputs(): for i in range(10): n = hash_256(f"divmod256 input n msb {i}") n <<= 256 @@ -231,6 +231,11 @@ class PowModCases(TestAccumulatorBase): d = 1 if n >= d << 256: n -= d << 256 + yield (n, d) + + @skip_case("FIXME: wip -- currently broken") + def case_divmod_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}", q=f"{q:#_x}", r=f"{r:#_x}"):