mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Increasing the SIMD size improves the vectorization possibilities
Change the simd-wide-sum.rs to pass the LLVM main branching test.
This commit is contained in:
parent
cbce15c617
commit
d30f210e5d
@ -11,14 +11,14 @@
|
||||
#![feature(portable_simd)]
|
||||
|
||||
use std::simd::{Simd, SimdUint};
|
||||
const N: usize = 8;
|
||||
const N: usize = 16;
|
||||
|
||||
#[no_mangle]
|
||||
// CHECK-LABEL: @wider_reduce_simd
|
||||
pub fn wider_reduce_simd(x: Simd<u8, N>) -> u16 {
|
||||
// CHECK: zext <8 x i8>
|
||||
// CHECK-SAME: to <8 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v8i16(<8 x i16>
|
||||
// CHECK: zext <16 x i8>
|
||||
// CHECK-SAME: to <16 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v16i16(<16 x i16>
|
||||
let x: Simd<u16, N> = x.cast();
|
||||
x.reduce_sum()
|
||||
}
|
||||
@ -26,9 +26,9 @@ pub fn wider_reduce_simd(x: Simd<u8, N>) -> u16 {
|
||||
#[no_mangle]
|
||||
// CHECK-LABEL: @wider_reduce_loop
|
||||
pub fn wider_reduce_loop(x: Simd<u8, N>) -> u16 {
|
||||
// CHECK: zext <8 x i8>
|
||||
// CHECK-SAME: to <8 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v8i16(<8 x i16>
|
||||
// CHECK: zext <16 x i8>
|
||||
// CHECK-SAME: to <16 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v16i16(<16 x i16>
|
||||
let mut sum = 0_u16;
|
||||
for i in 0..N {
|
||||
sum += u16::from(x[i]);
|
||||
@ -39,9 +39,9 @@ pub fn wider_reduce_loop(x: Simd<u8, N>) -> u16 {
|
||||
#[no_mangle]
|
||||
// CHECK-LABEL: @wider_reduce_iter
|
||||
pub fn wider_reduce_iter(x: Simd<u8, N>) -> u16 {
|
||||
// CHECK: zext <8 x i8>
|
||||
// CHECK-SAME: to <8 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v8i16(<8 x i16>
|
||||
// CHECK: zext <16 x i8>
|
||||
// CHECK-SAME: to <16 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v16i16(<16 x i16>
|
||||
x.as_array().iter().copied().map(u16::from).sum()
|
||||
}
|
||||
|
||||
@ -52,8 +52,8 @@ pub fn wider_reduce_iter(x: Simd<u8, N>) -> u16 {
|
||||
#[no_mangle]
|
||||
// CHECK-LABEL: @wider_reduce_into_iter
|
||||
pub fn wider_reduce_into_iter(x: Simd<u8, N>) -> u16 {
|
||||
// CHECK: zext <8 x i8>
|
||||
// CHECK-SAME: to <8 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v8i16(<8 x i16>
|
||||
// CHECK: zext <16 x i8>
|
||||
// CHECK-SAME: to <16 x i16>
|
||||
// CHECK: call i16 @llvm.vector.reduce.add.v16i16(<16 x i16>
|
||||
x.to_array().into_iter().map(u16::from).sum()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user