| 
 | 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_RISCV64_META_H  | 
 | 7 | +#define MLK_NATIVE_RISCV64_META_H  | 
 | 8 | + | 
 | 9 | +/* Identifier for this backend so that source and assembly files  | 
 | 10 | + * in the build can be appropriately guarded. */  | 
 | 11 | +#define MLK_ARITH_BACKEND_RISCV64  | 
 | 12 | + | 
 | 13 | +/* Set of primitives that this backend replaces */  | 
 | 14 | +#define MLK_USE_NATIVE_NTT  | 
 | 15 | +#define MLK_USE_NATIVE_INTT  | 
 | 16 | +#define MLK_USE_NATIVE_POLY_TOMONT  | 
 | 17 | +#define MLK_USE_NATIVE_REJ_UNIFORM  | 
 | 18 | +#define MLK_USE_NATIVE_POLY_REDUCE  | 
 | 19 | +#define MLK_USE_NATIVE_POLY_MULCACHE_COMPUTE  | 
 | 20 | +#define MLK_USE_NATIVE_POLYVEC_BASEMUL_ACC_MONTGOMERY_CACHED  | 
 | 21 | + | 
 | 22 | +#include "../../common.h"  | 
 | 23 | + | 
 | 24 | +#if !defined(__ASSEMBLER__)  | 
 | 25 | + | 
 | 26 | +#include "src/arith_native_riscv64.h"  | 
 | 27 | + | 
 | 28 | +static MLK_INLINE void mlk_ntt_native(int16_t data[MLKEM_N])  | 
 | 29 | +{  | 
 | 30 | +  mlk_rv64v_poly_ntt(data);  | 
 | 31 | +}  | 
 | 32 | + | 
 | 33 | +static MLK_INLINE void mlk_intt_native(int16_t data[MLKEM_N])  | 
 | 34 | +{  | 
 | 35 | +  mlk_rv64v_poly_invntt_tomont(data);  | 
 | 36 | +}  | 
 | 37 | + | 
 | 38 | +static MLK_INLINE void mlk_poly_tomont_native(int16_t data[MLKEM_N])  | 
 | 39 | +{  | 
 | 40 | +  mlk_rv64v_poly_tomont(data);  | 
 | 41 | +}  | 
 | 42 | + | 
 | 43 | +static MLK_INLINE int mlk_rej_uniform_native(int16_t *r, unsigned len,  | 
 | 44 | +                                             const uint8_t *buf,  | 
 | 45 | +                                             unsigned buflen)  | 
 | 46 | +{  | 
 | 47 | +  return mlk_rv64v_rej_uniform(r, len, buf, buflen);  | 
 | 48 | +}  | 
 | 49 | + | 
 | 50 | +static MLK_INLINE void mlk_poly_reduce_native(int16_t data[MLKEM_N])  | 
 | 51 | +{  | 
 | 52 | +  mlk_rv64v_poly_reduce(data);  | 
 | 53 | +}  | 
 | 54 | + | 
 | 55 | +static MLK_INLINE void mlk_poly_mulcache_compute_native(  | 
 | 56 | +    int16_t x[MLKEM_N / 2], const int16_t y[MLKEM_N])  | 
 | 57 | +{  | 
 | 58 | +  (void)x; /*	not using the cache atm  */  | 
 | 59 | +  (void)y;  | 
 | 60 | +}  | 
 | 61 | + | 
 | 62 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k2_native(  | 
 | 63 | +    int16_t r[MLKEM_N], const int16_t a[2 * MLKEM_N],  | 
 | 64 | +    const int16_t b[2 * MLKEM_N], const int16_t b_cache[2 * (MLKEM_N / 2)])  | 
 | 65 | +{  | 
 | 66 | +  (void)b_cache;  | 
 | 67 | +  mlk_rv64v_poly_basemul_mont_add_k2(r, a, b);  | 
 | 68 | +}  | 
 | 69 | + | 
 | 70 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k3_native(  | 
 | 71 | +    int16_t r[MLKEM_N], const int16_t a[3 * MLKEM_N],  | 
 | 72 | +    const int16_t b[3 * MLKEM_N], const int16_t b_cache[3 * (MLKEM_N / 2)])  | 
 | 73 | +{  | 
 | 74 | +  (void)b_cache;  | 
 | 75 | +  mlk_rv64v_poly_basemul_mont_add_k3(r, a, b);  | 
 | 76 | +}  | 
 | 77 | + | 
 | 78 | +static MLK_INLINE void mlk_polyvec_basemul_acc_montgomery_cached_k4_native(  | 
 | 79 | +    int16_t r[MLKEM_N], const int16_t a[4 * MLKEM_N],  | 
 | 80 | +    const int16_t b[4 * MLKEM_N], const int16_t b_cache[4 * (MLKEM_N / 2)])  | 
 | 81 | +{  | 
 | 82 | +  (void)b_cache;  | 
 | 83 | +  mlk_rv64v_poly_basemul_mont_add_k4(r, a, b);  | 
 | 84 | +}  | 
 | 85 | + | 
 | 86 | +#endif /* !__ASSEMBLER__ */  | 
 | 87 | + | 
 | 88 | +#endif /* !MLK_NATIVE_RISCV64_META_H */  | 
0 commit comments