diff --git a/cache_utils/src/bin/cache_info.rs b/cache_utils/src/bin/cache_info.rs index bdf1163..d7df9de 100644 --- a/cache_utils/src/bin/cache_info.rs +++ b/cache_utils/src/bin/cache_info.rs @@ -16,6 +16,7 @@ pub fn main() { ); println!("{:?}", slicing.image((1 << 12) - 1)); println!("{:?}", slicing.kernel_compl_basis((1 << 12) - 1)); + println!("{:?}", slicing.image_antecedent((1 << 12) - 1)); } } } diff --git a/cache_utils/src/complex_addressing.rs b/cache_utils/src/complex_addressing.rs index 34fce80..bd22968 100644 --- a/cache_utils/src/complex_addressing.rs +++ b/cache_utils/src/complex_addressing.rs @@ -3,9 +3,13 @@ use crate::complex_addressing::CacheSlicing::{ }; use cpuid::{CPUVendor, MicroArchitecture}; +extern crate alloc; + #[cfg(feature = "no_std")] use alloc::collections::VecDeque; #[cfg(feature = "no_std")] +use alloc::vec::Vec; +#[cfg(feature = "no_std")] use hashbrown::HashMap; #[cfg(feature = "no_std")] use hashbrown::HashSet; @@ -229,4 +233,26 @@ impl CacheSlicing { _ => None, } } + pub fn image_antecedent(&self, mask: usize) -> Option> { + match self { + ComplexAddressing(_functions) => { + let matrix = self.pivot(mask); + + let mut result = HashMap::::new(); + result.insert(0, 0); + + for (slice_u, addr_u) in matrix { + if (slice_u != 0) { + let mut tmp = HashMap::new(); + for (slice_v, addr_v) in &result { + tmp.insert(slice_v ^ slice_u, addr_v ^ addr_u); + } + result.extend(tmp); + } + } + Some(result) + } + _ => None, + } + } }