Skip to content

Commit 12342ef

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 <[email protected]>
1 parent f95a354 commit 12342ef

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

1239+
if name == sym::simd_reinterpret {
1240+
require_simd!(ret_ty, SimdReturn);
1241+
1242+
return Ok(match args[0].val {
1243+
OperandValue::Ref(PlaceValue { llval: val, .. }) | OperandValue::Immediate(val) => {
1244+
bx.bitcast(val, llret_ty)
1245+
}
1246+
OperandValue::ZeroSized => bx.const_undef(llret_ty),
1247+
OperandValue::Pair(_, _) => todo!(),
1248+
});
1249+
}
1250+
12391251
// every intrinsic below takes a SIMD vector as its first argument
12401252
let (in_len, in_elem) = require_simd!(args[0].layout.ty, SimdInput);
12411253
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
@@ -621,6 +621,7 @@ pub(crate) fn check_intrinsic_type(
621621
}
622622
sym::simd_cast
623623
| sym::simd_as
624+
| sym::simd_reinterpret
624625
| sym::simd_cast_ptr
625626
| sym::simd_expose_provenance
626627
| 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
@@ -2010,6 +2010,7 @@ symbols! {
20102010
simd_reduce_mul_unordered,
20112011
simd_reduce_or,
20122012
simd_reduce_xor,
2013+
simd_reinterpret,
20132014
simd_relaxed_fma,
20142015
simd_rem,
20152016
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)