1 from nmigen_gf
.reference
.state
import ST
4 def decode_reducing_polynomial():
5 """returns the decoded reducing polynomial as an integer.
6 Note: the returned integer is `XLEN + 1` bits wide.
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
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.
18 v |
= 1 # LSB must be set