From: Jacob Lifshay Date: Tue, 15 Mar 2022 08:41:15 +0000 (-0700) Subject: translate clmul* to python for easier testing X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=633b8c74cce4c1282e1e6d456191d82d7a0627ca;p=nmutil.git translate clmul* to python for easier testing --- diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/clmul.py b/clmul.py new file mode 100644 index 0000000..7451c3c --- /dev/null +++ b/clmul.py @@ -0,0 +1,8 @@ +def clmul(a, b): + x = 0 + i = 0 + while b >> i != 0: + if (b >> i) & 1: + x ^= a << i + i += 1 + return x diff --git a/clmulh.py b/clmulh.py new file mode 100644 index 0000000..b170aca --- /dev/null +++ b/clmulh.py @@ -0,0 +1,5 @@ +from .clmul import clmul + + +def clmulh(a, b, XLEN): + return clmul(a, b) >> XLEN diff --git a/clmulr.py b/clmulr.py new file mode 100644 index 0000000..5b155b5 --- /dev/null +++ b/clmulr.py @@ -0,0 +1,5 @@ +from .clmul import clmul + + +def clmulh(a, b, XLEN): + return clmul(a, b) >> (XLEN - 1)