Skip to content

Commit

Permalink
Add more tests (simd_shuffle/simd_swizzle)
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed Dec 7, 2023
1 parent 6f1569d commit fa92da2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions library/kani/src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ mod test {
let bitmask = mask.to_bitmask();
assert_eq!(bitmask, 0b1010);

let kani_mask = unsafe { u64::from(kani_intrinsic::simd_bitmask::<_, u8, u32, 4>(mask.clone())) };
let kani_mask =
unsafe { u64::from(kani_intrinsic::simd_bitmask::<_, u8, u32, 4>(mask.clone())) };
assert_eq!(kani_mask, bitmask);
}

}
10 changes: 10 additions & 0 deletions tests/kani/Intrinsics/SIMD/Shuffle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ fn main() {
assert!(c == i64x4(2, 4, 6, 8));
}
}

#[kani::proof]
fn check_shuffle() {
{
let y = i64x2(0, 1);
let z = i64x2(1, 2);
const I: [u32; 4] = [1, 2, 0, 3];
let _x: i64x4 = unsafe { simd_shuffle(y, z, I) };
}
}
1 change: 0 additions & 1 deletion tests/kani/SIMD/portable_simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ fn check_resize() {
let x = u32x4::from_array([0, 1, 2, 3]);
assert_eq!(x.resize::<8>(9).to_array(), [0, 1, 2, 3, 9, 9, 9, 9]);
assert_eq!(x.resize::<2>(9).to_array(), [0, 1]);

}
31 changes: 31 additions & 0 deletions tests/kani/SIMD/swizzle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Ensure we can safely swizzle between SIMD types of different sizes.
#![feature(portable_simd)]

use std::simd::{simd_swizzle, u32x4, u32x8};

#[kani::proof]
fn harness_from_u32x4_to_u32x4() {
let a = u32x4::from_array([0, 1, 2, 3]);
let b = u32x4::from_array([4, 5, 6, 7]);
let r: u32x4 = simd_swizzle!(a, b, [0, 1, 6, 7]);
assert_eq!(r.to_array(), [0, 1, 6, 7]);
}

#[kani::proof]
fn harness_from_u32x4_to_u32x8() {
let a = u32x4::from_array([0, 1, 2, 3]);
let b = u32x4::from_array([4, 5, 6, 7]);
let r: u32x8 = simd_swizzle!(a, b, [0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(r.to_array(), [0, 1, 2, 3, 4, 5, 6, 7]);
}

#[kani::proof]
fn harness_from_u32x8_to_u32x4() {
let a = u32x8::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
let b = u32x8::from_array([0, 1, 2, 3, 4, 5, 6, 7]);
let r: u32x4 = simd_swizzle!(a, b, [0, 1, 2, 3]);
assert_eq!(r.to_array(), [0, 1, 2, 3]);
}

0 comments on commit fa92da2

Please sign in to comment.