From 7178a60fc9b8079c2e85976547f3739c62dc7ae5 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 14 Mar 2022 22:24:12 -0700 Subject: [PATCH] move pack/unpack_poly to separate file --- openpower/sv/bitmanip.mdwn | 18 +----------------- openpower/sv/bitmanip/pack_poly.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 openpower/sv/bitmanip/pack_poly.py diff --git a/openpower/sv/bitmanip.mdwn b/openpower/sv/bitmanip.mdwn index 75703e79e..6ce42a991 100644 --- a/openpower/sv/bitmanip.mdwn +++ b/openpower/sv/bitmanip.mdwn @@ -533,23 +533,7 @@ instruction is not provided since the `xor[i]` instruction can be used instead. These are operations on polynomials with coefficients in `GF(2)`, with the polynomial's coefficients packed into integers with the following algorithm: -```python -def pack_poly(poly): - """`poly` is a list where `poly[i]` is the coefficient for `x ** i`""" - retval = 0 - for i, v in enumerate(poly): - retval |= v << i - return retval - -def unpack_poly(v): - """returns a list `poly`, where `poly[i]` is the coefficient for `x ** i`. - """ - poly = [] - while v != 0: - poly.append(v & 1) - v >>= 1 - return poly -``` +[[!inline pagenames="openpower/sv/bitmanip/pack_poly.py" raw="true" feeds="no" actions="yes"]] ## Carry-less Multiply Instructions diff --git a/openpower/sv/bitmanip/pack_poly.py b/openpower/sv/bitmanip/pack_poly.py new file mode 100644 index 000000000..f5ab64467 --- /dev/null +++ b/openpower/sv/bitmanip/pack_poly.py @@ -0,0 +1,19 @@ +"""Polynomials with GF(2) coefficients.""" + + +def pack_poly(poly): + """`poly` is a list where `poly[i]` is the coefficient for `x ** i`""" + retval = 0 + for i, v in enumerate(poly): + retval |= v << i + return retval + + +def unpack_poly(v): + """returns a list `poly`, where `poly[i]` is the coefficient for `x ** i`. + """ + poly = [] + while v != 0: + poly.append(v & 1) + v >>= 1 + return poly -- 2.30.2