Skip to content

Commit

Permalink
Add assembly tests for simd_reduce_all/simd_reduce_any on x86_64 and …
Browse files Browse the repository at this point in the history
…aarch64
  • Loading branch information
jhorstmann committed Feb 28, 2023
1 parent 55ca959 commit b8b2b8d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/assembly/aarch64-simd-mask-reduce.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// verify that simd mask reductions do not introduce additional bit shift operations

// assembly-output: emit-asm
// compile-flags: --crate-type=lib -O --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
// only-aarch64
// only-linux

#![feature(repr_simd, platform_intrinsics)]
#![allow(non_camel_case_types)]

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct mask8x16([i8; 16]);

extern "platform-intrinsic" {
fn simd_reduce_all<T>(x: T) -> bool;
fn simd_reduce_any<T>(x: T) -> bool;
}

// CHECK-LABEL: mask_reduce_all:
#[no_mangle]
pub unsafe fn mask_reduce_all(m: mask8x16) -> bool {
// CHECK: umaxv
simd_reduce_all(m)
}

// CHECK-LABEL: mask_reduce_any:
#[no_mangle]
pub unsafe fn mask_reduce_any(m: mask8x16) -> bool {
// CHECK: umaxv
simd_reduce_any(m)
}
33 changes: 33 additions & 0 deletions tests/assembly/x86_64-simd-mask-reduce.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// verify that simd mask reductions do not introduce additional bit shift operations

// assembly-output: emit-asm
// compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
// only-x86_64

#![feature(repr_simd, platform_intrinsics)]
#![allow(non_camel_case_types)]

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct mask8x16([i8; 16]);

extern "platform-intrinsic" {
fn simd_reduce_all<T>(x: T) -> bool;
fn simd_reduce_any<T>(x: T) -> bool;
}

// CHECK-LABEL: mask_reduce_all:
#[no_mangle]
pub unsafe fn mask_reduce_all(m: mask8x16) -> bool {
// CHECK-NOT: psllw
// CHECK: pmovmskb
simd_reduce_all(m)
}

// CHECK-LABEL: mask_reduce_any:
#[no_mangle]
pub unsafe fn mask_reduce_any(m: mask8x16) -> bool {
// CHECK-NOT: psllw
// CHECK: pmovmskb
simd_reduce_any(m)
}

0 comments on commit b8b2b8d

Please sign in to comment.