Skip to content

Commit

Permalink
portable-simd: add test for non-power-of-2 bitmask
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jun 8, 2024
1 parent c51b733 commit 6e7119d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/pass/intrinsics/portable-simd.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@compile-flags: -Zmiri-strict-provenance

Check failure on line 1 in tests/pass/intrinsics/portable-simd.rs

View workflow job for this annotation

GitHub Actions / build (macos-14, aarch64-apple-darwin)

pass test got exit status: 1

no message

Check failure on line 1 in tests/pass/intrinsics/portable-simd.rs

View workflow job for this annotation

GitHub Actions / build (macos-14, aarch64-apple-darwin)

test generated output

you likely need to bless the tests with `./miri test --bless`
#![feature(portable_simd, adt_const_params, core_intrinsics)]
#![feature(portable_simd, adt_const_params, core_intrinsics, repr_simd)]
#![allow(incomplete_features, internal_features)]
use std::intrinsics::simd as intrinsics;
use std::ptr;
Expand Down Expand Up @@ -318,6 +318,34 @@ fn simd_mask() {
assert_eq!(selected1, i32x4::from_array([0, 0, 0, 1]));
assert_eq!(selected2, selected1);
}

// Non-power-of-2 multi-byte mask.
#[repr(simd, packed)]
#[allow(non_camel_case_types)]
#[derive(Debug, PartialEq)]
struct i32x10(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32);
impl i32x10 {
fn splat(x: i32) -> Self {
Self(x, x, x, x, x, x, x, x, x, x)
}
fn from_array(a: [i32; 10]) -> Self {
unsafe { std::mem::transmute(a) }
}
}
unsafe {
let selected1 = simd_select_bitmask::<u16, _>(
if cfg!(target_endian = "little") { 0b0101001001 } else { 0b1001001010 },
i32x10::splat(1), // yes
i32x10::splat(0), // no
);
let selected2 = simd_select_bitmask::<[u8; 2], _>(

Check failure on line 341 in tests/pass/intrinsics/portable-simd.rs

View workflow job for this annotation

GitHub Actions / build (macos-14, aarch64-apple-darwin)

Unmatched diagnostics

Error: Undefined Behavior: a SIMD bitmask less than 8 bits long must be filled with 0s for the remaining bits
if cfg!(target_endian = "little") { [0b01001001, 0b01] } else { [0b10010010, 0b10] },
i32x10::splat(1), // yes
i32x10::splat(0), // no
);
assert_eq!(selected1, i32x10::from_array([1, 0, 0, 1, 0, 0, 1, 0, 1, 0]));
assert_eq!(selected2, selected1);
}
}

fn simd_cast() {
Expand Down

0 comments on commit 6e7119d

Please sign in to comment.