Files
compiler-explorer/examples/rust/Sum_over_array_(Unreachable).rs
Patrick Quist ce64888b7e More rust examples (#2482)
* more rust examples

* Update default.rs
2021-03-11 17:30:03 +01:00

10 lines
281 B
Rust

// Compile with -C opt-level=3 -C target-cpu=native to see autovectorization
// assumes input's length is a multiple of 64
pub fn sum_array(input: &[i32]) -> i32 {
if input.len() & 63 != 0 {
unsafe { std::hint::unreachable_unchecked() }
}
input.iter().sum()
}