|
| 1 | +/* |
| 2 | + * Copyright (c) The mldsa-native project authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | + */ |
| 5 | + |
| 6 | +/* References |
| 7 | + * ========== |
| 8 | + * |
| 9 | + * - [REF_AVX2] |
| 10 | + * CRYSTALS-Dilithium optimized AVX2 implementation |
| 11 | + * Bai, Ducas, Kiltz, Lepoint, Lyubashevsky, Schwabe, Seiler, Stehlé |
| 12 | + * https://github.com/pq-crystals/dilithium/tree/master/avx2 |
| 13 | + */ |
| 14 | + |
| 15 | +/* |
| 16 | + * This file is derived from the public domain |
| 17 | + * AVX2 Dilithium implementation @[REF_AVX2]. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "../../../common.h" |
| 21 | + |
| 22 | +#if defined(MLD_ARITH_BACKEND_X86_64_DEFAULT) && \ |
| 23 | + !defined(MLD_CONFIG_MULTILEVEL_NO_SHARED) |
| 24 | + |
| 25 | +#include <immintrin.h> |
| 26 | +#include <stdint.h> |
| 27 | +#include "arith_native_x86_64.h" |
| 28 | + |
| 29 | +uint32_t mld_poly_chknorm_avx2(const __m256i *a, int32_t B) |
| 30 | +{ |
| 31 | + unsigned int i; |
| 32 | + __m256i f, t; |
| 33 | + const __m256i bound = _mm256_set1_epi32(B - 1); |
| 34 | + |
| 35 | + t = _mm256_setzero_si256(); |
| 36 | + for (i = 0; i < MLDSA_N / 8; i++) |
| 37 | + { |
| 38 | + f = _mm256_load_si256(&a[i]); |
| 39 | + f = _mm256_abs_epi32(f); |
| 40 | + f = _mm256_cmpgt_epi32(f, bound); |
| 41 | + t = _mm256_or_si256(t, f); |
| 42 | + } |
| 43 | + |
| 44 | + return _mm256_testz_si256(t, t) - 1; |
| 45 | +} |
| 46 | + |
| 47 | +#else /* MLD_ARITH_BACKEND_X86_64_DEFAULT && !MLD_CONFIG_MULTILEVEL_NO_SHARED \ |
| 48 | + */ |
| 49 | + |
| 50 | +MLD_EMPTY_CU(avx2_poly_chknorm) |
| 51 | + |
| 52 | +#endif /* !(MLD_ARITH_BACKEND_X86_64_DEFAULT && \ |
| 53 | + !MLD_CONFIG_MULTILEVEL_NO_SHARED) */ |
0 commit comments