blob: 1e57c795e10cd0682cfae6a20ca83c94672f9470 [file] [log] [blame] [raw]
// 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 {
let len = input.len();
let input = input.as_ptr();
if len & 63 != 0 {
unsafe { std::hint::unreachable_unchecked() }
}
let mut sum = 0;
for i in 0..len {
sum += unsafe { *input.add(i) };
}
sum
}