--- /dev/null
+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
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 \
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