remove relative imports, use explicit. requires installation
[nmigen-gf.git] / gf_reference / decode_reducing_polynomial.py
1 from nmigen_gf.reference.state import ST
2
3
4 def decode_reducing_polynomial():
5 """returns the decoded reducing polynomial as an integer.
6 Note: the returned integer is `XLEN + 1` bits wide.
7 """
8 v = ST.GFBREDPOLY & ((1 << ST.XLEN) - 1) # mask to XLEN bits
9 if v == 0 or v == 2: # GF(2)
10 return 0b10 # degree = 1, poly = x
11 if (v & 1) == 0:
12 # all reducing polynomials of degree > 1 must have the LSB set,
13 # because they must be irreducible polynomials (meaning they
14 # can't be factored), if the LSB was clear, then they would
15 # have `x` as a factor. Therefore, we can reuse the LSB clear
16 # to instead mean the polynomial has degree XLEN.
17 v |= 1 << ST.XLEN
18 v |= 1 # LSB must be set
19 return v