From 1fba0a26ac5d16759c2f5ee078e2bc8fe860c088 Mon Sep 17 00:00:00 2001 From: "Hadrien G." Date: Sat, 5 Jul 2025 12:06:20 +0200 Subject: [PATCH] Leverage is_multiple_of as advised by newer lints --- common/src/inputs/generators/mod.rs | 16 ++++++++-------- common/src/operations.rs | 14 +++++++++----- fma_addend/src/lib.rs | 9 ++++----- fma_full_max/src/lib.rs | 9 ++++----- rust-toolchain | 2 +- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/common/src/inputs/generators/mod.rs b/common/src/inputs/generators/mod.rs index 005a0fd..d0ce774 100644 --- a/common/src/inputs/generators/mod.rs +++ b/common/src/inputs/generators/mod.rs @@ -139,7 +139,7 @@ pub fn generate_input_pairs( // Split the input in two halves let target_len = target.len(); - assert_eq!(target_len % 2, 0); + assert!(target_len.is_multiple_of(2)); let half_len = target_len / 2; let (left_target, right_target) = target.split_at_mut(half_len); assert_eq!(left_target.len(), right_target.len()); @@ -335,7 +335,7 @@ impl<'data, T> DataStream<'data, T> { pub fn into_pair_iter( self, ) -> impl DoubleEndedIterator + ExactSizeIterator { - assert_eq!(self.target.len() % 2, 0); + assert!(self.target.len().is_multiple_of(2)); debug_assert!(self.stream_idx < self.num_streams); let half_len = self.target.len() / 2; @@ -498,7 +498,7 @@ pub mod test_utils { + (stream_idx < (sequence_len % num_streams)) as usize }; let stream_len = if pairwise { - assert_eq!(target_len % 2, 0); + assert!(target_len.is_multiple_of(2)); stream_len(target_len / 2) * 2 } else { stream_len(target_len) @@ -623,7 +623,7 @@ pub(crate) mod tests { fn stream_pair_iter((num_streams, mut target) in num_streams_and_target::(true)) { let initial = target.clone(); let target = &mut target[..]; - debug_assert_eq!(target.len() % 2, 0); + debug_assert!(target.len().is_multiple_of(2)); let half_len = target.len() / 2; let left_start = target.as_ptr(); let right_start = left_start.wrapping_add(half_len); @@ -839,7 +839,7 @@ pub(crate) mod tests { (num_streams, num_subnormals, target_len) in num_streams_and_subnormal_config(true), ) { // Set up a mock of the expected element_generator usage context - debug_assert_eq!(target_len % 2, 0); + debug_assert!(target_len.is_multiple_of(2)); let half_len = target_len / 2; let mut rng = rand::thread_rng(); if num_subnormals > target_len { @@ -942,7 +942,7 @@ pub(crate) mod tests { pairs: bool, ) -> impl Strategy { if pairs { - assert_eq!(INPUT_REGISTERS % 2, 0); + assert!(INPUT_REGISTERS.is_multiple_of(2)); } ( [any::(); INPUT_REGISTERS], @@ -1168,7 +1168,7 @@ pub(crate) mod tests { prop_assert!(streams.len() >= expected_streams); // Check that the stream generators performed the expected actions - debug_assert_eq!(target.len() % 2, 0); + debug_assert!(target.len().is_multiple_of(2)); let half_len = target.len() / 2; let min_pairs_per_stream = half_len / expected_streams; let mut actual_subnormals = 0; @@ -1197,7 +1197,7 @@ pub(crate) mod tests { // Check that the data element generation actions look correct let mut expected_left_idx = stream_idx; - debug_assert_eq!(other_actions.len() % 2, 0); + debug_assert!(other_actions.len().is_multiple_of(2)); for action_pair in other_actions.chunks_exact(2) { let expected_indices = [expected_left_idx, expected_left_idx + half_len]; for (action, expected_idx) in action_pair.iter().zip(expected_indices) { diff --git a/common/src/operations.rs b/common/src/operations.rs index 485c931..4867e58 100644 --- a/common/src/operations.rs +++ b/common/src/operations.rs @@ -271,7 +271,7 @@ pub fn integrate_pairs, const ILP: usize>( ) { let inputs = inputs.as_ref(); let inputs_len = inputs.len(); - assert_eq!(inputs_len % 2, 0); + assert!(inputs_len.is_multiple_of(2)); let (left, right) = inputs.split_at(inputs_len / 2); if I::KIND.is_reused() { for (&left_elem, &right_elem) in left.iter().zip(right) { @@ -830,7 +830,11 @@ pub mod test_utils { // Instantiate benchmark, checking for invalid input length let input_len_granularity = 1 + (pairwise as usize); - if input_storage.as_ref().len() % input_len_granularity != 0 { + if !input_storage + .as_ref() + .len() + .is_multiple_of(input_len_granularity) + { return assert_panics(AssertUnwindSafe(|| { Op::make_benchmark::<_, ILP>(input_storage) })); @@ -860,7 +864,7 @@ pub mod test_utils { let input_is_reused = Storage::KIND.is_reused(); // Set up a benchmark... - if pairwise && input_len % 2 != 0 { + if pairwise && !input_len.is_multiple_of(2) { return assert_panics(AssertUnwindSafe(|| { Op::make_benchmark::<_, ILP>(input_storage) })); @@ -902,7 +906,7 @@ pub mod test_utils { std::array::from_fn(input_is_normal) }; if pairwise { - debug_assert_eq!(input_len % 2, 0); + debug_assert!(input_len.is_multiple_of(2)); let first_right_input = input_len / 2; if input_is_reused { first_input_normal = std::array::from_fn(|acc_idx| { @@ -1409,7 +1413,7 @@ mod tests { // Test without reused input hiding let integrate_pairs = super::integrate_pairs::; - if initial_inputs.len() % 2 != 0 { + if !initial_inputs.len().is_multiple_of(2) { return assert_panics(AssertUnwindSafe(|| { integrate_pairs(&mut accumulators, hide_accumulators, &inputs, iter) })); diff --git a/fma_addend/src/lib.rs b/fma_addend/src/lib.rs index 3690c57..eedeb0b 100644 --- a/fma_addend/src/lib.rs +++ b/fma_addend/src/lib.rs @@ -30,9 +30,8 @@ impl Operation for FmaAddend { fn make_benchmark( input_storage: Storage, ) -> impl Benchmark { - assert_eq!( - input_storage.as_ref().len() % 2, - 0, + assert!( + input_storage.as_ref().len().is_multiple_of(2), "Invalid test input length" ); FmaAddendBenchmark::<_, ILP> { @@ -384,7 +383,7 @@ mod tests { prop_assert_eq!(&stream.state, &FmaAddendState::Unconstrained); // Simulate the creation of a dataset, checking behavior - debug_assert_eq!(target.len() % 2, 0); + debug_assert!(target.len().is_multiple_of(2)); let half_len = target.len() / 2; let stream_indices = ((0..half_len).skip(stream_idx).step_by(num_streams)) @@ -458,7 +457,7 @@ mod tests { // Generate the inputs let mut rng = rand::thread_rng(); let target_len = target.len(); - if num_subnormals > target_len || target_len % 2 != 0 { + if num_subnormals > target_len || !target_len.is_multiple_of(2) { return assert_panics(AssertUnwindSafe(|| { generate_inputs::<_, ILP>(num_subnormals, &mut target, &mut rng, true, multiplier); })); diff --git a/fma_full_max/src/lib.rs b/fma_full_max/src/lib.rs index 5d667ce..3f4ede2 100644 --- a/fma_full_max/src/lib.rs +++ b/fma_full_max/src/lib.rs @@ -31,9 +31,8 @@ impl Operation for FmaFullMax { fn make_benchmark( input_storage: Storage, ) -> impl Benchmark { - assert_eq!( - input_storage.as_ref().len() % 2, - 0, + assert!( + input_storage.as_ref().len().is_multiple_of(2), "Invalid test input length" ); FmaFullMaxBenchmark::<_, ILP> { @@ -507,7 +506,7 @@ mod tests { prop_assert_eq!(&stream.state, &FmaFullMaxState::Narrow); // Simulate the creation of a dataset, checking behavior - debug_assert_eq!(target.len() % 2, 0); + debug_assert!(target.len().is_multiple_of(2)); let half_len = target.len() / 2; let stream_indices = ((0..half_len).skip(stream_idx).step_by(num_streams)) @@ -690,7 +689,7 @@ mod tests { // Generate the inputs let mut rng = rand::thread_rng(); let target_len = target.len(); - if num_subnormals > target_len || target_len % 2 != 0 { + if num_subnormals > target_len || !target_len.is_multiple_of(2) { return assert_panics(AssertUnwindSafe(|| { generate_inputs::(num_subnormals, &mut target, &mut rng, true); })); diff --git a/rust-toolchain b/rust-toolchain index 537ad6c..45c0abf 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2024-12-06 \ No newline at end of file +nightly-2025-04-25