mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-08 22:28:01 -05:00
chore: fix new lints
This commit is contained in:
@@ -278,12 +278,12 @@ 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;
|
||||
}
|
||||
@@ -291,7 +291,7 @@ impl Plan {
|
||||
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();
|
||||
@@ -375,7 +375,7 @@ 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 => {}
|
||||
@@ -383,7 +383,7 @@ impl Plan {
|
||||
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 => {
|
||||
@@ -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) {
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user