From: Jacob Lifshay Date: Fri, 17 May 2024 08:09:11 +0000 (-0700) Subject: gf_reference/is_irreducible.py: move is_irreducible() to a separate file X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9d615801f85b1878bc46548bca1479c73438bf8c;p=nmigen-gf.git gf_reference/is_irreducible.py: move is_irreducible() to a separate file --- diff --git a/gf_reference/is_irreducible.py b/gf_reference/is_irreducible.py new file mode 100644 index 0000000..f341e98 --- /dev/null +++ b/gf_reference/is_irreducible.py @@ -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 diff --git a/src/nmigen_gf/hdl/test/test_gfbinv.py b/src/nmigen_gf/hdl/test/test_gfbinv.py index 957ce35..c639062 100644 --- a/src/nmigen_gf/hdl/test/test_gfbinv.py +++ b/src/nmigen_gf/hdl/test/test_gfbinv.py @@ -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