| 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[327]; |
| 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 = 41; |
| 27 |
while (i > 0) { |
| 28 |
__m256i x,y; |
| 29 |
--i; |
| 30 |
if (!i) { |
| 31 |
reading -= 4; |
| 32 |
writing -= 2; |
| 33 |
out -= 2; |
| 34 |
} |
| 35 |
x = _mm256_loadu_si256((__m256i *) reading); |
| 36 |
x = _mm256_mulhrs_epi16(x,_mm256_set1_epi16(10923)); |
| 37 |
x = _mm256_add_epi16(x,_mm256_add_epi16(x,x)); |
| 38 |
x = _mm256_add_epi16(x,_mm256_set1_epi16(2310)); |
| 39 |
x &= _mm256_set1_epi16(16383); |
| 40 |
x = _mm256_mulhi_epi16(x,_mm256_set1_epi16(21846)); |
| 41 |
y = x & _mm256_set1_epi32(65535); |
| 42 |
x = _mm256_srli_epi32(x,16); |
| 43 |
x = _mm256_mullo_epi32(x,_mm256_set1_epi32(1541)); |
| 44 |
x = _mm256_add_epi32(y,x); |
| 45 |
x = _mm256_shuffle_epi8(x,_mm256_set_epi8( |
| 46 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1, |
| 47 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1 |
| 48 |
)); |
| 49 |
x = _mm256_permute4x64_epi64(x,0xd8); |
| 50 |
_mm_storeu_si128((__m128i *) writing,_mm256_extractf128_si256(x,0)); |
| 51 |
*((uint32 *) (out+0)) = _mm256_extract_epi32(x,4); |
| 52 |
*((uint32 *) (out+4)) = _mm256_extract_epi32(x,6); |
| 53 |
reading += 16; |
| 54 |
writing += 8; |
| 55 |
out += 8; |
| 56 |
} |
| 57 |
R[326] = (((3*((10923*R0[652]+16384)>>15)+2310)&16383)*10923)>>15; |
| 58 |
|
| 59 |
reading = (uint16 *) R; |
| 60 |
writing = R; |
| 61 |
i = 11; |
| 62 |
while (i > 0) { |
| 63 |
__m256i x,x2,y,y2; |
| 64 |
--i; |
| 65 |
if (!i) { |
| 66 |
reading -= 26; |
| 67 |
writing -= 13; |
| 68 |
out -= 26; |
| 69 |
} |
| 70 |
x = _mm256_loadu_si256((__m256i *) (reading+0)); |
| 71 |
x2 = _mm256_loadu_si256((__m256i *) (reading+16)); |
| 72 |
y = x & _mm256_set1_epi32(65535); |
| 73 |
y2 = x2 & _mm256_set1_epi32(65535); |
| 74 |
x = _mm256_srli_epi32(x,16); |
| 75 |
x2 = _mm256_srli_epi32(x2,16); |
| 76 |
x = _mm256_mullo_epi32(x,_mm256_set1_epi32(9277)); |
| 77 |
x2 = _mm256_mullo_epi32(x2,_mm256_set1_epi32(9277)); |
| 78 |
x = _mm256_add_epi32(y,x); |
| 79 |
x2 = _mm256_add_epi32(y2,x2); |
| 80 |
x = _mm256_shuffle_epi8(x,_mm256_set_epi8( |
| 81 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0, |
| 82 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0 |
| 83 |
)); |
| 84 |
x2 = _mm256_shuffle_epi8(x2,_mm256_set_epi8( |
| 85 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0, |
| 86 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0 |
| 87 |
)); |
| 88 |
x = _mm256_permute4x64_epi64(x,0xd8); |
| 89 |
x2 = _mm256_permute4x64_epi64(x2,0xd8); |
| 90 |
_mm256_storeu_si256((__m256i *) writing,_mm256_permute2f128_si256(x,x2,0x31)); |
| 91 |
_mm256_storeu_si256((__m256i *) out,_mm256_permute2f128_si256(x,x2,0x20)); |
| 92 |
reading += 32; |
| 93 |
writing += 16; |
| 94 |
out += 32; |
| 95 |
} |
| 96 |
R[163] = R[326]; |
| 97 |
|
| 98 |
reading = (uint16 *) R; |
| 99 |
writing = R; |
| 100 |
i = 11; |
| 101 |
while (i > 0) { |
| 102 |
__m256i x,y; |
| 103 |
--i; |
| 104 |
if (!i) { |
| 105 |
reading -= 12; |
| 106 |
writing -= 6; |
| 107 |
out -= 6; |
| 108 |
} |
| 109 |
x = _mm256_loadu_si256((__m256i *) reading); |
| 110 |
y = x & _mm256_set1_epi32(65535); |
| 111 |
x = _mm256_srli_epi32(x,16); |
| 112 |
x = _mm256_mullo_epi32(x,_mm256_set1_epi32(1314)); |
| 113 |
x = _mm256_add_epi32(y,x); |
| 114 |
x = _mm256_shuffle_epi8(x,_mm256_set_epi8( |
| 115 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1, |
| 116 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1 |
| 117 |
)); |
| 118 |
x = _mm256_permute4x64_epi64(x,0xd8); |
| 119 |
_mm_storeu_si128((__m128i *) writing,_mm256_extractf128_si256(x,0)); |
| 120 |
*((uint32 *) (out+0)) = _mm256_extract_epi32(x,4); |
| 121 |
*((uint32 *) (out+4)) = _mm256_extract_epi32(x,6); |
| 122 |
reading += 16; |
| 123 |
writing += 8; |
| 124 |
out += 8; |
| 125 |
} |
| 126 |
|
| 127 |
reading = (uint16 *) R; |
| 128 |
writing = R; |
| 129 |
i = 3; |
| 130 |
while (i > 0) { |
| 131 |
__m256i x,x2,y,y2; |
| 132 |
--i; |
| 133 |
if (!i) { |
| 134 |
reading -= 14; |
| 135 |
writing -= 7; |
| 136 |
out -= 14; |
| 137 |
} |
| 138 |
x = _mm256_loadu_si256((__m256i *) (reading+0)); |
| 139 |
x2 = _mm256_loadu_si256((__m256i *) (reading+16)); |
| 140 |
y = x & _mm256_set1_epi32(65535); |
| 141 |
y2 = x2 & _mm256_set1_epi32(65535); |
| 142 |
x = _mm256_srli_epi32(x,16); |
| 143 |
x2 = _mm256_srli_epi32(x2,16); |
| 144 |
x = _mm256_mullo_epi32(x,_mm256_set1_epi32(6745)); |
| 145 |
x2 = _mm256_mullo_epi32(x2,_mm256_set1_epi32(6745)); |
| 146 |
x = _mm256_add_epi32(y,x); |
| 147 |
x2 = _mm256_add_epi32(y2,x2); |
| 148 |
x = _mm256_shuffle_epi8(x,_mm256_set_epi8( |
| 149 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0, |
| 150 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0 |
| 151 |
)); |
| 152 |
x2 = _mm256_shuffle_epi8(x2,_mm256_set_epi8( |
| 153 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0, |
| 154 |
15,14,11,10,7,6,3,2,13,12,9,8,5,4,1,0 |
| 155 |
)); |
| 156 |
x = _mm256_permute4x64_epi64(x,0xd8); |
| 157 |
x2 = _mm256_permute4x64_epi64(x2,0xd8); |
| 158 |
_mm256_storeu_si256((__m256i *) writing,_mm256_permute2f128_si256(x,x2,0x31)); |
| 159 |
_mm256_storeu_si256((__m256i *) out,_mm256_permute2f128_si256(x,x2,0x20)); |
| 160 |
reading += 32; |
| 161 |
writing += 16; |
| 162 |
out += 32; |
| 163 |
} |
| 164 |
|
| 165 |
reading = (uint16 *) R; |
| 166 |
writing = R; |
| 167 |
i = 3; |
| 168 |
while (i > 0) { |
| 169 |
__m256i x,y; |
| 170 |
--i; |
| 171 |
if (!i) { |
| 172 |
reading -= 8; |
| 173 |
writing -= 4; |
| 174 |
out -= 4; |
| 175 |
} |
| 176 |
x = _mm256_loadu_si256((__m256i *) reading); |
| 177 |
y = x & _mm256_set1_epi32(65535); |
| 178 |
x = _mm256_srli_epi32(x,16); |
| 179 |
x = _mm256_mullo_epi32(x,_mm256_set1_epi32(695)); |
| 180 |
x = _mm256_add_epi32(y,x); |
| 181 |
x = _mm256_shuffle_epi8(x,_mm256_set_epi8( |
| 182 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1, |
| 183 |
12,8,4,0,12,8,4,0,14,13,10,9,6,5,2,1 |
| 184 |
)); |
| 185 |
x = _mm256_permute4x64_epi64(x,0xd8); |
| 186 |
_mm_storeu_si128((__m128i *) writing,_mm256_extractf128_si256(x,0)); |
| 187 |
*((uint32 *) (out+0)) = _mm256_extract_epi32(x,4); |
| 188 |
*((uint32 *) (out+4)) = _mm256_extract_epi32(x,6); |
| 189 |
reading += 16; |
| 190 |
writing += 8; |
| 191 |
out += 8; |
| 192 |
} |
| 193 |
R[20] = R[40]; |
| 194 |
|
| 195 |
for (i = 0;i < 10;++i) { |
| 196 |
r0 = R[2*i]; |
| 197 |
r1 = R[2*i+1]; |
| 198 |
r2 = r0+r1*(uint32)1887; |
| 199 |
*out++ = r2; r2 >>= 8; |
| 200 |
R[i] = r2; |
| 201 |
} |
| 202 |
R[10] = R[20]; |
| 203 |
|
| 204 |
for (i = 0;i < 5;++i) { |
| 205 |
r0 = R[2*i]; |
| 206 |
r1 = R[2*i+1]; |
| 207 |
r2 = r0+r1*(uint32)13910; |
| 208 |
*out++ = r2; r2 >>= 8; |
| 209 |
*out++ = r2; r2 >>= 8; |
| 210 |
R[i] = r2; |
| 211 |
} |
| 212 |
R[5] = R[10]; |
| 213 |
|
| 214 |
for (i = 0;i < 2;++i) { |
| 215 |
r0 = R[2*i]; |
| 216 |
r1 = R[2*i+1]; |
| 217 |
r2 = r0+r1*(uint32)2953; |
| 218 |
*out++ = r2; r2 >>= 8; |
| 219 |
*out++ = r2; r2 >>= 8; |
| 220 |
R[i] = r2; |
| 221 |
} |
| 222 |
r0 = R[4]; |
| 223 |
r1 = R[5]; |
| 224 |
r2 = r0+r1*(uint32)2953; |
| 225 |
*out++ = r2; r2 >>= 8; |
| 226 |
R[2] = r2; |
| 227 |
|
| 228 |
r0 = R[0]; |
| 229 |
r1 = R[1]; |
| 230 |
r2 = r0+r1*(uint32)134; |
| 231 |
*out++ = r2; r2 >>= 8; |
| 232 |
R[0] = r2; |
| 233 |
R[1] = R[2]; |
| 234 |
|
| 235 |
r0 = R[0]; |
| 236 |
r1 = R[1]; |
| 237 |
r2 = r0+r1*(uint32)71; |
| 238 |
*out++ = r2; r2 >>= 8; |
| 239 |
R[0] = r2; |
| 240 |
|
| 241 |
r0 = R[0]; |
| 242 |
*out++ = r0; r0 >>= 8; |
| 243 |
*out++ = r0; r0 >>= 8; |
| 244 |
} |