mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 05:06:44 +01:00
* Added some circuit, evaluation + some layouts * Refactor + memory reduction * Rows -> Dnum, Digits -> Dsize * fix #96 + glwe_packing (indirectly CBT) * clippy
199 lines
6.0 KiB
Rust
199 lines
6.0 KiB
Rust
use crate::reference::znx::{
|
|
ZnxAdd, ZnxAddInplace, ZnxAutomorphism, ZnxCopy, ZnxExtractDigitAddMul, ZnxMulAddPowerOfTwo, ZnxMulPowerOfTwo,
|
|
ZnxMulPowerOfTwoInplace, ZnxNegate, ZnxNegateInplace, ZnxNormalizeDigit, ZnxNormalizeFinalStep, ZnxNormalizeFinalStepInplace,
|
|
ZnxNormalizeFirstStep, ZnxNormalizeFirstStepCarryOnly, ZnxNormalizeFirstStepInplace, ZnxNormalizeMiddleStep,
|
|
ZnxNormalizeMiddleStepCarryOnly, ZnxNormalizeMiddleStepInplace, ZnxRotate, ZnxSub, ZnxSubInplace, ZnxSubNegateInplace,
|
|
ZnxSwitchRing, ZnxZero,
|
|
add::{znx_add_inplace_ref, znx_add_ref},
|
|
automorphism::znx_automorphism_ref,
|
|
copy::znx_copy_ref,
|
|
neg::{znx_negate_inplace_ref, znx_negate_ref},
|
|
normalization::{
|
|
znx_normalize_final_step_inplace_ref, znx_normalize_final_step_ref, znx_normalize_first_step_carry_only_ref,
|
|
znx_normalize_first_step_inplace_ref, znx_normalize_first_step_ref, znx_normalize_middle_step_carry_only_ref,
|
|
znx_normalize_middle_step_inplace_ref, znx_normalize_middle_step_ref,
|
|
},
|
|
sub::{znx_sub_inplace_ref, znx_sub_negate_inplace_ref, znx_sub_ref},
|
|
switch_ring::znx_switch_ring_ref,
|
|
zero::znx_zero_ref,
|
|
znx_extract_digit_addmul_ref, znx_mul_add_power_of_two_ref, znx_mul_power_of_two_inplace_ref, znx_mul_power_of_two_ref,
|
|
znx_normalize_digit_ref, znx_rotate,
|
|
};
|
|
|
|
pub struct ZnxRef {}
|
|
|
|
impl ZnxAdd for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_add(res: &mut [i64], a: &[i64], b: &[i64]) {
|
|
znx_add_ref(res, a, b);
|
|
}
|
|
}
|
|
|
|
impl ZnxRotate for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_rotate(p: i64, res: &mut [i64], src: &[i64]) {
|
|
znx_rotate::<Self>(p, res, src);
|
|
}
|
|
}
|
|
|
|
impl ZnxAddInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_add_inplace(res: &mut [i64], a: &[i64]) {
|
|
znx_add_inplace_ref(res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxSub for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_sub(res: &mut [i64], a: &[i64], b: &[i64]) {
|
|
znx_sub_ref(res, a, b);
|
|
}
|
|
}
|
|
|
|
impl ZnxSubInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_sub_inplace(res: &mut [i64], a: &[i64]) {
|
|
znx_sub_inplace_ref(res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxSubNegateInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_sub_negate_inplace(res: &mut [i64], a: &[i64]) {
|
|
znx_sub_negate_inplace_ref(res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxAutomorphism for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_automorphism(p: i64, res: &mut [i64], a: &[i64]) {
|
|
znx_automorphism_ref(p, res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxMulPowerOfTwo for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_mul_power_of_two(k: i64, res: &mut [i64], a: &[i64]) {
|
|
znx_mul_power_of_two_ref(k, res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxMulAddPowerOfTwo for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_muladd_power_of_two(k: i64, res: &mut [i64], a: &[i64]) {
|
|
znx_mul_add_power_of_two_ref(k, res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxMulPowerOfTwoInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_mul_power_of_two_inplace(k: i64, res: &mut [i64]) {
|
|
znx_mul_power_of_two_inplace_ref(k, res);
|
|
}
|
|
}
|
|
|
|
impl ZnxCopy for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_copy(res: &mut [i64], a: &[i64]) {
|
|
znx_copy_ref(res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxNegate for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_negate(res: &mut [i64], src: &[i64]) {
|
|
znx_negate_ref(res, src);
|
|
}
|
|
}
|
|
|
|
impl ZnxNegateInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_negate_inplace(res: &mut [i64]) {
|
|
znx_negate_inplace_ref(res);
|
|
}
|
|
}
|
|
|
|
impl ZnxZero for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_zero(res: &mut [i64]) {
|
|
znx_zero_ref(res);
|
|
}
|
|
}
|
|
|
|
impl ZnxSwitchRing for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_switch_ring(res: &mut [i64], a: &[i64]) {
|
|
znx_switch_ring_ref(res, a);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeFinalStep for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_final_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
znx_normalize_final_step_ref(base2k, lsh, x, a, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeFinalStepInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_final_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
znx_normalize_final_step_inplace_ref(base2k, lsh, x, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeFirstStep for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_first_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
znx_normalize_first_step_ref(base2k, lsh, x, a, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeFirstStepCarryOnly for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_first_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) {
|
|
znx_normalize_first_step_carry_only_ref(base2k, lsh, x, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeFirstStepInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_first_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
znx_normalize_first_step_inplace_ref(base2k, lsh, x, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeMiddleStep for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_middle_step(base2k: usize, lsh: usize, x: &mut [i64], a: &[i64], carry: &mut [i64]) {
|
|
znx_normalize_middle_step_ref(base2k, lsh, x, a, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeMiddleStepCarryOnly for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_middle_step_carry_only(base2k: usize, lsh: usize, x: &[i64], carry: &mut [i64]) {
|
|
znx_normalize_middle_step_carry_only_ref(base2k, lsh, x, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeMiddleStepInplace for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_middle_step_inplace(base2k: usize, lsh: usize, x: &mut [i64], carry: &mut [i64]) {
|
|
znx_normalize_middle_step_inplace_ref(base2k, lsh, x, carry);
|
|
}
|
|
}
|
|
|
|
impl ZnxExtractDigitAddMul for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_extract_digit_addmul(base2k: usize, lsh: usize, res: &mut [i64], src: &mut [i64]) {
|
|
znx_extract_digit_addmul_ref(base2k, lsh, res, src);
|
|
}
|
|
}
|
|
|
|
impl ZnxNormalizeDigit for ZnxRef {
|
|
#[inline(always)]
|
|
fn znx_normalize_digit(base2k: usize, res: &mut [i64], src: &mut [i64]) {
|
|
znx_normalize_digit_ref(base2k, res, src);
|
|
}
|
|
}
|