arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/spqlios/coeffs/coeffs_arithmetic.h
poulpy-backend/src/cpu_spqlios/spqlios-arithmetic/spqlios/coeffs/coeffs_arithmetic.hRaw
 1#ifndef SPQLIOS_COEFFS_ARITHMETIC_H
 2#define SPQLIOS_COEFFS_ARITHMETIC_H
 3
 4#include "../commons.h"
 5
 6/** res = a + b */
 7EXPORT void znx_add_i64_ref(uint64_t nn, int64_t* res, const int64_t* a, const int64_t* b);
 8EXPORT void znx_add_i64_avx(uint64_t nn, int64_t* res, const int64_t* a, const int64_t* b);
 9/** res = a - b */
10EXPORT void znx_sub_i64_ref(uint64_t nn, int64_t* res, const int64_t* a, const int64_t* b);
11EXPORT void znx_sub_i64_avx(uint64_t nn, int64_t* res, const int64_t* a, const int64_t* b);
12/** res = -a */
13EXPORT void znx_negate_i64_ref(uint64_t nn, int64_t* res, const int64_t* a);
14EXPORT void znx_negate_i64_avx(uint64_t nn, int64_t* res, const int64_t* a);
15/** res = a */
16EXPORT void znx_copy_i64_ref(uint64_t nn, int64_t* res, const int64_t* a);
17/** res = 0 */
18EXPORT void znx_zero_i64_ref(uint64_t nn, int64_t* res);
19
20/** res = a / m where m is a power of 2 */
21EXPORT void rnx_divide_by_m_ref(uint64_t nn, double m, double* res, const double* a);
22EXPORT void rnx_divide_by_m_avx(uint64_t nn, double m, double* res, const double* a);
23
24/**
25 * @param res = X^p *in mod X^nn +1
26 * @param nn the ring dimension
27 * @param p a power for the rotation -2nn <= p <= 2nn
28 * @param in is a rnx/znx vector of dimension nn
29 */
30EXPORT void rnx_rotate_f64(uint64_t nn, int64_t p, double* res, const double* in);
31EXPORT void znx_rotate_i64(uint64_t nn, int64_t p, int64_t* res, const int64_t* in);
32EXPORT void rnx_rotate_inplace_f64(uint64_t nn, int64_t p, double* res);
33EXPORT void znx_rotate_inplace_i64(uint64_t nn, int64_t p, int64_t* res);
34
35/**
36 * @brief res(X) = in(X^p)
37 * @param nn the ring dimension
38 * @param p is odd integer and must be between 0 < p < 2nn
39 * @param in is a rnx/znx vector of dimension nn
40 */
41EXPORT void rnx_automorphism_f64(uint64_t nn, int64_t p, double* res, const double* in);
42EXPORT void znx_automorphism_i64(uint64_t nn, int64_t p, int64_t* res, const int64_t* in);
43EXPORT void rnx_automorphism_inplace_f64(uint64_t nn, int64_t p, double* res);
44EXPORT void znx_automorphism_inplace_i64(uint64_t nn, int64_t p, int64_t* res);
45
46/**
47 * @brief res = (X^p-1).in
48 * @param nn the ring dimension
49 * @param p must be between -2nn <= p <= 2nn
50 * @param in is a rnx/znx vector of dimension nn
51 */
52EXPORT void rnx_mul_xp_minus_one_f64(uint64_t nn, int64_t p, double* res, const double* in);
53EXPORT void znx_mul_xp_minus_one_i64(uint64_t nn, int64_t p, int64_t* res, const int64_t* in);
54EXPORT void rnx_mul_xp_minus_one_inplace_f64(uint64_t nn, int64_t p, double* res);
55EXPORT void znx_mul_xp_minus_one_inplace_i64(uint64_t nn, int64_t p, int64_t* res);
56
57/**
58 * @brief      Normalize input plus carry mod-2^k. The following
59 *             equality holds @c {in + carry_in == out + carry_out . 2^k}.
60 *
61 *             @c in must be in [-2^62 .. 2^62]
62 *
63 *             @c out is in [ -2^(base_k-1), 2^(base_k-1) [.
64 *
65 *             @c carry_in and @carry_out have at most 64+1-k bits.
66 *
67 *             Null @c carry_in or @c carry_out are ignored.
68 *
69 * @param[in]  nn         the ring dimension
70 * @param[in]  base_k     the base k
71 * @param      out        output normalized znx
72 * @param      carry_out  output carry znx
73 * @param[in]  in         input znx
74 * @param[in]  carry_in   input carry znx
75 */
76EXPORT void znx_normalize(uint64_t nn, uint64_t base_k, int64_t* out, int64_t* carry_out, const int64_t* in,
77                          const int64_t* carry_in);
78
79#endif  // SPQLIOS_COEFFS_ARITHMETIC_H