Debian Codegraph @

crypto_encode/857x1723/avx/encode.c

raw
1 /* auto-generated; do not edit */
2 /* 20250302 djb: port to -Wc++-compat */
3
4 #include <immintrin.h>
5 #include "crypto_encode.h"
6 #include "crypto_int16.h"
7 #include "crypto_uint16.h"
8 #include "crypto_uint32.h"
9 #define int16 crypto_int16
10 #define uint16 crypto_uint16
11 #define uint32 crypto_uint32
12
13 void crypto_encode(unsigned char *out,const void *v)
14 {
15 const int16 *R0 = (const int16 *) v;
16 /* XXX: caller could overlap R with input */
17 uint16 R[429];
18 long i;
19 const uint16 *reading;
20 uint16 *writing;
21 uint16 r0,r1;
22 uint32 r2;
23
24 reading = (uint16 *) R0;
25 writing = R;
26 i = 54;
27 while (i > 0) {
28 __m256i x,y;
29 --i;
30 if (!i) {
31 reading -= 8;
32 writing -= 4;
33 out -= 4;
34 }
35 x = _mm256_loadu_si256((__m256i *) reading);
36 x = _mm256_add_epi16(x,_mm256_set1_epi16(2583));
37 x &= _mm256_set1_epi16(16383);
38 x = _mm256_mulhi_epi16(x,_mm256_set1_epi16(21846));
39 y = x & _mm256_set1_epi32(65535);
40 x = _mm256_srli_epi32(x,16);
41 x = _mm256_mullo_epi32(x,_mm256_set1_epi32(1723));
42 x = _mm256_add_epi32(y,x);
43 x = _mm256_shuffle_epi8(x,_mm256_set_epi8(
44 12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1,
45 12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1
46 ));
47 x = _mm256_permute4x64_epi64(x,0xd8);
48 _mm_storeu_si128((__m128i *) writing,_mm256_extractf128_si256(x,0));
49 *((uint32 *) (out+0)) = _mm256_extract_epi32(x,4);
50 *((uint32 *) (out+4)) = _mm256_extract_epi32(x,6);
51 reading += 16;
52 writing += 8;
53 out += 8;
54 }
55 R[428] = (((R0[856]+2583)&16383)*10923)>>15;
56
57 reading = (uint16 *) R;
58 writing = R;
59 i = 14;
60 while (i > 0) {
61 __m256i x,x2,y,y2;
62 --i;
63 if (!i) {
64 reading -= 20;
65 writing -= 10;
66 out -= 20;
67 }
68 x = _mm256_loadu_si256((__m256i *) (reading+0));
69 x2 = _mm256_loadu_si256((__m256i *) (reading+16));
70 y = x & _mm256_set1_epi32(65535);
71 y2 = x2 & _mm256_set1_epi32(65535);
72 x = _mm256_srli_epi32(x,16);
73 x2 = _mm256_srli_epi32(x2,16);
74 x = _mm256_mullo_epi32(x,_mm256_set1_epi32(11597));
75 x2 = _mm256_mullo_epi32(x2,_mm256_set1_epi32(11597));
76 x = _mm256_add_epi32(y,x);
77 x2 = _mm256_add_epi32(y2,x2);
78 x = _mm256_shuffle_epi8(x,_mm256_set_epi8(
79 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
80 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
81 ));
82 x2 = _mm256_shuffle_epi8(x2,_mm256_set_epi8(
83 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
84 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
85 ));
86 x = _mm256_permute4x64_epi64(x,0xd8);
87 x2 = _mm256_permute4x64_epi64(x2,0xd8);
88 _mm256_storeu_si256((__m256i *) writing,_mm256_permute2f128_si256(x,x2,0x31));
89 _mm256_storeu_si256((__m256i *) out,_mm256_permute2f128_si256(x,x2,0x20));
90 reading += 32;
91 writing += 16;
92 out += 32;
93 }
94 R[214] = R[428];
95
96 reading = (uint16 *) R;
97 writing = R;
98 i = 7;
99 while (i > 0) {
100 __m256i x,x2,y,y2;
101 --i;
102 if (!i) {
103 reading -= 10;
104 writing -= 5;
105 out -= 10;
106 }
107 x = _mm256_loadu_si256((__m256i *) (reading+0));
108 x2 = _mm256_loadu_si256((__m256i *) (reading+16));
109 y = x & _mm256_set1_epi32(65535);
110 y2 = x2 & _mm256_set1_epi32(65535);
111 x = _mm256_srli_epi32(x,16);
112 x2 = _mm256_srli_epi32(x2,16);
113 x = _mm256_mullo_epi32(x,_mm256_set1_epi32(2053));
114 x2 = _mm256_mullo_epi32(x2,_mm256_set1_epi32(2053));
115 x = _mm256_add_epi32(y,x);
116 x2 = _mm256_add_epi32(y2,x2);
117 x = _mm256_shuffle_epi8(x,_mm256_set_epi8(
118 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
119 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
120 ));
121 x2 = _mm256_shuffle_epi8(x2,_mm256_set_epi8(
122 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
123 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
124 ));
125 x = _mm256_permute4x64_epi64(x,0xd8);
126 x2 = _mm256_permute4x64_epi64(x2,0xd8);
127 _mm256_storeu_si256((__m256i *) writing,_mm256_permute2f128_si256(x,x2,0x31));
128 _mm256_storeu_si256((__m256i *) out,_mm256_permute2f128_si256(x,x2,0x20));
129 reading += 32;
130 writing += 16;
131 out += 32;
132 }
133 R[107] = R[214];
134
135 for (i = 0;i < 53;++i) {
136 r0 = R[2*i];
137 r1 = R[2*i+1];
138 r2 = r0+r1*(uint32)65;
139 R[i] = r2;
140 }
141 r0 = R[106];
142 r1 = R[107];
143 r2 = r0+r1*(uint32)65;
144 *out++ = r2; r2 >>= 8;
145 R[53] = r2;
146
147 reading = (uint16 *) R;
148 writing = R;
149 i = 2;
150 while (i > 0) {
151 __m256i x,x2,y,y2;
152 --i;
153 if (!i) {
154 reading -= 12;
155 writing -= 6;
156 out -= 12;
157 }
158 x = _mm256_loadu_si256((__m256i *) (reading+0));
159 x2 = _mm256_loadu_si256((__m256i *) (reading+16));
160 y = x & _mm256_set1_epi32(65535);
161 y2 = x2 & _mm256_set1_epi32(65535);
162 x = _mm256_srli_epi32(x,16);
163 x2 = _mm256_srli_epi32(x2,16);
164 x = _mm256_mullo_epi32(x,_mm256_set1_epi32(4225));
165 x2 = _mm256_mullo_epi32(x2,_mm256_set1_epi32(4225));
166 x = _mm256_add_epi32(y,x);
167 x2 = _mm256_add_epi32(y2,x2);
168 x = _mm256_shuffle_epi8(x,_mm256_set_epi8(
169 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
170 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
171 ));
172 x2 = _mm256_shuffle_epi8(x2,_mm256_set_epi8(
173 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0,
174 15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0
175 ));
176 x = _mm256_permute4x64_epi64(x,0xd8);
177 x2 = _mm256_permute4x64_epi64(x2,0xd8);
178 _mm256_storeu_si256((__m256i *) writing,_mm256_permute2f128_si256(x,x2,0x31));
179 _mm256_storeu_si256((__m256i *) out,_mm256_permute2f128_si256(x,x2,0x20));
180 reading += 32;
181 writing += 16;
182 out += 32;
183 }
184 r0 = R[52];
185 r1 = R[53];
186 r2 = r0+r1*(uint32)4225;
187 *out++ = r2; r2 >>= 8;
188 R[26] = r2;
189
190 reading = (uint16 *) R;
191 writing = R;
192 i = 2;
193 while (i > 0) {
194 __m256i x,y;
195 --i;
196 if (!i) {
197 reading -= 6;
198 writing -= 3;
199 out -= 3;
200 }
201 x = _mm256_loadu_si256((__m256i *) reading);
202 y = x & _mm256_set1_epi32(65535);
203 x = _mm256_srli_epi32(x,16);
204 x = _mm256_mullo_epi32(x,_mm256_set1_epi32(273));
205 x = _mm256_add_epi32(y,x);
206 x = _mm256_shuffle_epi8(x,_mm256_set_epi8(
207 12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1,
208 12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1
209 ));
210 x = _mm256_permute4x64_epi64(x,0xd8);
211 _mm_storeu_si128((__m128i *) writing,_mm256_extractf128_si256(x,0));
212 *((uint32 *) (out+0)) = _mm256_extract_epi32(x,4);
213 *((uint32 *) (out+4)) = _mm256_extract_epi32(x,6);
214 reading += 16;
215 writing += 8;
216 out += 8;
217 }
218 R[13] = R[26];
219
220 for (i = 0;i < 7;++i) {
221 r0 = R[2*i];
222 r1 = R[2*i+1];
223 r2 = r0+r1*(uint32)292;
224 *out++ = r2; r2 >>= 8;
225 R[i] = r2;
226 }
227
228 for (i = 0;i < 3;++i) {
229 r0 = R[2*i];
230 r1 = R[2*i+1];
231 r2 = r0+r1*(uint32)334;
232 *out++ = r2; r2 >>= 8;
233 R[i] = r2;
234 }
235 R[3] = R[6];
236
237 for (i = 0;i < 2;++i) {
238 r0 = R[2*i];
239 r1 = R[2*i+1];
240 r2 = r0+r1*(uint32)436;
241 *out++ = r2; r2 >>= 8;
242 R[i] = r2;
243 }
244
245 r0 = R[0];
246 r1 = R[1];
247 r2 = r0+r1*(uint32)743;
248 *out++ = r2; r2 >>= 8;
249 *out++ = r2; r2 >>= 8;
250 R[0] = r2;
251
252 r0 = R[0];
253 *out++ = r0; r0 >>= 8;
254 }