Skip to content

Commit

Permalink
Added implementation and test of _MM_SHUFFLE macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Jun 16, 2018
1 parent dda4072 commit a495882
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions coresimd/x86/sse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@ pub unsafe fn _mm_setzero_ps() -> __m128 {
__m128(0.0, 0.0, 0.0, 0.0)
}

/// A utility function for creating masks to use with Intel shuffle and permute intrinsics.
#[inline]
#[allow(non_snake_case)]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub const fn _MM_SHUFFLE(z: u32, y: u32, x: u32, w: u32) -> u32 {
(z << 6) | (y << 4) | (x << 2) | w
}

/// Shuffle packed single-precision (32-bit) floating-point elements in `a` and
/// `b` using `mask`.
///
Expand Down Expand Up @@ -3570,6 +3578,13 @@ mod tests {
assert_eq_m128(r, _mm_set1_ps(0.0));
}

#[simd_test(enable = "sse")]
unsafe fn test_mm_shuffle() {
assert_eq!(_MM_SHUFFLE(0, 1, 1, 3), 0b00_01_01_11);
assert_eq!(_MM_SHUFFLE(3, 1, 1, 0), 0b11_01_01_00);
assert_eq!(_MM_SHUFFLE(1, 2, 2, 1), 0b01_10_10_01);
}

#[simd_test(enable = "sse")]
unsafe fn test_mm_shuffle_ps() {
let a = _mm_setr_ps(1.0, 2.0, 3.0, 4.0);
Expand Down

0 comments on commit a495882

Please sign in to comment.