Skip to content

Commit

Permalink
chore: fix new lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Jan 15, 2025
1 parent 9a64c34 commit ce14a49
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions tfhe-ntt/src/product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,20 @@ impl Plan {
let ntt_32: &mut [u32] = bytemuck::cast_slice_mut(ntt_32);

// optimize common cases(?): u64x1, u32x1
if self.plan_32.len() == 0 && self.plan_64.len() == 1 {
if self.plan_32.is_empty() && self.plan_64.len() == 1 {
ntt_64.copy_from_slice(standard);
self.plan_64[0].fwd(ntt_64);
return;
}
if self.plan_32.len() == 1 && self.plan_64.len() == 0 {
if self.plan_32.len() == 1 && self.plan_64.is_empty() {
for (ntt, &standard) in ntt_32.iter_mut().zip(standard) {
*ntt = standard as u32;
}
self.plan_32[0].fwd(ntt_32);
return;
}

if self.plan_32.len() == 2 && self.plan_64.len() == 0 {
if self.plan_32.len() == 2 && self.plan_64.is_empty() {
let (ntt0, ntt1) = ntt_32.split_at_mut(self.ntt_size());
let p0_div = self.plan_32[0].p_div();
let p1_div = self.plan_32[1].p_div();
Expand Down Expand Up @@ -375,15 +375,15 @@ impl Plan {
let ntt_64 = &*ntt_64;

// optimize common cases(?): u64x1, u32x1, u32x2
if self.plan_32.len() == 0 && self.plan_64.len() == 0 {
if self.plan_32.is_empty() && self.plan_64.is_empty() {
match mode {
InvMode::Replace => standard.fill(0),
InvMode::Accumulate => {}
}
return;
}

if self.plan_32.len() == 0 && self.plan_64.len() == 1 {
if self.plan_32.is_empty() && self.plan_64.len() == 1 {
match mode {
InvMode::Replace => standard.copy_from_slice(ntt_64),
InvMode::Accumulate => {
Expand All @@ -396,7 +396,7 @@ impl Plan {
}
return;
}
if self.plan_32.len() == 1 && self.plan_64.len() == 0 {
if self.plan_32.len() == 1 && self.plan_64.is_empty() {
match mode {
InvMode::Replace => {
for (standard, &ntt) in standard.iter_mut().zip(ntt_32) {
Expand All @@ -416,7 +416,7 @@ impl Plan {

// implements the algorithms from "the art of computer programming (Donald E. Knuth)" 4.3.2
// for finding solutions of the chinese remainder theorem
if self.plan_32.len() == 2 && self.plan_64.len() == 0 {
if self.plan_32.len() == 2 && self.plan_64.is_empty() {
let (ntt0, ntt1) = ntt_32.split_at(self.ntt_size());
let p0 = self.plan_32[0].modulus();
let p1 = self.plan_32[1].modulus();
Expand Down
6 changes: 3 additions & 3 deletions tfhe/src/core_crypto/fft_impl/fft128/math/fft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn f64_to_u128(f: f64) -> u128 {
0
} else {
// >= 1, < max
let m = 1 << 127 | (f as u128) << 75; // Mantissa and the implicit 1-bit.
let m = (1 << 127) | ((f as u128) << 75); // Mantissa and the implicit 1-bit.
let s = 1150 - (f >> 52); // Shift based on the exponent and bias.
if s >= 128 {
0
Expand All @@ -180,13 +180,13 @@ pub fn f64_to_u128(f: f64) -> u128 {
pub fn f64_to_i128(f: f64) -> i128 {
let f = f.to_bits();

let a = f & !0 >> 1; // Remove sign bit.
let a = f & (!0 >> 1); // Remove sign bit.
if a < 1023 << 52 {
// >= 0, < 1
0
} else {
// >= 1, < max
let m = 1 << 127 | (a as u128) << 75; // Mantissa and the implicit 1-bit.
let m = (1 << 127) | ((a as u128) << 75); // Mantissa and the implicit 1-bit.
let s = 1150 - (a >> 52); // Shift based on the exponent and bias.
let u = (m >> s) as i128; // Unsigned result.
if (f as i64) < 0 {
Expand Down
8 changes: 4 additions & 4 deletions tfhe/src/core_crypto/fft_impl/fft128_u128/math/fft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn u128_to_f64((lo, hi): (u64, u64)) -> f64 {
const C: f64 = (1u128 << 76) as f64;
const D: f64 = u128::MAX as f64;
if hi < 1 << 40 {
let l = f64::from_bits(A.to_bits() | (lo << 12) >> 12) - A;
let l = f64::from_bits(A.to_bits() | ((lo << 12) >> 12)) - A;
let h = f64::from_bits(B.to_bits() | ((lo >> 52) | (hi << 12))) - B;
l + h
} else {
Expand Down Expand Up @@ -306,7 +306,7 @@ pub fn f64_to_u128(f: f64) -> (u64, u64) {
(0u64, 0u64)
} else {
// >= 1, < max
let hi = 1 << 63 | f << 11;
let hi = (1 << 63) | (f << 11);
let s = 1150 - (f >> 52); // Shift based on the exponent and bias.
if s >= 128 {
(0u64, 0u64)
Expand All @@ -322,13 +322,13 @@ pub fn f64_to_u128(f: f64) -> (u64, u64) {
pub fn f64_to_i128(f: f64) -> (u64, u64) {
let f = f.to_bits();

let a = f & !0 >> 1; // Remove sign bit.
let a = f & (!0 >> 1); // Remove sign bit.
if a < 1023 << 52 {
// >= 0, < 1
(0, 0)
} else {
// >= 1, < max
let hi = 1 << 63 | a << 11;
let hi = (1 << 63) | (a << 11);
let s = 1150 - (a >> 52); // Shift based on the exponent and bias.
let u = if s >= 128 {
(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/gpu/server_key/radix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ impl CudaServerKey {
let num_bits_in_block = message_modulus.ilog2();
let padding_block_creator_lut = self.generate_lookup_table(|x| {
let x = x % message_modulus;
let x_sign_bit = x >> (num_bits_in_block - 1) & 1;
let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1;
// padding is a message full of 1 if sign bit is one
// else padding is a zero message
(message_modulus - 1) * x_sign_bit
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl ServerKey {
let num_bits_in_block = message_modulus.ilog2();
let padding_block_creator_lut = self.key.generate_lookup_table(|x| {
let x = x % message_modulus;
let x_sign_bit = x >> (num_bits_in_block - 1) & 1;
let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1;
// padding is a message full of 1 if sign bit is one
// else padding is a zero message
(message_modulus - 1) * x_sign_bit
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(in crate::integer) fn slice_oneblock_clear_unaligned(
offset: usize,
block_size: usize,
) -> u64 {
cur_block >> (offset) | ((next_block << (block_size - offset)) % (1 << block_size))
(cur_block >> (offset)) | ((next_block << (block_size - offset)) % (1 << block_size))
}

impl ServerKey {
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/integer/server_key/radix_parallel/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl ServerKey {
is_x_less_than_y_given_input_borrow(x, y, 0, self.message_modulus());
let b1 =
is_x_less_than_y_given_input_borrow(x, y, 1, self.message_modulus());
(b1 << 1 | b0) << 2
((b1 << 1) | b0) << 2
});

Some(PreparedSignedCheck::Unified(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ impl ServerKey {
};
let b0 = is_x_less_than_y_given_input_borrow(x, y, 0, modulus);
let b1 = is_x_less_than_y_given_input_borrow(x, y, 1, modulus);
(b1 << 1 | b0) << 2
((b1 << 1) | b0) << 2
});

Some(PreparedSignedCheck::Unified(
Expand Down
4 changes: 2 additions & 2 deletions tfhe/src/integer/server_key/radix_parallel/scalar_shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl ServerKey {
let shift_last_block = || {
let last_block_lut = self.key.generate_lookup_table(|x| {
let x = x % message_modulus;
let x_sign_bit = x >> (num_bits_in_block - 1) & 1;
let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1;
let shifted = x >> shift_within_block;
// padding is a message full of 1 if sign bit is one
// else padding is a zero message
Expand All @@ -193,7 +193,7 @@ impl ServerKey {

let pad_block_creator_lut = self.key.generate_lookup_table(|x| {
let x = x % message_modulus;
let x_sign_bit = x >> (num_bits_in_block - 1) & 1;
let x_sign_bit = (x >> (num_bits_in_block - 1)) & 1;
// padding is a message full of 1 if sign bit is one
// else padding is a zero message
(message_modulus - 1) * x_sign_bit
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/shortint/client_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ impl ClientKey {
let decrypted_u64: u64 = self.decrypt_no_decode(ct);

let mut result = decrypted_u64 as u128 * basis as u128;
result = result.wrapping_add((result & 1 << 63) << 1) / (1 << 64);
result = result.wrapping_add((result & (1 << 63)) << 1) / (1 << 64);

result as u64 % basis
}
Expand Down
2 changes: 1 addition & 1 deletion utils/tfhe-versionable-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn remove_unsized_bound(
.filter(|bound| match bound {
TypeParamBound::Trait(trait_bound) => {
if !matches!(trait_bound.modifier, TraitBoundModifier::None) {
if let Some(segment) = trait_bound.path.segments.iter().last() {
if let Some(segment) = trait_bound.path.segments.iter().next_back() {
if segment.ident == "Sized" {
return false;
}
Expand Down

0 comments on commit ce14a49

Please sign in to comment.