From dca5d75bb9fe9cc923e613df0a96183cd0be0c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20L=C3=A4ufer?= Date: Wed, 6 Mar 2024 16:36:41 -0500 Subject: [PATCH] ghw: optimize index calculation --- src/ghw/signals.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ghw/signals.rs b/src/ghw/signals.rs index 1dedc49..eb30d3b 100644 --- a/src/ghw/signals.rs +++ b/src/ghw/signals.rs @@ -439,11 +439,11 @@ fn set_value(bits: u32, states: States, data: &mut [u8], bit: u32, value: u8) { #[inline] fn get_data_index(bits: u32, bit: u32, states: States) -> (usize, usize) { debug_assert!(bit < bits); - let bytes = bits.div_ceil(states.bits_in_a_byte() as u32); - let mirrored = (bytes * states.bits_in_a_byte() as u32) - 1 - bit; - let index = mirrored as usize / states.bits_in_a_byte(); - let shift = (bit as usize % states.bits_in_a_byte()) * states.bits(); - (index, shift) + let bits_in_a_byte = states.bits_in_a_byte() as u32; + let bytes = bits.div_ceil(bits_in_a_byte); + let index = bytes - 1 - (bit / bits_in_a_byte); + let shift = (bit % bits_in_a_byte) * states.bits() as u32; + (index as usize, shift as usize) } #[cfg(test)]