Skip to content

Commit 73f7524

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 46dd282 commit 73f7524

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
@@ -1242,6 +1242,18 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
12421242
return Ok(bx.select(m_i1s, args[1].immediate(), args[2].immediate()));
12431243
}
12441244

1245+
if name == sym::simd_reinterpret {
1246+
require_simd!(ret_ty, SimdReturn);
1247+
1248+
return Ok(match args[0].val {
1249+
OperandValue::Ref(PlaceValue { llval: val, .. }) | OperandValue::Immediate(val) => {
1250+
bx.bitcast(val, llret_ty)
1251+
}
1252+
OperandValue::ZeroSized => bx.const_undef(llret_ty),
1253+
OperandValue::Pair(_, _) => todo!(),
1254+
});
1255+
}
1256+
12451257
// every intrinsic below takes a SIMD vector as its first argument
12461258
let (in_len, in_elem) = require_simd!(args[0].layout.ty, SimdInput);
12471259
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
@@ -611,6 +611,7 @@ pub(crate) fn check_intrinsic_type(
611611
}
612612
sym::simd_cast
613613
| sym::simd_as
614+
| sym::simd_reinterpret
614615
| sym::simd_cast_ptr
615616
| sym::simd_expose_provenance
616617
| 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
@@ -2004,6 +2004,7 @@ symbols! {
20042004
simd_reduce_mul_unordered,
20052005
simd_reduce_or,
20062006
simd_reduce_xor,
2007+
simd_reinterpret,
20072008
simd_relaxed_fma,
20082009
simd_rem,
20092010
simd_round,

library/core/src/intrinsics/simd.rs

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

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

0 commit comments

Comments
 (0)