| 1 | //! Advanced Vector Extensions (AVX) |
| 2 | //! |
| 3 | //! The references are: |
| 4 | //! |
| 5 | //! - [Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2: |
| 6 | //! Instruction Set Reference, A-Z][intel64_ref]. - [AMD64 Architecture |
| 7 | //! Programmer's Manual, Volume 3: General-Purpose and System |
| 8 | //! Instructions][amd64_ref]. |
| 9 | //! |
| 10 | //! [Wikipedia][wiki] provides a quick overview of the instructions available. |
| 11 | //! |
| 12 | //! [intel64_ref]: http://www.intel.de/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf |
| 13 | //! [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf |
| 14 | //! [wiki]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions |
| 15 | |
| 16 | use crate::{core_arch::x86::*, mem::transmute}; |
| 17 | |
| 18 | /// Copies `a` to result, and insert the 64-bit integer `i` into result |
| 19 | /// at the location specified by `index`. |
| 20 | /// |
| 21 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_insert_epi64) |
| 22 | #[inline ] |
| 23 | #[rustc_legacy_const_generics (2)] |
| 24 | #[target_feature (enable = "avx" )] |
| 25 | // This intrinsic has no corresponding instruction. |
| 26 | #[stable (feature = "simd_x86" , since = "1.27.0" )] |
| 27 | pub fn _mm256_insert_epi64<const INDEX: i32>(a: __m256i, i: i64) -> __m256i { |
| 28 | static_assert_uimm_bits!(INDEX, 2); |
| 29 | unsafe { transmute(src:simd_insert!(a.as_i64x4(), INDEX as u32, i)) } |
| 30 | } |
| 31 | |
| 32 | /// Extracts a 64-bit integer from `a`, selected with `INDEX`. |
| 33 | /// |
| 34 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_extract_epi64) |
| 35 | #[inline ] |
| 36 | #[target_feature (enable = "avx" )] |
| 37 | #[rustc_legacy_const_generics (1)] |
| 38 | // This intrinsic has no corresponding instruction. |
| 39 | #[stable (feature = "simd_x86" , since = "1.27.0" )] |
| 40 | pub fn _mm256_extract_epi64<const INDEX: i32>(a: __m256i) -> i64 { |
| 41 | static_assert_uimm_bits!(INDEX, 2); |
| 42 | unsafe { simd_extract!(a.as_i64x4(), INDEX as u32) } |
| 43 | } |
| 44 | |
| 45 | #[cfg (test)] |
| 46 | mod tests { |
| 47 | use stdarch_test::simd_test; |
| 48 | |
| 49 | use crate::core_arch::arch::x86_64::*; |
| 50 | |
| 51 | #[simd_test(enable = "avx" )] |
| 52 | unsafe fn test_mm256_insert_epi64() { |
| 53 | let a = _mm256_setr_epi64x(1, 2, 3, 4); |
| 54 | let r = _mm256_insert_epi64::<3>(a, 0); |
| 55 | let e = _mm256_setr_epi64x(1, 2, 3, 0); |
| 56 | assert_eq_m256i(r, e); |
| 57 | } |
| 58 | |
| 59 | #[simd_test(enable = "avx" )] |
| 60 | unsafe fn test_mm256_extract_epi64() { |
| 61 | let a = _mm256_setr_epi64x(0, 1, 2, 3); |
| 62 | let r = _mm256_extract_epi64::<3>(a); |
| 63 | assert_eq!(r, 3); |
| 64 | } |
| 65 | } |
| 66 | |