test python_divmod_algorithm
authorJacob Lifshay <programmerjake@gmail.com>
Thu, 28 Sep 2023 02:48:50 +0000 (19:48 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Thu, 28 Sep 2023 02:48:50 +0000 (19:48 -0700)
src/openpower/decoder/isa/test_caller_svp64_powmod.py
src/openpower/test/bigint/powmod.py

index 37da2b728ab9a4b3c126db6f3e3f55148bcd50e7..68afdf8f44c086677174b34f526555de2f38f636 100644 (file)
@@ -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
 
 
index 057f45209a07c0a4a52e233276263aff46bb6000..3e97eef2d9fd645f89ed9eb9c4ba7a86821f63d2 100644 (file)
@@ -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}"):