poulpy/spqlios/lib/spqlios/q120/q120_arithmetic.h
spqlios/lib/spqlios/q120/q120_arithmetic.hRaw
1#ifndef SPQLIOS_Q120_ARITHMETIC_H
2#define SPQLIOS_Q120_ARITHMETIC_H
3
4#include <stdint.h>
5
6#include "../commons.h"
7#include "q120_common.h"
8
9typedef struct _q120_mat1col_product_baa_precomp q120_mat1col_product_baa_precomp;
10typedef struct _q120_mat1col_product_bbb_precomp q120_mat1col_product_bbb_precomp;
11typedef struct _q120_mat1col_product_bbc_precomp q120_mat1col_product_bbc_precomp;
12
13EXPORT q120_mat1col_product_baa_precomp* q120_new_vec_mat1col_product_baa_precomp();
14EXPORT void q120_delete_vec_mat1col_product_baa_precomp(q120_mat1col_product_baa_precomp*);
15EXPORT q120_mat1col_product_bbb_precomp* q120_new_vec_mat1col_product_bbb_precomp();
16EXPORT void q120_delete_vec_mat1col_product_bbb_precomp(q120_mat1col_product_bbb_precomp*);
17EXPORT q120_mat1col_product_bbc_precomp* q120_new_vec_mat1col_product_bbc_precomp();
18EXPORT void q120_delete_vec_mat1col_product_bbc_precomp(q120_mat1col_product_bbc_precomp*);
19
20// ell < 10000
21EXPORT void q120_vec_mat1col_product_baa_ref(q120_mat1col_product_baa_precomp*, const uint64_t ell, q120b* const res,
22 const q120a* const x, const q120a* const y);
23EXPORT void q120_vec_mat1col_product_bbb_ref(q120_mat1col_product_bbb_precomp*, const uint64_t ell, q120b* const res,
24 const q120b* const x, const q120b* const y);
25EXPORT void q120_vec_mat1col_product_bbc_ref(q120_mat1col_product_bbc_precomp*, const uint64_t ell, q120b* const res,
26 const q120b* const x, const q120c* const y);
27
28EXPORT void q120_vec_mat1col_product_baa_avx2(q120_mat1col_product_baa_precomp*, const uint64_t ell, q120b* const res,
29 const q120a* const x, const q120a* const y);
30EXPORT void q120_vec_mat1col_product_bbb_avx2(q120_mat1col_product_bbb_precomp*, const uint64_t ell, q120b* const res,
31 const q120b* const x, const q120b* const y);
32EXPORT void q120_vec_mat1col_product_bbc_avx2(q120_mat1col_product_bbc_precomp*, const uint64_t ell, q120b* const res,
33 const q120b* const x, const q120c* const y);
34
35EXPORT void q120x2_vec_mat1col_product_bbc_ref(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
36 q120b* const res, const q120b* const x, const q120c* const y);
37EXPORT void q120x2_vec_mat1col_product_bbc_avx2(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
38 q120b* const res, const q120b* const x, const q120c* const y);
39EXPORT void q120x2_vec_mat2cols_product_bbc_ref(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
40 q120b* const res, const q120b* const x, const q120c* const y);
41EXPORT void q120x2_vec_mat2cols_product_bbc_avx2(q120_mat1col_product_bbc_precomp* precomp, const uint64_t ell,
42 q120b* const res, const q120b* const x, const q120c* const y);
43
44/**
45 * @brief extract 1 q120x2 block from one q120 ntt vectors
46 * @param nn the size of each vector
47 * @param blk the block id to extract (<nn/2)
48 * @param dst the output: nrows q120x2's dst[i] = src[i](blk)
49 * @param src the input: nrows q120 ntt vecs's
50 */
51EXPORT void q120x2_extract_1blk_from_q120b_ref(uint64_t nn, uint64_t blk,
52 q120x2b* const dst, // 8 doubles
53 const q120b* const src // a reim vector
54);
55EXPORT void q120x2_extract_1blk_from_q120c_ref(uint64_t nn, uint64_t blk,
56 q120x2c* const dst, // 8 doubles
57 const q120c* const src // a reim vector
58);
59EXPORT void q120x2_extract_1blk_from_q120b_avx(uint64_t nn, uint64_t blk,
60 q120x2b* const dst, // 8 doubles
61 const q120b* const src // a reim vector
62);
63EXPORT void q120x2_extract_1blk_from_q120c_avx(uint64_t nn, uint64_t blk,
64 q120x2c* const dst, // 8 doubles
65 const q120c* const src // a reim vector
66);
67
68/**
69 * @brief extract 1 reim4 block from nrows reim vectors of m complexes
70 * @param nn the size of each q120
71 * @param nrows the number of q120 (ntt) vectors
72 * @param blk the block id to extract (<m/4)
73 * @param dst the output: nrows q120x2's dst[i] = src[i](blk)
74 * @param src the input: nrows q120 ntt vectors
75 */
76EXPORT void q120x2_extract_1blk_from_contiguous_q120b_ref(
77 uint64_t nn, uint64_t nrows, uint64_t blk,
78 q120x2b* const dst, // nrows * 2 q120
79 const q120b* const src // a contiguous array of nrows q120b vectors
80);
81EXPORT void q120x2_extract_1blk_from_contiguous_q120b_avx(
82 uint64_t nn, uint64_t nrows, uint64_t blk,
83 q120x2b* const dst, // nrows * 2 q120
84 const q120b* const src // a contiguous array of nrows q120b vectors
85);
86
87/**
88 * @brief saves 1 single q120x2 block in a q120 vectors of size nn
89 * @param nn the size of the output q120
90 * @param blk the block id to save (<nn/2)
91 * @param dest the output q120b vector: dst(blk) = src
92 * @param src the input q120x2b
93 */
94EXPORT void q120x2b_save_1blk_to_q120b_ref(uint64_t nn, uint64_t blk,
95 q120b* dest, // 1 reim vector of length m
96 const q120x2b* src // 8 doubles
97);
98EXPORT void q120x2b_save_1blk_to_q120b_avx(uint64_t nn, uint64_t blk,
99 q120b* dest, // 1 reim vector of length m
100 const q120x2b* src // 8 doubles
101);
102
103EXPORT void q120_add_bbb_simple(uint64_t nn, q120b* const res, const q120b* const x, const q120b* const y);
104
105EXPORT void q120_add_ccc_simple(uint64_t nn, q120c* const res, const q120c* const x, const q120c* const y);
106
107EXPORT void q120_c_from_b_simple(uint64_t nn, q120c* const res, const q120b* const x);
108
109EXPORT void q120_b_from_znx64_simple(uint64_t nn, q120b* const res, const int64_t* const x);
110
111EXPORT void q120_c_from_znx64_simple(uint64_t nn, q120c* const res, const int64_t* const x);
112
113EXPORT void q120_b_to_znx128_simple(uint64_t nn, __int128_t* const res, const q120b* const x);
114
115#endif // SPQLIOS_Q120_ARITHMETIC_H