mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
* Fix Max_array.rs iter_mut is not necessary The previous example failed to compile as `y` was not borrowed as a mutable reference but used to produce a mutable iterator. Changing from `iter_mut()` to `iter()` resolved this issue. * Fix Max_array_(Optimized).rs The previous example failed to compile as `y` was not borrowed as a mutable reference but used to produce a mutable iterator. Changing from `iter_mut()` to `iter()` resolved this issue.
11 lines
312 B
Rust
11 lines
312 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()) {
|
|
*x = if *y > *x { *y } else { *x };
|
|
}
|
|
}
|