25 template <
class Adaptee,
class... Args>
54 NTT(uint64_t degree, uint64_t q,
55 std::shared_ptr<AllocatorBase> alloc_ptr = {});
57 template <
class Allocator,
class... AllocatorArgs>
58 NTT(uint64_t degree, uint64_t q, Allocator&& a, AllocatorArgs&&... args)
62 std::move(a), std::forward<AllocatorArgs>(args)...))) {}
75 NTT(uint64_t degree, uint64_t q, uint64_t root_of_unity,
76 std::shared_ptr<AllocatorBase> alloc_ptr = {});
78 template <
class Allocator,
class... AllocatorArgs>
79 NTT(uint64_t degree, uint64_t q, uint64_t root_of_unity, Allocator&& a,
80 AllocatorArgs&&... args)
81 :
NTT(degree, q, root_of_unity,
84 std::move(a), std::forward<AllocatorArgs>(args)...))) {}
100 uint64_t input_mod_factor, uint64_t output_mod_factor);
110 uint64_t input_mod_factor, uint64_t output_mod_factor);
123 return m_root_of_unity_powers;
132 return m_precon32_root_of_unity_powers;
138 return m_precon64_root_of_unity_powers;
144 return m_avx512_root_of_unity_powers;
150 return m_avx512_precon32_root_of_unity_powers;
156 return m_avx512_precon52_root_of_unity_powers;
162 return m_avx512_precon64_root_of_unity_powers;
167 return m_inv_root_of_unity_powers;
179 return m_precon32_inv_root_of_unity_powers;
186 return m_precon52_inv_root_of_unity_powers;
193 return m_precon64_inv_root_of_unity_powers;
226 void ComputeRootOfUnityPowers();
231 uint64_t m_degree_bits;
236 std::shared_ptr<AllocatorBase> m_alloc;
const AlignedVector64< uint64_t > & GetInvRootOfUnityPowers() const
Returns the inverse root of unity powers in bit-reversed order.
Definition: ntt.hpp:166
const AlignedVector64< uint64_t > & GetPrecon52InvRootOfUnityPowers() const
Returns the vector of 52-bit pre-conditioned pre-computed root of unity.
Definition: ntt.hpp:185
NTT(uint64_t degree, uint64_t q, uint64_t root_of_unity, Allocator &&a, AllocatorArgs &&... args)
Definition: ntt.hpp:79
uint64_t GetRootOfUnityPower(size_t i)
Returns the root of unity power at bit-reversed index i.
Definition: ntt.hpp:127
Base class for custom memory allocator.
Definition: allocator.hpp:12
Performs negacyclic forward and inverse number-theoretic transform (NTT), commonly used in RLWE crypt...
Definition: ntt.hpp:22
NTT(uint64_t degree, uint64_t q, Allocator &&a, AllocatorArgs &&... args)
Definition: ntt.hpp:58
const AlignedVector64< uint64_t > & GetPrecon32InvRootOfUnityPowers() const
Returns the vector of 32-bit pre-conditioned pre-computed root of unity.
Definition: ntt.hpp:178
uint64_t GetInvRootOfUnityPower(size_t i)
Returns the inverse root of unity power at bit-reversed index i.
Definition: ntt.hpp:171
std::vector< T, AlignedAllocator< T, 64 > > AlignedVector64
64-byte aligned memory allocator
Definition: aligned-allocator.hpp:107
AllocatorAdapter(Adaptee &&_a, Args &&... args)
static const size_t s_ifma_shift_bits
Bit shift used in Barrett precomputation when AVX512-IFMA acceleration is enabled.
Definition: ntt.hpp:207
static size_t MaxDegreeBits()
Maximum power of 2 in degree.
Definition: ntt.hpp:197
const AlignedVector64< uint64_t > & GetPrecon64RootOfUnityPowers() const
Returns 64-bit pre-conditioned root of unity powers in bit-reversed order.
Definition: ntt.hpp:137
uint64_t GetDegree() const
Returns the degree N.
Definition: ntt.hpp:116
const AlignedVector64< uint64_t > & GetAVX512Precon52RootOfUnityPowers() const
Returns 52-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. ...
Definition: ntt.hpp:155
void ComputeInverse(uint64_t *result, const uint64_t *operand, uint64_t input_mod_factor, uint64_t output_mod_factor)
void deallocate_impl(void *p, size_t n)
static const size_t s_max_inv_32_modulus
Maximum modulus to use 32-bit AVX512-DQ acceleration for the inverse transform.
Definition: ntt.hpp:215
const AlignedVector64< uint64_t > & GetPrecon32RootOfUnityPowers() const
Returns 32-bit pre-conditioned root of unity powers in bit-reversed order.
Definition: ntt.hpp:131
const AlignedVector64< uint64_t > & GetPrecon64InvRootOfUnityPowers() const
Returns the vector of 64-bit pre-conditioned pre-computed root of unity.
Definition: ntt.hpp:192
const AlignedVector64< uint64_t > & GetAVX512Precon64RootOfUnityPowers() const
Returns 64-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. ...
Definition: ntt.hpp:161
Definition: eltwise-add-mod.hpp:8
uint64_t GetMinimalRootOfUnity() const
Returns the minimal 2N'th root of unity.
Definition: ntt.hpp:113
NTT()=default
Initializes an empty NTT object.
const AlignedVector64< uint64_t > & GetRootOfUnityPowers() const
Returns the root of unity powers in bit-reversed order.
Definition: ntt.hpp:122
static const size_t s_max_fwd_32_modulus
Maximum modulus to use 32-bit AVX512-DQ acceleration for the forward transform.
Definition: ntt.hpp:211
uint64_t GetModulus() const
Returns the word-sized prime modulus.
Definition: ntt.hpp:119
static const size_t s_max_fwd_ifma_modulus
Maximum modulus to use AVX512-IFMA acceleration for the forward transform.
Definition: ntt.hpp:219
~NTT()=default
Destructs the NTT object.
static const size_t s_default_shift_bits
Default bit shift used in Barrett precomputation.
Definition: ntt.hpp:203
Helper class for custom memory allocation.
Definition: ntt.hpp:26
static const size_t s_max_inv_ifma_modulus
Maximum modulus to use AVX512-IFMA acceleration for the inverse transform.
Definition: ntt.hpp:223
void * allocate_impl(size_t bytes_count)
const AlignedVector64< uint64_t > & GetAVX512Precon32RootOfUnityPowers() const
Returns 32-bit pre-conditioned AVX512 root of unity powers in bit-reversed order. ...
Definition: ntt.hpp:149
void ComputeForward(uint64_t *result, const uint64_t *operand, uint64_t input_mod_factor, uint64_t output_mod_factor)
Compute forward NTT. Results are bit-reversed.
static bool CheckArguments(uint64_t degree, uint64_t modulus)
Returns true if arguments satisfy constraints for negacyclic NTT.
const AlignedVector64< uint64_t > & GetAVX512RootOfUnityPowers() const
Returns the root of unity powers in bit-reversed order with modifications for use by AVX512 implement...
Definition: ntt.hpp:143
static size_t MaxModulusBits()
Maximum number of bits in modulus;.
Definition: ntt.hpp:200
Helper memory allocation struct which delegates implementation to AllocatorImpl.
Definition: allocator.hpp:29