poulpy/spqlios/lib/test/testlib/ntt120_layouts.h
spqlios/lib/test/testlib/ntt120_layouts.hRaw
1#ifndef SPQLIOS_NTT120_LAYOUTS_H
2#define SPQLIOS_NTT120_LAYOUTS_H
3
4#include "../../spqlios/arithmetic/vec_znx_arithmetic.h"
5#include "mod_q120.h"
6#include "negacyclic_polynomial.h"
7#include "ntt120_dft.h"
8#include "test_commons.h"
9
10struct q120b_vector_view {};
11
12struct mod_q120x2 {
13 mod_q120 value[2];
14 mod_q120x2();
15 mod_q120x2(const mod_q120& a, const mod_q120& b);
16 mod_q120x2(__int128_t value);
17 explicit mod_q120x2(q120x2b* addr);
18 explicit mod_q120x2(q120x2c* addr);
19 void save_as(q120x2b* addr) const;
20 void save_as(q120x2c* addr) const;
21 static mod_q120x2 random();
22};
23mod_q120x2 operator+(const mod_q120x2& a, const mod_q120x2& b);
24mod_q120x2 operator-(const mod_q120x2& a, const mod_q120x2& b);
25mod_q120x2 operator*(const mod_q120x2& a, const mod_q120x2& b);
26bool operator==(const mod_q120x2& a, const mod_q120x2& b);
27bool operator!=(const mod_q120x2& a, const mod_q120x2& b);
28mod_q120x2& operator+=(mod_q120x2& a, const mod_q120x2& b);
29mod_q120x2& operator-=(mod_q120x2& a, const mod_q120x2& b);
30
31/** @brief test layout for the VEC_ZNX_DFT */
32struct ntt120_vec_znx_dft_layout {
33 const uint64_t nn;
34 const uint64_t size;
35 VEC_ZNX_DFT* const data;
36 ntt120_vec_znx_dft_layout(uint64_t n, uint64_t size);
37 mod_q120x2 get_copy_zext(uint64_t idx, uint64_t blk);
38 q120_nttvec get_copy_zext(uint64_t idx);
39 void set(uint64_t idx, const q120_nttvec& v);
40 q120x2b* get_blk(uint64_t idx, uint64_t blk);
41 thash content_hash() const;
42 void fill_random();
43 ~ntt120_vec_znx_dft_layout();
44};
45
46/** @brief test layout for the VEC_ZNX_BIG */
47class ntt120_vec_znx_big_layout {
48 public:
49 const uint64_t nn;
50 const uint64_t size;
51 VEC_ZNX_BIG* const data;
52 ntt120_vec_znx_big_layout(uint64_t n, uint64_t size);
53
54 private:
55 __int128* get_addr(uint64_t index) const;
56
57 public:
58 znx_i128 get_copy(uint64_t index) const;
59 znx_i128 get_copy_zext(uint64_t index) const;
60 void set(uint64_t index, const znx_i128& value);
61 ~ntt120_vec_znx_big_layout();
62};
63
64/** @brief test layout for the VMP_PMAT */
65class ntt120_vmp_pmat_layout {
66 const uint64_t nn;
67 const uint64_t nrows;
68 const uint64_t ncols;
69 VMP_PMAT* const data;
70 ntt120_vmp_pmat_layout(uint64_t n, uint64_t nrows, uint64_t ncols);
71 mod_q120x2 get(uint64_t row, uint64_t col, uint64_t blk) const;
72 ~ntt120_vmp_pmat_layout();
73};
74
75/** @brief test layout for the SVP_PPOL */
76class ntt120_svp_ppol_layout {
77 const uint64_t nn;
78 SVP_PPOL* const data;
79 ntt120_svp_ppol_layout(uint64_t n);
80 ~ntt120_svp_ppol_layout();
81};
82
83/** @brief test layout for the CNV_PVEC_L */
84class ntt120_cnv_left_layout {
85 const uint64_t nn;
86 const uint64_t size;
87 CNV_PVEC_L* const data;
88 ntt120_cnv_left_layout(uint64_t n, uint64_t size);
89 mod_q120x2 get(uint64_t idx, uint64_t blk);
90 ~ntt120_cnv_left_layout();
91};
92
93/** @brief test layout for the CNV_PVEC_R */
94class ntt120_cnv_right_layout {
95 const uint64_t nn;
96 const uint64_t size;
97 CNV_PVEC_R* const data;
98 ntt120_cnv_right_layout(uint64_t n, uint64_t size);
99 mod_q120x2 get(uint64_t idx, uint64_t blk);
100 ~ntt120_cnv_right_layout();
101};
102
103#endif // SPQLIOS_NTT120_LAYOUTS_H