|
| 1 | +/* |
| 2 | + * Copyright (c) The mlkem-native project authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT |
| 4 | + */ |
| 5 | + |
| 6 | +#ifndef MLK_NATIVE_AARCH64_META_H |
| 7 | +#define MLK_NATIVE_AARCH64_META_H |
| 8 | + |
| 9 | +/* Set of primitives that this backend replaces */ |
| 10 | +#define MLK_USE_NATIVE_NTT |
| 11 | +#define MLK_USE_NATIVE_INTT |
| 12 | +#define MLK_USE_NATIVE_POLY_REDUCE |
| 13 | +#define MLK_USE_NATIVE_POLY_TOMONT |
| 14 | +#define MLK_USE_NATIVE_POLY_MULCACHE_COMPUTE |
| 15 | +#define MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED |
| 16 | +#define MLK_USE_NATIVE_POLY_TOBYTES |
| 17 | +#define MLK_USE_NATIVE_REJ_UNIFORM |
| 18 | + |
| 19 | +/* Identifier for this backend so that source and assembly files |
| 20 | + * in the build can be appropriately guarded. */ |
| 21 | +#define MLK_ARITH_BACKEND_AARCH64 |
| 22 | + |
| 23 | + |
| 24 | +#if !defined(__ASSEMBLER__) |
| 25 | +#include "src/arith_native_aarch64.h" |
| 26 | + |
| 27 | +static MLK_INLINE void mlk_ntt_native(int16_t data[MLKEM_N]) |
| 28 | +{ |
| 29 | + mlk_ntt_asm(data, mlk_aarch64_ntt_zetas_layer12345, |
| 30 | + mlk_aarch64_ntt_zetas_layer67); |
| 31 | +} |
| 32 | + |
| 33 | +static MLK_INLINE void mlk_intt_native(int16_t data[MLKEM_N]) |
| 34 | +{ |
| 35 | + mlk_intt_asm(data, mlk_aarch64_invntt_zetas_layer12345, |
| 36 | + mlk_aarch64_invntt_zetas_layer67); |
| 37 | +} |
| 38 | + |
| 39 | +static MLK_INLINE void mlk_poly_reduce_native(int16_t data[MLKEM_N]) |
| 40 | +{ |
| 41 | + mlk_poly_reduce_asm(data); |
| 42 | +} |
| 43 | + |
| 44 | +static MLK_INLINE void mlk_poly_tomont_native(int16_t data[MLKEM_N]) |
| 45 | +{ |
| 46 | + mlk_poly_tomont_asm(data); |
| 47 | +} |
| 48 | + |
| 49 | +static MLK_INLINE void mlk_poly_mulcache_compute_native( |
| 50 | + int16_t x[MLKEM_N / 2], const int16_t y[MLKEM_N]) |
| 51 | +{ |
| 52 | + mlk_poly_mulcache_compute_asm(x, y, mlk_aarch64_zetas_mulcache_native, |
| 53 | + mlk_aarch64_zetas_mulcache_twisted_native); |
| 54 | +} |
| 55 | + |
| 56 | +#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 2 |
| 57 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k2_native( |
| 58 | + int16_t r[MLKEM_N], const int16_t a[2 * MLKEM_N], |
| 59 | + const int16_t b[2 * MLKEM_N], const int16_t b_cache[2 * (MLKEM_N / 2)]) |
| 60 | +{ |
| 61 | + mlk_polyvec_basemul_acc_montgomery_cached_asm_k2(r, a, b, b_cache); |
| 62 | +} |
| 63 | +#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 2 */ |
| 64 | + |
| 65 | +#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 3 |
| 66 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k3_native( |
| 67 | + int16_t r[MLKEM_N], const int16_t a[3 * MLKEM_N], |
| 68 | + const int16_t b[3 * MLKEM_N], const int16_t b_cache[3 * (MLKEM_N / 2)]) |
| 69 | +{ |
| 70 | + mlk_polyvec_basemul_acc_montgomery_cached_asm_k3(r, a, b, b_cache); |
| 71 | +} |
| 72 | +#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 3 */ |
| 73 | + |
| 74 | +#if defined(MLK_CONFIG_MULTILEVEL_WITH_SHARED) || MLKEM_K == 4 |
| 75 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k4_native( |
| 76 | + int16_t r[MLKEM_N], const int16_t a[4 * MLKEM_N], |
| 77 | + const int16_t b[4 * MLKEM_N], const int16_t b_cache[4 * (MLKEM_N / 2)]) |
| 78 | +{ |
| 79 | + mlk_polyvec_basemul_acc_montgomery_cached_asm_k4(r, a, b, b_cache); |
| 80 | +} |
| 81 | +#endif /* MLK_CONFIG_MULTILEVEL_WITH_SHARED || MLKEM_K == 4 */ |
| 82 | + |
| 83 | +static MLK_INLINE void mlk_poly_tobytes_native(uint8_t r[MLKEM_POLYBYTES], |
| 84 | + const int16_t a[MLKEM_N]) |
| 85 | +{ |
| 86 | + mlk_poly_tobytes_asm(r, a); |
| 87 | +} |
| 88 | + |
| 89 | +static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len, |
| 90 | + const uint8_t *buf, |
| 91 | + unsigned buflen) |
| 92 | +{ |
| 93 | + if (len != MLKEM_N || buflen % 24 != 0) |
| 94 | + { |
| 95 | + return -1; |
| 96 | + } |
| 97 | + return (int)mlk_rej_uniform_asm(r, buf, buflen, mlk_rej_uniform_table); |
| 98 | +} |
| 99 | +#endif /* !__ASSEMBLER__ */ |
| 100 | + |
| 101 | +#endif /* !MLK_NATIVE_AARCH64_META_H */ |
0 commit comments