diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-07-03 14:22:22 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-07-04 13:43:12 +0200 |
| commit | ba601f28abb6b6080d024be4390e883e592cf40f (patch) | |
| tree | b9df48c90ad60e1c0568d676db72bd99634a93a8 /src/add_python/lilliput/multiplications.py | |
| parent | d8ed6474dc536812eff92e13be134f10ace6086e (diff) | |
| download | lilliput-ae-implem-ba601f28abb6b6080d024be4390e883e592cf40f.tar.xz | |
Implémentation de M⁴ à l'aide de sa matrice
Diffstat (limited to 'src/add_python/lilliput/multiplications.py')
| -rw-r--r-- | src/add_python/lilliput/multiplications.py | 42 |
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:] |
