Skip to content

Commit 7f6f8c8

Browse files
core: add simd_reinterpret
`simd_reinterpret` is a replacement for `transmute`, specifically for use with scalable SIMD types. It is used in the tests for scalable vectors and in stdarch. Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
1 parent fb5d918 commit 7f6f8c8

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,18 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
14061406
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
14071407
}
14081408

1409+
if name == sym::simd_reinterpret {
1410+
require_simd!(ret_ty, SimdReturn);
1411+
1412+
return Ok(match args[0].val {
1413+
OperandValue::Ref(PlaceValue { llval: val, .. }) | OperandValue::Immediate(val) => {
1414+
bx.bitcast(val, llret_ty)
1415+
}
1416+
OperandValue::ZeroSized => bx.const_undef(llret_ty),
1417+
OperandValue::Pair(_, _) => todo!(),
1418+
});
1419+
}
1420+
14091421
// every intrinsic below takes a SIMD vector as its first argument
14101422
let (in_len, in_elem) = require_simd!(args[0].layout.ty, SimdInput);
14111423
let in_ty = args[0].layout.ty;

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ pub(crate) fn check_intrinsic_type(
709709
}
710710
sym::simd_cast
711711
| sym::simd_as
712+
| sym::simd_reinterpret
712713
| sym::simd_cast_ptr
713714
| sym::simd_expose_provenance
714715
| sym::simd_with_exposed_provenance => (2, 0, vec![param(0)], param(1)),

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,7 @@ symbols! {
20982098
simd_reduce_mul_unordered,
20992099
simd_reduce_or,
21002100
simd_reduce_xor,
2101+
simd_reinterpret,
21012102
simd_relaxed_fma,
21022103
simd_rem,
21032104
simd_round,

library/core/src/intrinsics/simd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ pub const unsafe fn simd_cast<T, U>(x: T) -> U;
218218
#[rustc_nounwind]
219219
pub const unsafe fn simd_as<T, U>(x: T) -> U;
220220

221+
/// Replacement for `transmute`, specifically for use with scalable SIMD types.
222+
#[rustc_intrinsic]
223+
#[rustc_nounwind]
224+
pub unsafe fn simd_reinterpret<Src, Dst>(src: Src) -> Dst;
225+
221226
/// Negates a vector elementwise.
222227
///
223228
/// `T` must be a vector of integers or floats.

0 commit comments

Comments
 (0)