|
| 1 | +/* |
| 2 | + * Copyright (c) The mldsa-native project authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | + */ |
| 5 | + |
| 6 | +/* |
| 7 | + * This file is derived from the public domain |
| 8 | + * AVX2 Dilithium implementation @[REF_AVX2]. |
| 9 | + */ |
| 10 | + |
| 11 | +#include "../../../common.h" |
| 12 | + |
| 13 | +#if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \ |
| 14 | + !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) |
| 15 | + |
| 16 | +#include <immintrin.h> |
| 17 | +#include "arith_native_x86_64.h" |
| 18 | +#include "consts.h" |
| 19 | + |
| 20 | +/************************************************* |
| 21 | + * Name: mld_poly_caddq_avx2 |
| 22 | + * |
| 23 | + * Description: For all coefficients of in/out polynomial add Q if |
| 24 | + * coefficient is negative. |
| 25 | + * |
| 26 | + * Arguments: - int32_t *r: pointer to input/output polynomial |
| 27 | + **************************************************/ |
| 28 | +void mld_poly_caddq_avx2(int32_t *r) |
| 29 | +{ |
| 30 | + unsigned int i; |
| 31 | + __m256i f, g; |
| 32 | + const __m256i q = _mm256_set1_epi32(MLDSA_Q); |
| 33 | + const __m256i zero = _mm256_setzero_si256(); |
| 34 | + __m256i *rr = (__m256i *)r; |
| 35 | + |
| 36 | + for (i = 0; i < MLDSA_N / 8; i++) |
| 37 | + { |
| 38 | + f = _mm256_load_si256(&rr[i]); |
| 39 | + g = _mm256_cmpgt_epi32(zero, f); |
| 40 | + g = _mm256_and_si256(g, q); |
| 41 | + f = _mm256_add_epi32(f, g); |
| 42 | + _mm256_store_si256(&rr[i], f); |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +#else /* MLD_ARITH_BACKEND_X86_64_DEFAULT && !MLD_CONFIG_MULTILEVEL_NO_SHARED \ |
| 47 | + */ |
| 48 | + |
| 49 | +MLD_EMPTY_CU(avx2_reduce) |
| 50 | + |
| 51 | +#endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ |
| 52 | + !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ |
0 commit comments