fixed modulus switching rounding
Jean-Philippe Bossuat jeanphilippe.bossuat@gmail.com
Tue, 08 Jul 2025 13:48:51 +0200
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 }