1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! 高级 Vector 扩展 2 (AVX)
//!
//! AVX2 将大多数 AVX 命令扩展到 256 位宽的 vector 寄存器并添加了 [FMA](https://en.wikipedia.org/wiki/Fused_multiply-accumulate)。
//!
//! 引用的是:
//!
//! - [英特尔 64 位和 IA-32 架构软件开发人员手册第 2 卷:
//!   指令集引用,AZ][intel64_ref]。
//! - [AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions][amd64_ref].
//!
//! 维基百科的 [AVX][wiki_avx] 和 [FMA][wiki_fma] 页面提供了对可用说明的快速概述。
//!
//! [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
//! [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf
//! [wiki_avx]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
//! [wiki_fma]: https://en.wikipedia.org/wiki/Fused_multiply-accumulate
//!
//!
//!

use crate::core_arch::{simd_llvm::*, x86::*};

/// 从 `a` 中提取一个 64 位整数,用 `INDEX` 选择。
///
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_extract_epi64)
#[inline]
#[target_feature(enable = "avx2")]
#[rustc_legacy_const_generics(1)]
// 此内部函数没有相应的指令。
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm256_extract_epi64<const INDEX: i32>(a: __m256i) -> i64 {
    static_assert_uimm_bits!(INDEX, 2);
    simd_extract(a.as_i64x4(), INDEX as u32)
}

#[cfg(test)]
mod tests {
    use crate::core_arch::arch::x86_64::*;
    use stdarch_test::simd_test;

    #[simd_test(enable = "avx2")]
    unsafe fn test_mm256_extract_epi64() {
        let a = _mm256_setr_epi64x(0, 1, 2, 3);
        let r = _mm256_extract_epi64::<3>(a);
        assert_eq!(r, 3);
    }
}