Skip to content

Commit

Permalink
also rename the SIMD intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 23, 2024
1 parent 038e7c6 commit f2cff5e
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
});
}

sym::simd_expose_addr | sym::simd_from_exposed_addr | sym::simd_cast_ptr => {
sym::simd_expose_addr | sym::simd_with_exposed_provenance | sym::simd_cast_ptr => {
intrinsic_args!(fx, args => (arg); intrinsic);
ret.write_cvalue_transmute(fx, arg);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
return Ok(bx.ptrtoint(args[0].immediate(), llret_ty));
}

if name == sym::simd_from_exposed_addr {
if name == sym::simd_with_exposed_provenance {
let (out_len, out_elem) = require_simd!(ret_ty, SimdReturn);
require!(
in_len == out_len,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

CastKind::PointerWithExposedProvenance => {
let src = self.read_immediate(src)?;
let res = self.pointer_from_exposed_address_cast(&src, cast_layout)?;
let res = self.pointer_with_exposed_provenance_cast(&src, cast_layout)?;
self.write_immediate(*res, dest)?;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
Ok(ImmTy::from_scalar(self.cast_from_int_like(scalar, src.layout, cast_to.ty)?, cast_to))
}

pub fn pointer_from_exposed_address_cast(
pub fn pointer_with_exposed_provenance_cast(
&self,
src: &ImmTy<'tcx, M::Provenance>,
cast_to: TyAndLayout<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ pub fn check_intrinsic_type(
| sym::simd_as
| sym::simd_cast_ptr
| sym::simd_expose_addr
| sym::simd_from_exposed_addr => (2, 0, vec![param(0)], param(1)),
| sym::simd_with_exposed_provenance => (2, 0, vec![param(0)], param(1)),
sym::simd_bitmask => (2, 0, vec![param(0)], param(1)),
sym::simd_select | sym::simd_select_bitmask => {
(2, 0, vec![param(0), param(1), param(1)], param(1))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,6 @@ symbols! {
simd_fmin,
simd_fpow,
simd_fpowi,
simd_from_exposed_addr,
simd_fsin,
simd_fsqrt,
simd_gather,
Expand Down Expand Up @@ -1688,6 +1687,7 @@ symbols! {
simd_shuffle_generic,
simd_sub,
simd_trunc,
simd_with_exposed_provenance,
simd_xor,
since,
sinf128,
Expand Down
7 changes: 7 additions & 0 deletions library/core/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ extern "rust-intrinsic" {
///
/// `U` must be a vector of pointers, with the same length as `T`.
#[rustc_nounwind]
#[cfg(not(bootstrap))]
pub fn simd_with_exposed_provenance<T, U>(addr: T) -> U;
#[rustc_nounwind]
#[cfg(bootstrap)]
pub fn simd_from_exposed_addr<T, U>(addr: T) -> U;

/// Swap bytes of each element.
Expand Down Expand Up @@ -655,3 +659,6 @@ extern "rust-intrinsic" {
#[rustc_nounwind]
pub fn simd_flog<T>(a: T) -> T;
}

#[cfg(bootstrap)]
pub use simd_from_exposed_addr as simd_with_exposed_provenance;
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
#[inline]
fn with_exposed_provenance(addr: Self::Usize) -> Self {
// Safety: `self` is a pointer vector
unsafe { core::intrinsics::simd::simd_from_exposed_addr(addr) }
unsafe { core::intrinsics::simd::simd_with_exposed_provenance(addr) }
}

#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ where
#[inline]
fn with_exposed_provenance(addr: Self::Usize) -> Self {
// Safety: `self` is a pointer vector
unsafe { core::intrinsics::simd::simd_from_exposed_addr(addr) }
unsafe { core::intrinsics::simd::simd_with_exposed_provenance(addr) }
}

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/tools/miri/src/shims/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
dest.transmute(this.machine.layouts.uint(dest.layout.size).unwrap(), this)?;
this.write_int(res, &dest)?;
}
"cast" | "as" | "cast_ptr" | "expose_addr" | "from_exposed_addr" => {
"cast" | "as" | "cast_ptr" | "expose_addr" | "with_exposed_provenance" => {
let [op] = check_arg_count(args)?;
let (op, op_len) = this.operand_to_simd(op)?;
let (dest, dest_len) = this.mplace_to_simd(dest)?;
Expand All @@ -495,7 +495,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let safe_cast = intrinsic_name == "as";
let ptr_cast = intrinsic_name == "cast_ptr";
let expose_cast = intrinsic_name == "expose_addr";
let from_exposed_cast = intrinsic_name == "from_exposed_addr";
let from_exposed_cast = intrinsic_name == "with_exposed_provenance";

for i in 0..dest_len {
let op = this.read_immediate(&this.project_index(&op, i)?)?;
Expand Down Expand Up @@ -529,7 +529,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
(ty::RawPtr(..), ty::Int(_) | ty::Uint(_)) if expose_cast =>
this.pointer_expose_address_cast(&op, dest.layout)?,
(ty::Int(_) | ty::Uint(_), ty::RawPtr(..)) if from_exposed_cast =>
this.pointer_from_exposed_address_cast(&op, dest.layout)?,
this.pointer_with_exposed_provenance_cast(&op, dest.layout)?,
// Error otherwise
_ =>
throw_unsup_format!(
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/simd/intrinsic/ptr-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern "rust-intrinsic" {
fn simd_cast_ptr<T, U>(x: T) -> U;
fn simd_expose_addr<T, U>(x: T) -> U;
fn simd_from_exposed_addr<T, U>(x: T) -> U;
fn simd_with_exposed_provenance<T, U>(x: T) -> U;
}

#[derive(Copy, Clone)]
Expand All @@ -24,7 +24,7 @@ fn main() {

let exposed_addr: V<usize> = simd_expose_addr(const_ptrs);

let with_exposed_provenance: V<*mut i8> = simd_from_exposed_addr(exposed_addr);
let with_exposed_provenance: V<*mut i8> = simd_with_exposed_provenance(exposed_addr);

assert!(const_ptrs.0 == [ptr as *const u8, core::ptr::null()]);
assert!(exposed_addr.0 == [ptr as usize, 0]);
Expand Down

0 comments on commit f2cff5e

Please sign in to comment.