Skip to content

Instantly share code, notes, and snippets.

@samueleresca
Last active March 19, 2023 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueleresca/6fb753f9b90f0d3e32af3e687ec19953 to your computer and use it in GitHub Desktop.
Save samueleresca/6fb753f9b90f0d3e32af3e687ec19953 to your computer and use it in GitHub Desktop.
/// Returns an initialized matrix. The matrix is initialized in a standard way.
///
/// # Arguments
///
/// * `n` - The dimension of the matrix.
pub fn standard_initialize(n: usize) -> Vec<Vec<i32>> {
let mut data = vec![vec![0i32; n]; n];
for r in 0..n {
for c in 0..n {
data[r][c] = c as i32;
}
}
data
}
use std::arch::x86_64::_mm_stream_si32;
/// Returns an initialized matrix. The matrix is initialized using the *non-temporal* write operations.
///
/// The new content is directly written to the memory.
///
/// # Arguments
///
/// * `n` - The dimension of the matrix.
pub fn nocache_initialize(n: usize) -> Vec<Vec<i32>> {
let mut data = vec![vec![0i32; n]; n];
for r in 0..n {
let row = data[r].as_mut_ptr();
for c in 0..n {
unsafe {
_mm_stream_si32(row.add(c), c as i32);
}
}
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment