Skip to content

Portable SIMD subtree update #121269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
81af496
fix simd_bitmask docs
RalfJung Dec 3, 2023
289c1d1
Fix bitmask vector bit order
calebzulawski Dec 3, 2023
80ff6a5
Merge pull request #378 from RalfJung/simd_bitmask
calebzulawski Dec 3, 2023
c705775
Fix load/store safety comments to require aligned `T`
programmerjake Dec 11, 2023
1273da6
Merge pull request #383 from programmerjake/programmerjake-patch-1
calebzulawski Dec 11, 2023
b6eeb4e
Assume masks are correct
workingjubilee Dec 14, 2023
bb50fa2
Use core::intrinsics
calebzulawski Dec 29, 2023
e7130ec
Add exposed_provenance for rust-lang/rust#118487
calebzulawski Jan 5, 2024
97007cc
Merge pull request #386 from rust-lang/core-intrinsics
calebzulawski Jan 5, 2024
f55ca30
Merge pull request #380 from rust-lang/bitmask-order
calebzulawski Jan 29, 2024
4e36929
re-add const_intrinsic_copy feature
RalfJung Feb 9, 2024
047ba0a
stdsimd feature got split up
RalfJung Feb 9, 2024
f505736
Merge pull request #389 from RalfJung/const_intrinsic_copy
calebzulawski Feb 9, 2024
851ef63
use core::intrinsics::simd
RalfJung Feb 14, 2024
b2e1bcb
Merge pull request #391 from RalfJung/core-intrinsics
calebzulawski Feb 14, 2024
6ad779c
Merge pull request #385 from workingjubilee/make-an-ass-out-of-u-and-me
calebzulawski Feb 17, 2024
a2dd4a3
Minor fixes
calebzulawski Feb 17, 2024
644bdfb
Revert "Merge pull request #385 from workingjubilee/make-an-ass-out-o…
calebzulawski Feb 17, 2024
d8439e9
Add back core_intrinsics
calebzulawski Feb 17, 2024
061d5ac
Merge pull request #392 from rust-lang/minor-fixes
calebzulawski Feb 17, 2024
44b4d26
Revert "Revert "Merge pull request #385 from workingjubilee/make-an-a…
calebzulawski Feb 17, 2024
aebf6f1
Use intrinsics directly to avoid recursion
calebzulawski Feb 17, 2024
7348d2d
Merge pull request #393 from rust-lang/assume-masks-are-correct
calebzulawski Feb 17, 2024
afa70e6
Remove link to core::arch::x86_64
calebzulawski Dec 2, 2023
64bd26f
Fix target_feature config in portable-simd
Urgau Dec 12, 2023
9aec60e
Disable conversions between portable_simd and stdarch on big-endian ARM
Amanieu Jan 30, 2024
e06e54c
Merge pull request #394 from rust-lang/sync-upstream-2024-02-17
calebzulawski Feb 17, 2024
eee4f1d
Fix swizzle_dyn
calebzulawski Feb 18, 2024
6491107
Merge pull request #395 from rust-lang/swizzle_dyn_fix
calebzulawski Feb 18, 2024
b2691ba
Merge commit '649110751ef4f27440d7cc711b3e07d11bf02d4a' into sync-por…
calebzulawski Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 0 additions & 169 deletions library/portable-simd/crates/core_simd/src/intrinsics.rs

This file was deleted.

22 changes: 20 additions & 2 deletions library/portable-simd/crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
#![no_std]
#![feature(
const_intrinsic_copy,
const_refs_to_cell,
const_maybe_uninit_as_mut_ptr,
const_mut_refs,
convert_float_to_int,
core_intrinsics,
decl_macro,
inline_const,
intra_doc_pointers,
platform_intrinsics,
repr_simd,
simd_ffi,
staged_api,
stdsimd,
strict_provenance,
ptr_metadata
)]
#![cfg_attr(
all(
any(target_arch = "aarch64", target_arch = "arm",),
any(
all(target_feature = "v6", not(target_feature = "mclass")),
all(target_feature = "mclass", target_feature = "dsp"),
)
),
feature(stdarch_arm_dsp)
)]
#![cfg_attr(
all(target_arch = "arm", target_feature = "v7"),
feature(stdarch_arm_neon_intrinsics)
)]
#![cfg_attr(
any(target_arch = "powerpc", target_arch = "powerpc64"),
feature(stdarch_powerpc)
)]
#![warn(missing_docs, clippy::missing_inline_in_public_items)] // basically all items, really
#![deny(unsafe_op_in_unsafe_fn, clippy::undocumented_unsafe_blocks)]
#![allow(internal_features)]
Expand Down
41 changes: 27 additions & 14 deletions library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
)]
mod mask_impl;

use crate::simd::{
cmp::SimdPartialEq, intrinsics, LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount,
};
use crate::simd::{LaneCount, Simd, SimdCast, SimdElement, SupportedLaneCount};
use core::cmp::Ordering;
use core::{fmt, mem};

Expand All @@ -35,7 +33,7 @@ mod sealed {

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

fn as_usize(self) -> usize;
fn to_usize(self) -> usize;

type Unsigned: SimdElement;

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

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

#[inline]
fn as_usize(self) -> usize {
fn to_usize(self) -> usize {
self as usize
}

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

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

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

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

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

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

// Safety: the input is an integer vector
let min_index: T::Unsigned = unsafe { intrinsics::simd_reduce_min(masked_index) };
let min_index: T::Unsigned =
unsafe { core::intrinsics::simd::simd_reduce_min(masked_index) };

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

if min_index.eq(T::TRUE) {
None
} else {
Some(min_index.as_usize())
Some(min_index.to_usize())
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions library/portable-simd/crates/core_simd/src/masks/bitmask.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(unused_imports)]
use super::MaskElement;
use crate::simd::intrinsics;
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
use core::marker::PhantomData;

Expand Down Expand Up @@ -109,14 +108,18 @@ where
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn to_int(self) -> Simd<T, N> {
unsafe {
intrinsics::simd_select_bitmask(self.0, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
core::intrinsics::simd::simd_select_bitmask(
self.0,
Simd::splat(T::TRUE),
Simd::splat(T::FALSE),
)
}
}

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

#[inline]
Expand Down
Loading