gf_reference/is_irreducible.py: move is_irreducible() to a separate file
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 17 May 2024 08:09:11 +0000 (01:09 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 17 May 2024 08:09:11 +0000 (01:09 -0700)
gf_reference/is_irreducible.py [new file with mode: 0644]
src/nmigen_gf/hdl/test/test_gfbinv.py

diff --git a/gf_reference/is_irreducible.py b/gf_reference/is_irreducible.py
new file mode 100644 (file)
index 0000000..f341e98
--- /dev/null
@@ -0,0 +1,15 @@
+from nmigen_gf.reference.cldivrem import cldivrem, degree
+
+def is_irreducible(poly):
+    # type: (int) -> bool
+    if poly == 0b10:
+        return True
+    if poly & 1 == 0:
+        return False
+    d = degree(poly)
+    half_degree = d // 2
+    for trial_divisor in range(0b11, 1 << (1 + half_degree), 2):
+        q, r = cldivrem(poly, trial_divisor, width=d + 1)
+        if q != 1 and r == 0:
+            return False
+    return True
index 957ce3540e65e8b457e43faa5c09e5457535cb52..c639062ecf046fd1bcafd9d469d437b3b06fe615 100644 (file)
@@ -13,7 +13,7 @@ import unittest
 from nmigen.hdl.ast import Const, unsigned
 from nmutil.formaltest import FHDLTestCase
 from nmigen_gf.reference.gfbinv import gfbinv
-from nmigen_gf.reference.cldivrem import degree, cldivrem
+from nmigen_gf.reference.is_irreducible import is_irreducible
 from nmigen_gf.hdl.gfbinv import \
     py_gfbinv_algorithm, GFBInvShape, GFBInvFSMStage
 from nmigen_gf.reference.decode_reducing_polynomial import \
@@ -24,22 +24,6 @@ from nmigen_gf.reference.state import ST
 import itertools
 
 
-def is_irreducible(poly):
-    # type: (int) -> bool
-    assert poly < 2 ** 33, "too slow for testing"
-    if poly == 0b10:
-        return True
-    if poly & 1 == 0:
-        return False
-    d = degree(poly)
-    half_degree = d // 2
-    for trial_divisor in range(0b11, 1 << (1 + half_degree), 2):
-        q, r = cldivrem(poly, trial_divisor, width=d + 1)
-        if q != 1 and r == 0:
-            return False
-    return True
-
-
 class TestPyGFBInv(FHDLTestCase):
     def tst(self, XLEN, full):
         # type: (int, bool) -> None