Skip to content

Commit

Permalink
Merge pull request #448 from rust-lang/sync-upstream
Browse files Browse the repository at this point in the history
Sync upstream
  • Loading branch information
calebzulawski authored Jan 18, 2025
2 parents 49176ae + 638667a commit 4b1a23e
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 49 deletions.
5 changes: 2 additions & 3 deletions crates/core_simd/examples/dot_product.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Code taken from the `packed_simd` crate
// Run this code with `cargo test --example dot_product`
//use std::iter::zip;
//! Code taken from the `packed_simd` crate.
//! Run this code with `cargo test --example dot_product`.
#![feature(array_chunks)]
#![feature(slice_as_chunks)]
Expand Down
5 changes: 0 additions & 5 deletions crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#![no_std]
#![feature(
const_eval_select,
const_intrinsic_copy,
const_refs_to_cell,
const_maybe_uninit_as_mut_ptr,
const_mut_refs,
convert_float_to_int,
core_intrinsics,
decl_macro,
intra_doc_pointers,
repr_simd,
simd_ffi,
staged_api,
strict_provenance,
prelude_import,
ptr_metadata
)]
Expand Down
8 changes: 4 additions & 4 deletions crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
T: MaskElement,
LaneCount<N>: SupportedLaneCount,
{
/// Construct a mask by setting all elements to the given value.
/// Constructs a mask by setting all elements to the given value.
#[inline]
pub fn splat(value: bool) -> Self {
Self(mask_impl::Mask::splat(value))
Expand Down Expand Up @@ -288,7 +288,7 @@ where
self.0.all()
}

/// Create a bitmask from a mask.
/// Creates a bitmask from a mask.
///
/// Each bit is set if the corresponding element in the mask is `true`.
/// If the mask contains more than 64 elements, the bitmask is truncated to the first 64.
Expand All @@ -298,7 +298,7 @@ where
self.0.to_bitmask_integer()
}

/// Create a mask from a bitmask.
/// Creates a mask from a bitmask.
///
/// For each bit, if it is set, the corresponding element in the mask is set to `true`.
/// If the mask contains more than 64 elements, the remainder are set to `false`.
Expand All @@ -308,7 +308,7 @@ where
Self(mask_impl::Mask::from_bitmask_integer(bitmask))
}

/// Find the index of the first set element.
/// Finds the index of the first set element.
///
/// ```
/// # #![feature(portable_simd)]
Expand Down
2 changes: 1 addition & 1 deletion crates/core_simd/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! for_base_types {
#[inline]
#[must_use = "operator returns a new vector without mutating the inputs"]
// TODO: only useful for int Div::div, but we hope that this
// will essentially always always get inlined anyway.
// will essentially always get inlined anyway.
#[track_caller]
fn $call(self, rhs: Self) -> Self::Output {
$macro_impl!(self, rhs, $inner, $scalar)
Expand Down
1 change: 1 addition & 0 deletions crates/core_simd/src/ops/assign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Assignment operators
use super::*;
use core::ops::{AddAssign, MulAssign}; // commutative binary op-assignment
use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign}; // commutative bit binary op-assignment
Expand Down
1 change: 1 addition & 0 deletions crates/core_simd/src/ops/deref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Ideally, Rust would take care of this itself,
//! and method calls usually handle the LHS implicitly.
//! But this is not the case with arithmetic ops.
use super::*;

macro_rules! deref_lhs {
Expand Down
4 changes: 2 additions & 2 deletions crates/core_simd/src/simd/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait SimdConstPtr: Copy + Sealed {
/// Equivalent to calling [`pointer::addr`] on each element.
fn addr(self) -> Self::Usize;

/// Convert an address to a pointer without giving it any provenance.
/// Converts an address to a pointer without giving it any provenance.
///
/// Without provenance, this pointer is not associated with any actual allocation. Such a
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
Expand All @@ -67,7 +67,7 @@ pub trait SimdConstPtr: Copy + Sealed {
/// [`Self::with_exposed_provenance`] and returns the "address" portion.
fn expose_provenance(self) -> Self::Usize;

/// Convert an address back to a pointer, picking up a previously "exposed" provenance.
/// Converts an address back to a pointer, picking up a previously "exposed" provenance.
///
/// Equivalent to calling [`core::ptr::with_exposed_provenance`] on each element.
fn with_exposed_provenance(addr: Self::Usize) -> Self;
Expand Down
4 changes: 2 additions & 2 deletions crates/core_simd/src/simd/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait SimdMutPtr: Copy + Sealed {
/// Equivalent to calling [`pointer::addr`] on each element.
fn addr(self) -> Self::Usize;

/// Convert an address to a pointer without giving it any provenance.
/// Converts an address to a pointer without giving it any provenance.
///
/// Without provenance, this pointer is not associated with any actual allocation. Such a
/// no-provenance pointer may be used for zero-sized memory accesses (if suitably aligned), but
Expand All @@ -64,7 +64,7 @@ pub trait SimdMutPtr: Copy + Sealed {
/// [`Self::with_exposed_provenance`] and returns the "address" portion.
fn expose_provenance(self) -> Self::Usize;

/// Convert an address back to a pointer, picking up a previously "exposed" provenance.
/// Converts an address back to a pointer, picking up a previously "exposed" provenance.
///
/// Equivalent to calling [`core::ptr::with_exposed_provenance_mut`] on each element.
fn with_exposed_provenance(addr: Self::Usize) -> Self;
Expand Down
26 changes: 17 additions & 9 deletions crates/core_simd/src/swizzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ pub macro simd_swizzle {
}
}

/// Create a vector from the elements of another vector.
/// Creates a vector from the elements of another vector.
pub trait Swizzle<const N: usize> {
/// Map from the elements of the input vector to the output vector.
const INDEX: [usize; N];

/// Create a new vector from the elements of `vector`.
/// Creates a new vector from the elements of `vector`.
///
/// Lane `i` of the output is `vector[Self::INDEX[i]]`.
#[inline]
Expand All @@ -85,7 +85,7 @@ pub trait Swizzle<const N: usize> {
LaneCount<N>: SupportedLaneCount,
LaneCount<M>: SupportedLaneCount,
{
// Safety: `vector` is a vector, and the index is a const array of u32.
// Safety: `vector` is a vector, and the index is a const vector of u32.
unsafe {
core::intrinsics::simd::simd_shuffle(
vector,
Expand All @@ -103,13 +103,17 @@ pub trait Swizzle<const N: usize> {
output[i] = index as u32;
i += 1;
}
output

// The index list needs to be returned as a vector.
#[repr(simd)]
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
SimdShuffleIdx(output)
},
)
}
}

/// Create a new vector from the elements of `first` and `second`.
/// Creates a new vector from the elements of `first` and `second`.
///
/// Lane `i` of the output is `concat[Self::INDEX[i]]`, where `concat` is the concatenation of
/// `first` and `second`.
Expand All @@ -121,7 +125,7 @@ pub trait Swizzle<const N: usize> {
LaneCount<N>: SupportedLaneCount,
LaneCount<M>: SupportedLaneCount,
{
// Safety: `first` and `second` are vectors, and the index is a const array of u32.
// Safety: `first` and `second` are vectors, and the index is a const vector of u32.
unsafe {
core::intrinsics::simd::simd_shuffle(
first,
Expand All @@ -139,13 +143,17 @@ pub trait Swizzle<const N: usize> {
output[i] = index as u32;
i += 1;
}
output

// The index list needs to be returned as a vector.
#[repr(simd)]
struct SimdShuffleIdx<const LEN: usize>([u32; LEN]);
SimdShuffleIdx(output)
},
)
}
}

/// Create a new mask from the elements of `mask`.
/// Creates a new mask from the elements of `mask`.
///
/// Element `i` of the output is `mask[Self::INDEX[i]]`.
#[inline]
Expand All @@ -160,7 +168,7 @@ pub trait Swizzle<const N: usize> {
unsafe { Mask::from_int_unchecked(Self::swizzle(mask.to_int())) }
}

/// Create a new mask from the elements of `first` and `second`.
/// Creates a new mask from the elements of `first` and `second`.
///
/// Element `i` of the output is `concat[Self::INDEX[i]]`, where `concat` is the concatenation of
/// `first` and `second`.
Expand Down
2 changes: 2 additions & 0 deletions crates/core_simd/src/swizzle_dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ where
use core::arch::arm::{uint8x8_t, vtbl1_u8};
#[cfg(target_arch = "wasm32")]
use core::arch::wasm32 as wasm;
#[cfg(target_arch = "wasm64")]
use core::arch::wasm64 as wasm;
#[cfg(target_arch = "x86")]
use core::arch::x86;
#[cfg(target_arch = "x86_64")]
Expand Down
14 changes: 7 additions & 7 deletions crates/core_simd/src/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod sealed {
}
use sealed::Sealed;

/// Convert SIMD vectors to vectors of bytes
/// Converts SIMD vectors to vectors of bytes
pub trait ToBytes: Sealed {
/// This type, reinterpreted as bytes.
type Bytes: Copy
Expand All @@ -22,26 +22,26 @@ pub trait ToBytes: Sealed {
+ SimdUint<Scalar = u8>
+ 'static;

/// Return the memory representation of this integer as a byte array in native byte
/// Returns the memory representation of this integer as a byte array in native byte
/// order.
fn to_ne_bytes(self) -> Self::Bytes;

/// Return the memory representation of this integer as a byte array in big-endian
/// Returns the memory representation of this integer as a byte array in big-endian
/// (network) byte order.
fn to_be_bytes(self) -> Self::Bytes;

/// Return the memory representation of this integer as a byte array in little-endian
/// Returns the memory representation of this integer as a byte array in little-endian
/// byte order.
fn to_le_bytes(self) -> Self::Bytes;

/// Create a native endian integer value from its memory representation as a byte array
/// Creates a native endian integer value from its memory representation as a byte array
/// in native endianness.
fn from_ne_bytes(bytes: Self::Bytes) -> Self;

/// Create an integer value from its representation as a byte array in big endian.
/// Creates an integer value from its representation as a byte array in big endian.
fn from_be_bytes(bytes: Self::Bytes) -> Self;

/// Create an integer value from its representation as a byte array in little endian.
/// Creates an integer value from its representation as a byte array in little endian.
fn from_le_bytes(bytes: Self::Bytes) -> Self;
}

Expand Down
6 changes: 3 additions & 3 deletions crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ where
unsafe { &mut *(self as *mut Self as *mut [T; N]) }
}

/// Load a vector from an array of `T`.
/// Loads a vector from an array of `T`.
///
/// This function is necessary since `repr(simd)` has padding for non-power-of-2 vectors (at the time of writing).
/// With padding, `read_unaligned` will read past the end of an array of N elements.
Expand Down Expand Up @@ -591,7 +591,7 @@ where
unsafe { Self::gather_select_ptr(ptrs, enable, or) }
}

/// Read elementwise from pointers into a SIMD vector.
/// Reads elementwise from pointers into a SIMD vector.
///
/// # Safety
///
Expand Down Expand Up @@ -832,7 +832,7 @@ where
}
}

/// Write pointers elementwise into a SIMD vector.
/// Writes pointers elementwise into a SIMD vector.
///
/// # Safety
///
Expand Down
13 changes: 2 additions & 11 deletions crates/core_simd/src/vendor/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ mod neon {
from_transmute! { unsafe u64x2 => poly64x2_t }
}

#[cfg(any(
all(target_feature = "v5te", not(target_feature = "mclass")),
all(target_feature = "mclass", target_feature = "dsp"),
))]
mod dsp {
use super::*;

from_transmute! { unsafe Simd<u16, 2> => uint16x2_t }
from_transmute! { unsafe Simd<i16, 2> => int16x2_t }
}

#[cfg(any(
all(target_feature = "v6", not(target_feature = "mclass")),
all(target_feature = "mclass", target_feature = "dsp"),
Expand All @@ -68,6 +57,8 @@ mod simd32 {

from_transmute! { unsafe Simd<u8, 4> => uint8x4_t }
from_transmute! { unsafe Simd<i8, 4> => int8x4_t }
from_transmute! { unsafe Simd<u16, 2> => uint16x2_t }
from_transmute! { unsafe Simd<i16, 2> => int16x2_t }
}

#[cfg(all(
Expand Down
2 changes: 1 addition & 1 deletion crates/core_simd/tests/pointers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(portable_simd, strict_provenance, exposed_provenance)]
#![feature(portable_simd)]

use core_simd::simd::{
ptr::{SimdConstPtr, SimdMutPtr},
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-09-11"
channel = "nightly-2025-01-16"
components = ["rustfmt", "clippy", "miri", "rust-src"]

0 comments on commit 4b1a23e

Please sign in to comment.