Last active
March 19, 2023 18:38
-
-
Save samueleresca/6fb753f9b90f0d3e32af3e687ec19953 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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