summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 17:28:22 +0200
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 17:28:22 +0200
commit596b860e0702632a123ad0bd505942634c6836b1 (patch)
tree68a346e6ae1bed98bfd575c3a9917e41f5377bc4 /src
parentca765aa586265fd0ab9c7baaee69f5c1dc9185ae (diff)
downloadlilliput-ae-implem-596b860e0702632a123ad0bd505942634c6836b1.tar.xz
Réécriture de M_R³ en Python
Diffstat (limited to 'src')
-rw-r--r--src/add_python/lilliput/multiplications.py72
1 files changed, 15 insertions, 57 deletions
diff --git a/src/add_python/lilliput/multiplications.py b/src/add_python/lilliput/multiplications.py
index edbdaf3..a5faa55 100644
--- a/src/add_python/lilliput/multiplications.py
+++ b/src/add_python/lilliput/multiplications.py
@@ -44,6 +44,9 @@ def _M2(xi):
def _M3(xi):
return xi & 0b00011111
+def _M4(xi):
+ return ((xi<<2) & 0xff) >> 3
+
M = (
( _0, _Id, _0, _0, _0, _0, _0, _0),
@@ -78,7 +81,6 @@ M3 = (
( _0, _0, _Id, _0, _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.
@@ -105,6 +107,17 @@ MR2 = (
( _0, _Id, _0, _0, _0, _0, _0, _0),
)
+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, _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),
+ ( _0, _Id, _0, _0, _0, _0, _0, _0),
+ ( _0, _0, _Id, _0, _0, _0, _0, _0),
+)
+
def _multiplication(m, reverse=True):
def ordered(l):
@@ -121,61 +134,6 @@ def _multiplication(m, reverse=True):
return _multiply
-def _multiply_MR3(lane):
- multiplied_lane = [lane[(byte+3) % 8] for byte in range(0, 8)]
-
- multiplied_lane[0] ^= ((lane[4] >> 3) & 0xff)
- multiplied_lane[1] ^= ((lane[5] >> 3) & 0xff)
- multiplied_lane[3] ^= ((lane[3] << 2) & 0xff) ^ ((lane[7] << 3) & 0xff)
- multiplied_lane[4] ^= ((lane[0] << 3) & 0xff) ^ ((lane[4] << 2) & 0xff)
- multiplied_lane[5] ^= ((lane[5] << 2) & 0xff) ^ ((lane[6] << 5) & 0xff)
-
- # binary matrix m3
- multi_mat_l6_m3 = 0
- l6 = lane[6]
- multi_mat_l6_m3 ^= (l6 & 0x1)
- multi_mat_l6_m3 ^= (l6 & 0x2)
- multi_mat_l6_m3 ^= (l6 & 0x4)
- multi_mat_l6_m3 ^= (l6 & 0x8)
- multi_mat_l6_m3 ^= (l6 & 0x10)
-
- # binary matrix m3
- multi_mat_l7_m3 = 0
- l7 = lane[7]
- multi_mat_l7_m3 ^= (l7 & 0x1)
- multi_mat_l7_m3 ^= (l7 & 0x2)
- multi_mat_l7_m3 ^= (l7 & 0x4)
- multi_mat_l7_m3 ^= (l7 & 0x8)
- multi_mat_l7_m3 ^= (l7 & 0x10)
-
- # binary matrix m4
- multi_mat_l3_m4 = 0
- l3 = lane[3]
- multi_mat_l3_m4 ^= ((l3 & 0x2) >> 1)
- multi_mat_l3_m4 ^= ((l3 & 0x4) >> 1)
- multi_mat_l3_m4 ^= ((l3 & 0x8) >> 1)
- multi_mat_l3_m4 ^= ((l3 & 0x10) >> 1)
- multi_mat_l3_m4 ^= ((l3 & 0x20) >> 1)
-
- # binary matrix m1 for MR
- multi_mat_l6_m1 = 0
- l6 = lane[6]
- multi_mat_l6_m1 ^= ((l6 & 0x8) >> 3)
- multi_mat_l6_m1 ^= ((l6 & 0x10) >> 3)
- multi_mat_l6_m1 ^= ((l6 & 0x20) >> 3)
- multi_mat_l6_m1 ^= ((l6 & 0x40) >> 3) ^ ((l6 & 0x1) << 3)
- multi_mat_l6_m1 ^= ((l6 & 0x80) >> 3) ^ ((l6 & 0x2) << 3)
- multi_mat_l6_m1 ^= ((l6 & 0x4) << 3)
- multi_mat_l6_m1 ^= ((l6 & 0x8) << 3)
- multi_mat_l6_m1 ^= ((l6 & 0x10) << 3)
-
-
- multiplied_lane[1] ^= multi_mat_l6_m3
- multiplied_lane[2] ^= multi_mat_l3_m4 ^ multi_mat_l6_m1 ^ multi_mat_l7_m3
-
- return multiplied_lane
-
-
ALPHAS = (
list, # Identity.
_multiplication(M),
@@ -183,5 +141,5 @@ ALPHAS = (
_multiplication(M3),
_multiplication(MR, reverse=False),
_multiplication(MR2, reverse=False),
- _multiply_MR3
+ _multiplication(MR3, reverse=False)
)