Skip to content

Commit f31a902

Browse files
authored
Merge pull request #13 from tfhe/sc/q120
Q120 ntt and arithmetic
2 parents f0d1c97 + a18164d commit f31a902

22 files changed

+3662
-0
lines changed

spqlios/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ set(SRCS_GENERIC
2121
reim/reim_ifft_ref.c
2222
reim/reim_ifft_ref.c
2323
reim/reim_to_tnx_ref.c
24+
q120/q120_ntt.c
25+
q120/q120_arithmetic_ref.c
26+
q120/q120_arithmetic_simple.c
2427
)
2528
# C or assembly source files compiled only on x86 targets
2629
set(SRCS_X86
@@ -33,6 +36,7 @@ set(SRCS_AARCH64
3336
cplx/cplx_fallbacks_aarch64.c
3437
reim/reim_fallbacks_aarch64.c
3538
reim4/reim4_fallbacks_aarch64.c
39+
q120/q120_fallbacks_aarch64.c
3640
)
3741

3842
# C or assembly source files compiled only on x86: avx, avx2, fma targets
@@ -69,6 +73,8 @@ set_source_files_properties(${SRCS_AVX512} PROPERTIES COMPILE_OPTIONS "-mfma;-ma
6973

7074
# C or assembly source files compiled only on x86: avx2 + bmi targets
7175
set(SRCS_AVX2
76+
q120/q120_arithmetic_avx2.c
77+
q120/q120_ntt_avx2.c
7278
)
7379
set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_OPTIONS "-mbmi2;-mavx2")
7480

@@ -83,6 +89,9 @@ set(HEADERSPUBLIC
8389
commons.h
8490
cplx/cplx_fft.h
8591
reim/reim_fft.h
92+
q120/q120_common.h
93+
q120/q120_arithmetic.h
94+
q120/q120_ntt.h
8695
)
8796

8897
# H header files containing the private API (these headers are used internally)
@@ -96,6 +105,8 @@ set(HEADERSPRIVATE
96105
reim4/reim4_fftvec_public.h
97106
reim/reim_fft_internal.h
98107
reim/reim_fft_private.h
108+
q120/q120_arithmetic_private.h
109+
q120/q120_ntt_private.h
99110
)
100111

101112
set(SPQLIOSSOURCES

spqlios/q120/q120_arithmetic.h

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
9+
typedef struct _q120_mat1col_product_baa_precomp q120_mat1col_product_baa_precomp;
10+
typedef struct _q120_mat1col_product_bbb_precomp q120_mat1col_product_bbb_precomp;
11+
typedef struct _q120_mat1col_product_bbc_precomp q120_mat1col_product_bbc_precomp;
12+
13+
EXPORT q120_mat1col_product_baa_precomp* q120_new_vec_mat1col_product_baa_precomp();
14+
EXPORT void q120_delete_vec_mat1col_product_baa_precomp(q120_mat1col_product_baa_precomp*);
15+
EXPORT q120_mat1col_product_bbb_precomp* q120_new_vec_mat1col_product_bbb_precomp();
16+
EXPORT void q120_delete_vec_mat1col_product_bbb_precomp(q120_mat1col_product_bbb_precomp*);
17+
EXPORT q120_mat1col_product_bbc_precomp* q120_new_vec_mat1col_product_bbc_precomp();
18+
EXPORT void q120_delete_vec_mat1col_product_bbc_precomp(q120_mat1col_product_bbc_precomp*);
19+
20+
// ell < 10000
21+
EXPORT 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);
23+
EXPORT 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);
25+
EXPORT 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+
28+
EXPORT 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);
30+
EXPORT 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);
32+
EXPORT 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+
35+
EXPORT 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);
37+
EXPORT 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);
39+
EXPORT 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);
41+
EXPORT 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+
*/
51+
EXPORT 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+
);
55+
EXPORT 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+
);
59+
EXPORT 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+
);
63+
EXPORT 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+
*/
76+
EXPORT 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+
);
81+
EXPORT 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+
*/
94+
EXPORT 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+
);
98+
EXPORT 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+
103+
EXPORT void q120_add_bbb_simple(uint64_t nn, q120b* const res, const q120b* const x, const q120b* const y);
104+
105+
EXPORT void q120_add_ccc_simple(uint64_t nn, q120c* const res, const q120c* const x, const q120c* const y);
106+
107+
EXPORT void q120_c_from_b_simple(uint64_t nn, q120c* const res, const q120b* const x);
108+
109+
EXPORT void q120_b_from_znx64_simple(uint64_t nn, q120b* const res, const int64_t* const x);
110+
111+
EXPORT void q120_c_from_znx64_simple(uint64_t nn, q120c* const res, const int64_t* const x);
112+
113+
EXPORT void q120_b_to_znx128_simple(uint64_t nn, __int128_t* const res, const q120b* const x);
114+
115+
#endif // SPQLIOS_Q120_ARITHMETIC_H

0 commit comments

Comments
 (0)