From d770a271b321b0e38d0b3ee2ce3bf5e0c65987fb Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Thu, 22 Feb 2024 16:03:54 +0100 Subject: [PATCH] chore(core): add custom power of 2 support for u128 --- tfhe/src/core_crypto/commons/numeric/unsigned.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tfhe/src/core_crypto/commons/numeric/unsigned.rs b/tfhe/src/core_crypto/commons/numeric/unsigned.rs index e3a3c92f3d..f6c774fe2d 100644 --- a/tfhe/src/core_crypto/commons/numeric/unsigned.rs +++ b/tfhe/src/core_crypto/commons/numeric/unsigned.rs @@ -157,7 +157,10 @@ macro_rules! implement { .wrapping_rem(custom_modulus_u128) .cast_into() } else { - todo!("wrapping_add_custom_mod is not yet implemented for types wider than u64") + if custom_modulus.is_power_of_two() { + return self.wrapping_add(other).wrapping_rem(custom_modulus); + } + todo!("wrapping_add_custom_mod is not yet implemented for non power of two moduli wider than u64") } } #[inline] @@ -172,7 +175,10 @@ macro_rules! implement { .wrapping_rem(custom_modulus_u128) .cast_into() } else { - todo!("wrapping_sub_custom_mod is not yet implemented for types wider than u64") + if custom_modulus.is_power_of_two() { + return self.wrapping_sub(other).wrapping_rem(custom_modulus); + } + todo!("wrapping_sub_custom_mod is not yet implemented for non power of two moduli wider than u64") } } #[inline]