Skip to content

Commit fa92da2

Browse files
committed
Add more tests (simd_shuffle/simd_swizzle)
1 parent 6f1569d commit fa92da2

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

library/kani/src/models/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ mod test {
223223
let bitmask = mask.to_bitmask();
224224
assert_eq!(bitmask, 0b1010);
225225

226-
let kani_mask = unsafe { u64::from(kani_intrinsic::simd_bitmask::<_, u8, u32, 4>(mask.clone())) };
226+
let kani_mask =
227+
unsafe { u64::from(kani_intrinsic::simd_bitmask::<_, u8, u32, 4>(mask.clone())) };
227228
assert_eq!(kani_mask, bitmask);
228229
}
229-
230230
}

tests/kani/Intrinsics/SIMD/Shuffle/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ fn main() {
4545
assert!(c == i64x4(2, 4, 6, 8));
4646
}
4747
}
48+
49+
#[kani::proof]
50+
fn check_shuffle() {
51+
{
52+
let y = i64x2(0, 1);
53+
let z = i64x2(1, 2);
54+
const I: [u32; 4] = [1, 2, 0, 3];
55+
let _x: i64x4 = unsafe { simd_shuffle(y, z, I) };
56+
}
57+
}

tests/kani/SIMD/portable_simd.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ fn check_resize() {
2929
let x = u32x4::from_array([0, 1, 2, 3]);
3030
assert_eq!(x.resize::<8>(9).to_array(), [0, 1, 2, 3, 9, 9, 9, 9]);
3131
assert_eq!(x.resize::<2>(9).to_array(), [0, 1]);
32-
3332
}

tests/kani/SIMD/swizzle.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
//! Ensure we can safely swizzle between SIMD types of different sizes.
5+
#![feature(portable_simd)]
6+
7+
use std::simd::{simd_swizzle, u32x4, u32x8};
8+
9+
#[kani::proof]
10+
fn harness_from_u32x4_to_u32x4() {
11+
let a = u32x4::from_array([0, 1, 2, 3]);
12+
let b = u32x4::from_array([4, 5, 6, 7]);
13+
let r: u32x4 = simd_swizzle!(a, b, [0, 1, 6, 7]);
14+
assert_eq!(r.to_array(), [0, 1, 6, 7]);
15+
}
16+
17+
#[kani::proof]
18+
fn harness_from_u32x4_to_u32x8() {
19+
let a = u32x4::from_array([0, 1, 2, 3]);
20+
let b = u32x4::from_array([4, 5, 6, 7]);
21+
let r: u32x8 = simd_swizzle!(a, b, [0, 1, 2, 3, 4, 5, 6, 7]);
22+
assert_eq!(r.to_array(), [0, 1, 2, 3, 4, 5, 6, 7]);
23+
}
24+
25+
#[kani::proof]
26+
fn harness_from_u32x8_to_u32x4() {
27+
let a = u32x8::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
28+
let b = u32x8::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
29+
let r: u32x4 = simd_swizzle!(a, b, [0, 1, 2, 3]);
30+
assert_eq!(r.to_array(), [0, 1, 2, 3]);
31+
}

0 commit comments

Comments
 (0)