Files
compiler-explorer/examples/rust/Sum_over_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

9 lines
209 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 sum_array(input: &Aligned<[i32]>) -> i32 {
input.0.iter().sum()
}