Debian Codegraph @

crypto_core/scale3sntrup1277/avx/core.c

raw
1 #include <immintrin.h>
2 #include "crypto_core.h"
3
4 #define p 1277
5 #define q 7879
6
7 #include "crypto_decode_1277xint16.h"
8 #define crypto_decode_pxint16 crypto_decode_1277xint16
9 #include "crypto_encode_1277xint16.h"
10 #define crypto_encode_pxint16 crypto_encode_1277xint16
11
12 #include "crypto_int16.h"
13 typedef crypto_int16 Fq;
14
15 /* out = 3*in in Rq */
16 void crypto_core(unsigned char *outbytes,const unsigned char *inbytes,const unsigned char *kbytes,const unsigned char *cbytes)
17 {
18 int i = p-16;
19
20 __m256i save = _mm256_loadu_si256((__m256i *) (inbytes+2*i));
21 /* in case outbytes = inbytes */
22
23 for (;;) {
24 do {
25 __m256i x = _mm256_loadu_si256((__m256i *) inbytes);
26 __m256i xneg;
27 x = _mm256_mullo_epi16(x,_mm256_set1_epi16(3));
28 x = _mm256_sub_epi16(x,_mm256_set1_epi16((q+1)/2));
29 xneg = _mm256_srai_epi16(x,15);
30 x = _mm256_add_epi16(x,_mm256_set1_epi16(q)&xneg);
31 xneg = _mm256_srai_epi16(x,15);
32 x = _mm256_add_epi16(x,_mm256_set1_epi16(q)&xneg);
33 x = _mm256_sub_epi16(x,_mm256_set1_epi16((q-1)/2));
34 _mm256_storeu_si256((__m256i *) outbytes,x);
35
36 inbytes += 32;
37 outbytes += 32;
38 i -= 16;
39 } while (i >= 0);
40 if (i <= -16) break;
41 inbytes += 2*i;
42 outbytes += 2*i;
43 _mm256_storeu_si256((__m256i *) outbytes,save);
44 }
45 }