Files
compiler-explorer/examples/rust/Max_array_(Optimized).rs
T
Christopher Serr 91a35e65d4 Improve the Rust examples
This commit
 - formats the Rust examples idiomatically
 - uses idiomatic code
 - uses only safe code without compromising on performance
 - makes them compile on stable
2020-03-26 23:28:49 +01:00

11 lines
316 B
Rust

// Compile with -C opt-level=3 -C target-cpu=native to see autovectorization
#[repr(align(64))]
pub struct Aligned<T: ?Sized>(T);
pub fn max_array(x: &mut Aligned<[f64; 65536]>, y: &Aligned<[f64; 65536]>) {
for (x, y) in x.0.iter_mut().zip(y.0.iter_mut()) {
*x = if *y > *x { *y } else { *x };
}
}