summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/add_python/lilliput/multiplications.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/add_python/lilliput/multiplications.py b/src/add_python/lilliput/multiplications.py
index 65c75ab..09eaa08 100644
--- a/src/add_python/lilliput/multiplications.py
+++ b/src/add_python/lilliput/multiplications.py
@@ -23,8 +23,11 @@ from functools import reduce
from operator import xor
+def _shl(xi, n):
+ return (xi << n) & 0xff
+
def _Sl(n):
- return lambda xi: (xi<<n) & 0xff
+ return lambda xi: _shl(xi, n)
def _Sr(n):
return lambda xi: xi>>n
@@ -36,16 +39,25 @@ def _0(xi):
return 0
def _M1(xi):
- return (xi<<3 ^ xi>>3) & 0xff
+ return _shl(xi, 3) ^ xi>>3
def _M2(xi):
- return (xi<<6 ^ (xi&0b11111000) ^ xi>>6) & 0xff
+ return _shl(xi, 6) ^ xi&0b11111000 ^ xi>>6
def _M3(xi):
- return xi & 0b00011111
+ return _shl(xi>>3, 6) ^ xi>>6<<3
def _M4(xi):
- return ((xi<<2) & 0xff) >> 3
+ return _shl(xi, 2) >> 3
+
+def _M5(xi):
+ return _shl(xi, 5) ^ xi>>3<<2
+
+def _M6(xi):
+ return xi & 0b00011111
+
+def _M7(xi):
+ return _shl(xi, 2) >> 3
M = (
@@ -81,6 +93,17 @@ M3 = (
( _0, _0, _Id, _0, _0, _0, _0, _0),
)
+M4 = (
+ ( _0, _0, _Sl(6), _M1, _Id, _0, _0, _0),
+ ( _0, _0, _0, _M2, _M1, _Id, _0, _0),
+ ( _0, _Sl(2), _0, _M3, _M2, _M1, _Id, _0),
+ ( _0, _M4, _Sl(2), _0, _0, _Sr(6), _Sr(3), _Id),
+ (_Id, _0, _Sl(5), _Sl(2), _0, _0, _0, _0),
+ ( _0, _Id, _0, _M5, _Sl(2), _0, _0, _0),
+ ( _0, _0, _Id, _0, _0, _0, _0, _0),
+ ( _0, _0, _Sl(3), _Id, _0, _0, _0, _0),
+)
+
# NB: shift directions are reversed with respect to the specification
# for powers of M_R, since the specification reverses the byte order
# for those matrices.
@@ -99,7 +122,7 @@ MR = (
MR2 = (
( _0, _0, _Id, _0, _0, _0, _0, _0),
( _0, _0, _0, _Id, _Sr(3), _0, _0, _0),
- ( _0, _0, _0, _0, _Id, _Sr(3), _M3, _0),
+ ( _0, _0, _0, _0, _Id, _Sr(3), _M6, _0),
( _0, _0, _0, _0, _0, _Id, _Sl(3), _0),
( _0, _0, _0, _Sl(2), _0, _0, _Id, _Sl(3)),
( _0, _0, _0, _0, _Sl(2), _0, _0, _Id),
@@ -109,8 +132,8 @@ MR2 = (
MR3 = (
( _0, _0, _0, _Id, _Sr(3), _0, _0, _0),
- ( _0, _0, _0, _0, _Id, _Sr(3), _M3, _0),
- ( _0, _0, _0, _M4, _0, _Id, _M1, _M3),
+ ( _0, _0, _0, _0, _Id, _Sr(3), _M6, _0),
+ ( _0, _0, _0, _M7, _0, _Id, _M1, _M6),
( _0, _0, _0, _Sl(2), _0, _0, _Id, _Sl(3)),
(_Sl(3), _0, _0, _0, _Sl(2), _0, _0, _Id),
( _Id, _0, _0, _0, _0, _Sl(2), _Sl(5), _0),
@@ -138,9 +161,8 @@ ALPHAS = (
_multiplication(M),
_multiplication(M2),
_multiplication(M3),
+ _multiplication(M4),
_multiplication(MR, reverse=False),
_multiplication(MR2, reverse=False),
_multiplication(MR3, reverse=False)
)
-
-ALPHAS = ALPHAS[:3] + (lambda x: ALPHAS[1](ALPHAS[1](x)),) + ALPHAS[3:]