Skip to content

Commit

Permalink
avoid using simd_extract in SimdTy::extract (since the index is not a…
Browse files Browse the repository at this point in the history
… constant there)
  • Loading branch information
RalfJung authored and Amanieu committed Feb 17, 2024
1 parent 0075e68 commit a79a8de
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions crates/core_arch/src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,28 @@ macro_rules! simd_ty {
#[inline(always)]
pub(crate) const fn splat(value: $ety) -> Self {
$id($({
// We want this to be repeated for each element.
// So we need to use `elem_name` in a `$(...)`.
// But we don't actually need that name for anything so we use a dummy struct.
#[allow(non_camel_case_types, dead_code)]
struct $elem_name;
value
}),*)
}

/// Extract the element at position `index`.
/// `index` is not a constant so this is not efficient!
/// Use for testing only.
// FIXME: Workaround rust@60637
#[inline(always)]
pub(crate) fn extract(self, index: usize) -> $ety {
// Here we assume that there is no padding.
let len = crate::mem::size_of::<Self>() / crate::mem::size_of::<$ety>();
assert!(index < len);
// Now that we know this is in-bounds, use pointer arithmetic to access the right element.
let self_ptr = &self as *const Self as *const $ety;
unsafe {
crate::core_arch::simd_llvm::simd_extract(self, index as u32)
self_ptr.add(index).read()
}
}
}
Expand Down Expand Up @@ -62,15 +73,6 @@ macro_rules! simd_m_ty {
Self::bool_to_internal(value)
}),*)
}

// FIXME: Workaround rust@60637
#[inline(always)]
pub(crate) fn extract(self, index: usize) -> bool {
let r: $ety = unsafe {
crate::core_arch::simd_llvm::simd_extract(self, index as u32)
};
r != 0
}
}
}
}
Expand Down

0 comments on commit a79a8de

Please sign in to comment.