From 5557907098d0c9269d6d6643ead23d9877ee63ab Mon Sep 17 00:00:00 2001 From: miguel raz Date: Tue, 1 Jun 2021 15:25:56 -0500 Subject: [PATCH] rewrite unaligned slice, fix output const array --- crates/core_simd/examples/nbody.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/core_simd/examples/nbody.rs b/crates/core_simd/examples/nbody.rs index bf045737f82..4fdc0226397 100644 --- a/crates/core_simd/examples/nbody.rs +++ b/crates/core_simd/examples/nbody.rs @@ -128,7 +128,9 @@ pub struct Body { while i < N { let d2s = f64x2::from_array([(r[i] * r[i]).horizontal_sum(), (r[i + 1] * r[i + 1]).horizontal_sum()]); let dmags = f64x2::splat(dt) / (d2s * d2s.sqrt()); - dmags.write_to_slice_unaligned(&mut mag[i..]); + // dmags.write_to_slice_unaligned(&mut mag[i..]); + mag[i] = dmags[0]; + mag[i+1] = dmags[1]; i += 2; } @@ -146,6 +148,12 @@ pub struct Body { } } +// #[inline] +// pub unsafe fn write_to_slice_unaligned(slice: &mut SimdF64::) { +// let target_ptr = slice.get_unchecked_mut(0) as *mut f64x2; +// *(target_ptr as *mut f64x2) = SimdF64; +// } + pub fn run(n: usize) -> (f64, f64) { let mut bodies = BODIES; offset_momentum(&mut bodies); @@ -158,7 +166,7 @@ pub fn run(n: usize) -> (f64, f64) { (energy_before, energy_after) } -const OUTPUT: Vec = vec![-0.169075164, -0.169087605]; +const OUTPUT: [f64; 2] = [-0.169075164, -0.169087605]; #[cfg(test)] mod tests { #[test] @@ -172,6 +180,8 @@ fn test() { } } } + + fn main() { //let n: usize = std::env::args() //.nth(1) -- 2.44.0