Skip to content

Commit 29df0de

Browse files
committed
convert _mm_extract_epi64 to const generics
1 parent 4f5f0de commit 29df0de

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

crates/core_arch/src/x86_64/sse41.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ use crate::{
88
#[cfg(test)]
99
use stdarch_test::assert_instr;
1010

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

2724
/// Returns a copy of `a` with the 64-bit integer from `i` inserted at a
@@ -49,10 +46,10 @@ mod tests {
4946
#[simd_test(enable = "sse4.1")]
5047
unsafe fn test_mm_extract_epi64() {
5148
let a = _mm_setr_epi64x(0, 1);
52-
let r = _mm_extract_epi64(a, 1);
53-
assert_eq!(r, 1);
54-
let r = _mm_extract_epi64(a, 3);
49+
let r = _mm_extract_epi64::<1>(a);
5550
assert_eq!(r, 1);
51+
let r = _mm_extract_epi64::<0>(a);
52+
assert_eq!(r, 0);
5653
}
5754

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

0 commit comments

Comments
 (0)