Skip to content

Commit

Permalink
convert _mm_extract_epi64 to const generics
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Mar 5, 2021
1 parent 4f5f0de commit 29df0de
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions crates/core_arch/src/x86_64/sse41.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@ use crate::{
#[cfg(test)]
use stdarch_test::assert_instr;

/// Extracts an 64-bit integer from `a` selected with `imm8`
/// Extracts an 64-bit integer from `a` selected with `IMM1`
///
/// [Intel's documentation](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_extract_epi64)
#[inline]
#[target_feature(enable = "sse4.1")]
#[cfg_attr(all(test, not(target_os = "windows")), assert_instr(pextrq, imm8 = 1))]
#[rustc_args_required_const(1)]
#[cfg_attr(all(test, not(target_os = "windows")), assert_instr(pextrq, IMM1 = 1))]
#[rustc_legacy_const_generics(1)]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm_extract_epi64(a: __m128i, imm8: i32) -> i64 {
let a = a.as_i64x2();
match imm8 & 1 {
0 => simd_extract(a, 0),
_ => simd_extract(a, 1),
}
pub unsafe fn _mm_extract_epi64<const IMM1: i32>(a: __m128i) -> i64 {
static_assert_imm1!(IMM1);
simd_extract(a.as_i64x2(), IMM1 as u32)
}

/// Returns a copy of `a` with the 64-bit integer from `i` inserted at a
Expand Down Expand Up @@ -49,10 +46,10 @@ mod tests {
#[simd_test(enable = "sse4.1")]
unsafe fn test_mm_extract_epi64() {
let a = _mm_setr_epi64x(0, 1);
let r = _mm_extract_epi64(a, 1);
assert_eq!(r, 1);
let r = _mm_extract_epi64(a, 3);
let r = _mm_extract_epi64::<1>(a);
assert_eq!(r, 1);
let r = _mm_extract_epi64::<0>(a);
assert_eq!(r, 0);
}

#[simd_test(enable = "sse4.1")]
Expand Down

0 comments on commit 29df0de

Please sign in to comment.