arnaucube
arnaucube/poulpyPublic Self-hosted repository
fixed modulus switching rounding
Jean-Philippe Bossuat jeanphilippe.bossuat@gmail.com
Tue, 08 Jul 2025 13:48:51 +0200
commit

af5bbbb55db93cd815afe232bb7d588069d80edd

parent

f7c94cd84acc80c62cd58916c9678c3d4cbe7077

1 files changed, 2 insertions(+), 18 deletions(-)

jump to
M core/src/blind_rotation/ccgi.rs → core/src/blind_rotation/ccgi.rs

@@ -438,7 +438,7 @@

if basek > log2n { let diff: usize = basek - log2n; res.iter_mut().for_each(|x| { - *x = div_ceil_signed_by_pow2(x, diff); + *x = div_round_by_pow2(x, diff); }) } else { let rem: usize = basek - (log2n % basek);

@@ -460,21 +460,5 @@ }

#[inline(always)] fn div_round_by_pow2(x: &i64, k: usize) -> i64 { - if x >= &0 { - (x + (1 << (k - 1))) >> k - } else { - (x + (-1 << (k - 1))) >> k - } -} - -// #[inline(always)] -// fn div_floor_signed_by_pow2(x: &i64, k: usize) -> i64{ -// let bias: i64 = (1 << k) - 1; -// (x + ((x >> 63) & bias)) >> k -// } - -#[inline(always)] -fn div_ceil_signed_by_pow2(x: &i64, k: usize) -> i64 { - let bias: i64 = (1 << k) - 1; - (x + ((x >> 63) & bias)) >> k + (x + (1 << (k - 1))) >> k }