summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 16:09:32 +0200
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 17:11:13 +0200
commit2a05449541c783716437403c44b416eb35b38d96 (patch)
tree90860967ff7a3c572c779fa8b86ac300e800107f
parent53229fa55e46f4d474cd38f31185aa8dcb83c701 (diff)
downloadlilliput-ae-implem-2a05449541c783716437403c44b416eb35b38d96.tar.xz
Réécriture de M³ en Python
-rw-r--r--src/add_python/lilliput/multiplications.py67
1 files changed, 15 insertions, 52 deletions
diff --git a/src/add_python/lilliput/multiplications.py b/src/add_python/lilliput/multiplications.py
index 3b50987..c5abdfc 100644
--- a/src/add_python/lilliput/multiplications.py
+++ b/src/add_python/lilliput/multiplications.py
@@ -38,6 +38,9 @@ def _0(xi):
def _M1(xi):
return (xi<<3 ^ xi>>3) & 0xff
+def _M2(xi):
+ return (xi<<6 ^ (xi&0b11111000) ^ xi>>6) & 0xff
+
M = (
( _0, _Id, _0, _0, _0, _0, _0, _0),
@@ -61,6 +64,17 @@ M2 = (
( _0, _Id, _0, _0, _0, _0, _0, _0),
)
+M3 = (
+ ( _0, _0, _Sl(3), _Id, _0, _0, _0, _0),
+ ( _0, _0, _Sl(6), _M1, _Id, _0, _0, _0),
+ ( _0, _0, _0, _M2, _M1, _Id, _0, _0),
+ ( _0, _Sl(2), _0, _0, _Sr(6), _Sr(3), _Id, _0),
+ ( _0, _0, _Sl(2), _0, _0, _0, _0, _Id),
+ (_Id, _0, _Sl(5), _Sl(2), _0, _0, _0, _0),
+ ( _0, _Id, _0, _0, _0, _0, _0, _0),
+ ( _0, _0, _Id, _0, _0, _0, _0, _0),
+)
+
def _multiplication(m):
def _multiply(x):
@@ -72,57 +86,6 @@ def _multiplication(m):
return _multiply
-def _multiply_M3(lane):
- multiplied_lane = [lane[(byte-3) % 8] for byte in range(0, 8)]
-
- multiplied_lane[2] ^= ((lane[4] << 2) & 0xff) ^ ((lane[5] << 5) & 0xff)
- multiplied_lane[3] ^= ((lane[5] << 2) & 0xff)
- multiplied_lane[4] ^= ((lane[2] >> 3) & 0xff) ^ ((lane[3] >> 6) & 0xff) ^ ((lane[6] << 2) & 0xff)
- multiplied_lane[6] ^= ((lane[5] << 6) & 0xff)
- multiplied_lane[7] ^= ((lane[5] << 3) & 0xff)
-
- # binary matrix M1
- multi_mat_l3_m1 = 0
- l3 = lane[3]
- multi_mat_l3_m1 ^= ((l3 & 0x8) >> 3)
- multi_mat_l3_m1 ^= ((l3 & 0x10) >> 3)
- multi_mat_l3_m1 ^= ((l3 & 0x20) >> 3)
- multi_mat_l3_m1 ^= ((l3 & 0x40) >> 3) ^ ((l3 & 0x1) << 3)
- multi_mat_l3_m1 ^= ((l3 & 0x80) >> 3) ^ ((l3 & 0x2) << 3)
- multi_mat_l3_m1 ^= ((l3 & 0x04) << 3)
- multi_mat_l3_m1 ^= ((l3 & 0x08) << 3)
- multi_mat_l3_m1 ^= ((l3 & 0x10) << 3)
-
- # binary matrix M1
- multi_mat_l4_m1 = 0
- l4 = lane[4]
- multi_mat_l4_m1 ^= ((l4 & 0x8) >> 3)
- multi_mat_l4_m1 ^= ((l4 & 0x10) >> 3)
- multi_mat_l4_m1 ^= ((l4 & 0x20) >> 3)
- multi_mat_l4_m1 ^= ((l4 & 0x40) >> 3) ^ ((l4 & 0x1) << 3)
- multi_mat_l4_m1 ^= ((l4 & 0x80) >> 3) ^ ((l4 & 0x2) << 3)
- multi_mat_l4_m1 ^= ((l4 & 0x04) << 3)
- multi_mat_l4_m1 ^= ((l4 & 0x08) << 3)
- multi_mat_l4_m1 ^= ((l4 & 0x10) << 3)
-
- # binary matrix M2
- multi_mat_l4_m2 = 0
- l4 = lane[4]
- multi_mat_l4_m2 ^= ((l4 & 0x40) >> 6)
- multi_mat_l4_m2 ^= ((l4 & 0x80) >> 6)
- multi_mat_l4_m2 ^= (l4 & 0x08)
- multi_mat_l4_m2 ^= (l4 & 0x10)
- multi_mat_l4_m2 ^= (l4 & 0x20)
- multi_mat_l4_m2 ^= (l4 & 0x40) ^ ((l4 & 0x1) << 6)
- multi_mat_l4_m2 ^= (l4 & 0x80) ^ ((l4 & 0x2) << 6)
-
-
- multiplied_lane[5] ^= multi_mat_l3_m1 ^ multi_mat_l4_m2
- multiplied_lane[6] ^= multi_mat_l4_m1
-
- return multiplied_lane
-
-
def _multiply_MR(lane):
multiplied_lane = [lane[(byte+1) % 8] for byte in range(0, 8)]
@@ -217,7 +180,7 @@ ALPHAS = (
list, # Identity.
_multiplication(M),
_multiplication(M2),
- _multiply_M3,
+ _multiplication(M3),
_multiply_MR,
_multiply_MR2,
_multiply_MR3