working on goldschmidt_div_sqrt.py
[soc.git] / src / soc / fu / div / experiment / test / test_goldschmidt_div_sqrt.py
index e3c28b6413c7c621c57b9cf8b153a136007d04a8..fd07d6151a3e2fb187e36b17d41905a64f09c6e9 100644 (file)
@@ -6,7 +6,7 @@
 
 import unittest
 from nmutil.formaltest import FHDLTestCase
-from soc.fu.div.experiment.goldschmidt_div_sqrt import (goldschmidt_div,
+from soc.fu.div.experiment.goldschmidt_div_sqrt import (GoldschmidtDivParams, goldschmidt_div,
                                                         FixedPoint)
 
 
@@ -21,19 +21,25 @@ class TestFixedPoint(FHDLTestCase):
 
 
 class TestGoldschmidtDiv(FHDLTestCase):
-    def tst(self, width):
-        assert isinstance(width, int)
-        for d in range(1, 1 << width):
-            for n in range(d << width):
-                expected = n // d
-                with self.subTest(width=width, n=hex(n), d=hex(d),
-                                  expected=hex(expected)):
-                    result = goldschmidt_div(n, d, width)
-                    self.assertEqual(result, expected, f"result={hex(result)}")
+    @unittest.skip("goldschmidt_div isn't finished yet")
+    def tst(self, io_width):
+        assert isinstance(io_width, int)
+        params = GoldschmidtDivParams.get(io_width)
+        with self.subTest(params=str(params)):
+            for d in range(1, 1 << io_width):
+                for n in range(d << io_width):
+                    expected_q, expected_r = divmod(n, d)
+                    with self.subTest(n=hex(n), d=hex(d),
+                                      expected_q=hex(expected_q),
+                                      expected_r=hex(expected_r)):
+                        q, r = goldschmidt_div(n, d, params)
+                        with self.subTest(q=hex(q), r=hex(r)):
+                            self.assertEqual((q, r), (expected_q, expected_r))
 
     def test_1_through_5(self):
-        for width in range(1, 5 + 1):
-            self.tst(width)
+        for io_width in range(1, 5 + 1):
+            with self.subTest(io_width=io_width):
+                self.tst(io_width)
 
     def test_6(self):
         self.tst(6)