Skip to content

Commit 0944bd4

Browse files
committed
use simd_extract_dyn for extract
1 parent c935872 commit 0944bd4

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

crates/core_arch/src/powerpc/altivec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,7 @@ mod tests {
47404740
for off in 0..16 {
47414741
let val: u8x16 = transmute(vec_xl(0, (pat.as_ptr() as *const u8).offset(off)));
47424742
for i in 0..16 {
4743-
let v = val.extract(i);
4743+
let v = val.extract_dyn(i);
47444744
assert_eq!(off as usize + i, v as usize);
47454745
}
47464746
}
@@ -4795,7 +4795,7 @@ mod tests {
47954795
)];
47964796
for off in 0..16 {
47974797
let v: u8x16 = transmute(vec_lde(off, pat.as_ptr() as *const u8));
4798-
assert_eq!(off as u8, v.extract(off as _));
4798+
assert_eq!(off as u8, v.extract_dyn(off as _));
47994799
}
48004800
}
48014801

@@ -4804,7 +4804,7 @@ mod tests {
48044804
let pat = [u16x8::new(0, 1, 2, 3, 4, 5, 6, 7)];
48054805
for off in 0..8 {
48064806
let v: u16x8 = transmute(vec_lde(off * 2, pat.as_ptr() as *const u16));
4807-
assert_eq!(off as u16, v.extract(off as _));
4807+
assert_eq!(off as u16, v.extract_dyn(off as _));
48084808
}
48094809
}
48104810

@@ -4813,7 +4813,7 @@ mod tests {
48134813
let pat = [u32x4::new(0, 1, 2, 3)];
48144814
for off in 0..4 {
48154815
let v: u32x4 = transmute(vec_lde(off * 4, pat.as_ptr() as *const u32));
4816-
assert_eq!(off as u32, v.extract(off as _));
4816+
assert_eq!(off as u32, v.extract_dyn(off as _));
48174817
}
48184818
}
48194819

crates/core_arch/src/simd.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ impl<T: SimdElement, const N: usize> Simd<T, N> {
6060
unsafe { simd_shuffle!(one, one, [0; N]) }
6161
}
6262

63-
/// Extract the element at position `index`.
64-
/// `index` is not a constant so this is not efficient!
65-
/// Use for testing only.
66-
// FIXME: Workaround rust@60637
67-
#[inline(always)]
68-
pub(crate) const fn extract(&self, index: usize) -> T {
69-
self.as_array()[index]
63+
/// Extract the element at position `index`. Note that `index` is not a constant so this
64+
/// operation is not efficient on most platforms. Use for testing only.
65+
#[inline]
66+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
67+
pub(crate) const fn extract_dyn(&self, index: usize) -> T {
68+
assert!(index < N);
69+
// SAFETY: self is a vector, T its element type.
70+
unsafe { crate::intrinsics::simd::simd_extract_dyn(*self, index as u32) }
7071
}
7172

7273
#[inline]

crates/core_arch/src/x86/test.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,38 +78,45 @@ pub(crate) const fn assert_eq_m512h(a: __m512h, b: __m512h) {
7878
}
7979

8080
#[target_feature(enable = "sse2")]
81+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
8182
pub(crate) const fn get_m128d(a: __m128d, idx: usize) -> f64 {
82-
a.as_f64x2().extract(idx)
83+
a.as_f64x2().extract_dyn(idx)
8384
}
8485

8586
#[target_feature(enable = "sse")]
87+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
8688
pub(crate) const fn get_m128(a: __m128, idx: usize) -> f32 {
87-
a.as_f32x4().extract(idx)
89+
a.as_f32x4().extract_dyn(idx)
8890
}
8991

9092
#[target_feature(enable = "avx")]
93+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
9194
pub(crate) const fn get_m256d(a: __m256d, idx: usize) -> f64 {
92-
a.as_f64x4().extract(idx)
95+
a.as_f64x4().extract_dyn(idx)
9396
}
9497

9598
#[target_feature(enable = "avx")]
99+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
96100
pub(crate) const fn get_m256(a: __m256, idx: usize) -> f32 {
97-
a.as_f32x8().extract(idx)
101+
a.as_f32x8().extract_dyn(idx)
98102
}
99103

100104
#[target_feature(enable = "avx512f")]
105+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
101106
pub(crate) const fn get_m512(a: __m512, idx: usize) -> f32 {
102-
a.as_f32x16().extract(idx)
107+
a.as_f32x16().extract_dyn(idx)
103108
}
104109

105110
#[target_feature(enable = "avx512f")]
111+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
106112
pub(crate) const fn get_m512d(a: __m512d, idx: usize) -> f64 {
107-
a.as_f64x8().extract(idx)
113+
a.as_f64x8().extract_dyn(idx)
108114
}
109115

110116
#[target_feature(enable = "avx512f")]
117+
#[rustc_const_unstable(feature = "stdarch_const_helpers", issue = "none")]
111118
pub(crate) const fn get_m512i(a: __m512i, idx: usize) -> i64 {
112-
a.as_i64x8().extract(idx)
119+
a.as_i64x8().extract_dyn(idx)
113120
}
114121

115122
// not actually an intrinsic but useful in various tests as we ported from

0 commit comments

Comments
 (0)