Move files from libreriscv.git/openpower/sv/bitmanip/
[nmigen-gf.git] / gf_reference / pack_poly.py
1 """Polynomials with GF(2) coefficients."""
2
3
4 def pack_poly(poly):
5 """`poly` is a list where `poly[i]` is the coefficient for `x ** i`"""
6 retval = 0
7 for i, v in enumerate(poly):
8 retval |= v << i
9 return retval
10
11
12 def unpack_poly(v):
13 """returns a list `poly`, where `poly[i]` is the coefficient for `x ** i`.
14 """
15 poly = []
16 while v != 0:
17 poly.append(v & 1)
18 v >>= 1
19 return poly