Debian Codegraph @

crypto_decode/953x3/avx/decode.c

raw
1 // 20250302 djb: port to -Wc++-compat
2 #include <immintrin.h>
3 #include "crypto_decode.h"
4 #include "crypto_uint8.h"
5 #define uint8 crypto_uint8
6
7 #define p 953
8 #define loops 8
9 #define overshoot 18
10
11 void crypto_decode(void *v,const unsigned char *s)
12 {
13 uint8 *f = (uint8 *) v;
14 int loop;
15 uint8 *nextf = f+128-4*overshoot;
16 const unsigned char *nexts = s+32-overshoot;
17
18 for (loop = loops;loop > 0;--loop) {
19 __m256i s0 = _mm256_loadu_si256((const __m256i *) s);
20 s = nexts;
21 nexts += 32;
22
23 __m256i s1 = _mm256_srli_epi16(s0&_mm256_set1_epi8(-16),4);
24 s0 &= _mm256_set1_epi8(15);
25
26 __m256i a0 = _mm256_unpacklo_epi8(s0,s1);
27 /* 0 0>>4 1 1>>4 2 2>>4 3 3>>4 4 4>>4 5 5>>4 6 6>>4 7 7>>4 */
28 /* 16 16>>4 ... */
29 __m256i a1 = _mm256_unpackhi_epi8(s0,s1);
30 /* 8 8>>4 9 9>>4 10 10>>4 ... */
31 /* 24 24>>4 ... */
32
33 __m256i a2 = _mm256_srli_epi16(a0&_mm256_set1_epi8(12),2);
34 __m256i a3 = _mm256_srli_epi16(a1&_mm256_set1_epi8(12),2);
35 a0 &= _mm256_set1_epi8(3);
36 a1 &= _mm256_set1_epi8(3);
37
38 __m256i b0 = _mm256_unpacklo_epi8(a0,a2);
39 /* 0 0>>2 0>>4 0>>6 1 1>>2 1>>4 1>>6 */
40 /* 2 2>>2 2>>4 2>>6 3 3>>2 3>>4 3>.6 */
41 /* 16 16>>2 16>>4 16>>6 ... */
42 __m256i b2 = _mm256_unpackhi_epi8(a0,a2);
43 /* 4 4>>2 ... */
44 __m256i b1 = _mm256_unpacklo_epi8(a1,a3);
45 /* 8 8>>2 ... */
46 __m256i b3 = _mm256_unpackhi_epi8(a1,a3);
47 /* 12 12>>2 ... */
48
49 __m256i f0 = _mm256_permute2x128_si256(b0,b2,0x20);
50 __m256i f2 = _mm256_permute2x128_si256(b0,b2,0x31);
51 __m256i f1 = _mm256_permute2x128_si256(b1,b3,0x20);
52 __m256i f3 = _mm256_permute2x128_si256(b1,b3,0x31);
53
54 f0 = _mm256_add_epi8(f0,_mm256_set1_epi8(-1));
55 f1 = _mm256_add_epi8(f1,_mm256_set1_epi8(-1));
56 f2 = _mm256_add_epi8(f2,_mm256_set1_epi8(-1));
57 f3 = _mm256_add_epi8(f3,_mm256_set1_epi8(-1));
58
59 _mm256_storeu_si256((__m256i *) (f+0),f0);
60 _mm256_storeu_si256((__m256i *) (f+32),f1);
61 _mm256_storeu_si256((__m256i *) (f+64),f2);
62 _mm256_storeu_si256((__m256i *) (f+96),f3);
63 f = nextf;
64 nextf += 128;
65 }
66
67 *f = ((uint8)(*s&3))-1;
68 }