#
core/stdarch/crates/core_arch/src/x86_64/
sse41.rs

    1//! `i686`'s Streaming SIMD Extensions 4.1 (SSE4.1)
    2
    3use crate::{core_arch::x86::*, mem::transmute};
    4
    5#[cfg(test)]
    6use stdarch_test::assert_instr;
    7
    8/// Extracts an 64-bit integer from `a` selected with `IMM1`
    9///
    10/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_extract_epi64)
    11#[inline]
    12#[target_feature(enable = "sse4.1")]
    13#[cfg_attr(test, assert_instr(pextrq, IMM1 = 1))]
    14#[rustc_legacy_const_generics(1)]
    15#[stable(feature = "simd_x86", since = "1.27.0")]
    16pub fn _mm_extract_epi64<const IMM1: i32>(a: __m128i) -> i64 {
    17    static_assert_uimm_bits!(IMM1, 1);
    18    unsafe { simd_extract!(a.as_i64x2(), IMM1 as u32) }
    19}
    20
    21/// Returns a copy of `a` with the 64-bit integer from `i` inserted at a
    22/// location specified by `IMM1`.
    23///
    24/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_insert_epi64)
    25#[inline]
    26#[target_feature(enable = "sse4.1")]
    27#[cfg_attr(test, assert_instr(pinsrq, IMM1 = 0))]
    28#[rustc_legacy_const_generics(2)]
    29#[stable(feature = "simd_x86", since = "1.27.0")]
    30pub fn _mm_insert_epi64<const IMM1: i32>(a: __m128i, i: i64) -> __m128i {
    31    static_assert_uimm_bits!(IMM1, 1);
    32    unsafe { transmute(simd_insert!(a.as_i64x2(), IMM1 as u32, i)) }
    33}
    34
    35#[cfg(test)]
    36mod tests {
    37    use crate::core_arch::arch::x86_64::*;
    38    use stdarch_test::simd_test;
    39
    40    #[simd_test(enable = "sse4.1")]
    41    unsafe fn test_mm_extract_epi64() {
    42        let a = _mm_setr_epi64x(0, 1);
    43        let r = _mm_extract_epi64::<1>(a);
    44        assert_eq!(r, 1);
    45        let r = _mm_extract_epi64::<0>(a);
    46        assert_eq!(r, 0);
    47    }
    48
    49    #[simd_test(enable = "sse4.1")]
    50    unsafe fn test_mm_insert_epi64() {
    51        let a = _mm_set1_epi64x(0);
    52        let e = _mm_setr_epi64x(0, 32);
    53        let r = _mm_insert_epi64::<1>(a, 32);
    54        assert_eq_m128i(r, e);
    55        let e = _mm_setr_epi64x(32, 0);
    56        let r = _mm_insert_epi64::<0>(a, 32);
    57        assert_eq_m128i(r, e);
    58    }
    59}