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