Skip to content

Commit d573564

Browse files
committed
Auto merge of #121269 - calebzulawski:sync-portable-simd-2024-02-18, r=Mark-Simulacrum
Portable SIMD subtree update Syncs nightly to the latest changes from rust-lang/portable-simd r? `@rust-lang/libs` Also, fixes #119904 which is now fixed upstream.
2 parents 6122397 + b2691ba commit d573564

File tree

22 files changed

+218
-354
lines changed

22 files changed

+218
-354
lines changed

Diff for: library/portable-simd/crates/core_simd/src/intrinsics.rs

-169
This file was deleted.

Diff for: library/portable-simd/crates/core_simd/src/lib.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
#![no_std]
22
#![feature(
3+
const_intrinsic_copy,
34
const_refs_to_cell,
45
const_maybe_uninit_as_mut_ptr,
56
const_mut_refs,
67
convert_float_to_int,
8+
core_intrinsics,
79
decl_macro,
810
inline_const,
911
intra_doc_pointers,
10-
platform_intrinsics,
1112
repr_simd,
1213
simd_ffi,
1314
staged_api,
14-
stdsimd,
1515
strict_provenance,
1616
ptr_metadata
1717
)]
18+
#![cfg_attr(
19+
all(
20+
any(target_arch = "aarch64", target_arch = "arm",),
21+
any(
22+
all(target_feature = "v6", not(target_feature = "mclass")),
23+
all(target_feature = "mclass", target_feature = "dsp"),
24+
)
25+
),
26+
feature(stdarch_arm_dsp)
27+
)]
28+
#![cfg_attr(
29+
all(target_arch = "arm", target_feature = "v7"),
30+
feature(stdarch_arm_neon_intrinsics)
31+
)]
32+
#![cfg_attr(
33+
any(target_arch = "powerpc", target_arch = "powerpc64"),
34+
feature(stdarch_powerpc)
35+
)]
1836
#![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really
1937
#![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)]
2038
#![allow(internal_features)]

Diff for: library/portable-simd/crates/core_simd/src/masks.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
)]
1313
mod mask_impl;
1414

15-
use crate::simd::{
16-
cmp::SimdPartialEq, intrinsics, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount,
17-
};
15+
use crate::simd::{LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
1816
use core::cmp::Ordering;
1917
use core::{fmt, mem};
2018

@@ -35,7 +33,7 @@ mod sealed {
3533

3634
fn eq(self, other: Self) -> bool;
3735

38-
fn as_usize(self) -> usize;
36+
fn to_usize(self) -> usize;
3937

4038
type Unsigned: SimdElement;
4139

@@ -60,14 +58,23 @@ macro_rules! impl_element {
6058
where
6159
LaneCount<N>: SupportedLaneCount,
6260
{
63-
(value.simd_eq(Simd::splat(0 as _)) | value.simd_eq(Simd::splat(-1 as _))).all()
61+
// We can't use `Simd` directly, because `Simd`'s functions call this function and
62+
// we will end up with an infinite loop.
63+
// Safety: `value` is an integer vector
64+
unsafe {
65+
use core::intrinsics::simd;
66+
let falses: Simd<Self, N> = simd::simd_eq(value, Simd::splat(0 as _));
67+
let trues: Simd<Self, N> = simd::simd_eq(value, Simd::splat(-1 as _));
68+
let valid: Simd<Self, N> = simd::simd_or(falses, trues);
69+
simd::simd_reduce_all(valid)
70+
}
6471
}
6572

6673
#[inline]
6774
fn eq(self, other: Self) -> bool { self == other }
6875

6976
#[inline]
70-
fn as_usize(self) -> usize {
77+
fn to_usize(self) -> usize {
7178
self as usize
7279
}
7380

@@ -141,8 +148,9 @@ where
141148
// but these are "dependently-sized" types, so copy elision it is!
142149
unsafe {
143150
let bytes: [u8; N] = mem::transmute_copy(&array);
144-
let bools: Simd<i8, N> = intrinsics::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
145-
Mask::from_int_unchecked(intrinsics::simd_cast(bools))
151+
let bools: Simd<i8, N> =
152+
core::intrinsics::simd::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
153+
Mask::from_int_unchecked(core::intrinsics::simd::simd_cast(bools))
146154
}
147155
}
148156

@@ -160,7 +168,7 @@ where
160168
// This would be hypothetically valid as an "in-place" transmute,
161169
// but these are "dependently-sized" types, so copy elision it is!
162170
unsafe {
163-
let mut bytes: Simd<i8, N> = intrinsics::simd_cast(self.to_int());
171+
let mut bytes: Simd<i8, N> = core::intrinsics::simd::simd_cast(self.to_int());
164172
bytes &= Simd::splat(1i8);
165173
mem::transmute_copy(&bytes)
166174
}
@@ -175,7 +183,10 @@ where
175183
#[must_use = "method returns a new mask and does not mutate the original value"]
176184
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
177185
// Safety: the caller must confirm this invariant
178-
unsafe { Self(mask_impl::Mask::from_int_unchecked(value)) }
186+
unsafe {
187+
core::intrinsics::assume(<T as Sealed>::valid(value));
188+
Self(mask_impl::Mask::from_int_unchecked(value))
189+
}
179190
}
180191

181192
/// Converts a vector of integers to a mask, where 0 represents `false` and -1
@@ -374,23 +385,25 @@ where
374385
);
375386

376387
// Safety: the input and output are integer vectors
377-
let index: Simd<T, N> = unsafe { intrinsics::simd_cast(index) };
388+
let index: Simd<T, N> = unsafe { core::intrinsics::simd::simd_cast(index) };
378389

379390
let masked_index = self.select(index, Self::splat(true).to_int());
380391

381392
// Safety: the input and output are integer vectors
382-
let masked_index: Simd<T::Unsigned, N> = unsafe { intrinsics::simd_cast(masked_index) };
393+
let masked_index: Simd<T::Unsigned, N> =
394+
unsafe { core::intrinsics::simd::simd_cast(masked_index) };
383395

384396
// Safety: the input is an integer vector
385-
let min_index: T::Unsigned = unsafe { intrinsics::simd_reduce_min(masked_index) };
397+
let min_index: T::Unsigned =
398+
unsafe { core::intrinsics::simd::simd_reduce_min(masked_index) };
386399

387400
// Safety: the return value is the unsigned version of T
388401
let min_index: T = unsafe { core::mem::transmute_copy(&min_index) };
389402

390403
if min_index.eq(T::TRUE) {
391404
None
392405
} else {
393-
Some(min_index.as_usize())
406+
Some(min_index.to_usize())
394407
}
395408
}
396409
}

Diff for: library/portable-simd/crates/core_simd/src/masks/bitmask.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![allow(unused_imports)]
22
use super::MaskElement;
3-
use crate::simd::intrinsics;
43
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
54
use core::marker::PhantomData;
65

@@ -109,14 +108,18 @@ where
109108
#[must_use = "method returns a new vector and does not mutate the original value"]
110109
pub fn to_int(self) -> Simd<T, N> {
111110
unsafe {
112-
intrinsics::simd_select_bitmask(self.0, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
111+
core::intrinsics::simd::simd_select_bitmask(
112+
self.0,
113+
Simd::splat(T::TRUE),
114+
Simd::splat(T::FALSE),
115+
)
113116
}
114117
}
115118

116119
#[inline]
117120
#[must_use = "method returns a new mask and does not mutate the original value"]
118121
pub unsafe fn from_int_unchecked(value: Simd<T, N>) -> Self {
119-
unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) }
122+
unsafe { Self(core::intrinsics::simd::simd_bitmask(value), PhantomData) }
120123
}
121124

122125
#[inline]

0 commit comments

Comments
 (0)