Skip to content

Commit

Permalink
Auto merge of #135701 - calebzulawski:sync-from-portable-simd-2025-01…
Browse files Browse the repository at this point in the history
…-18, r=workingjubilee

Portable SIMD subtree update

r? `@workingjubilee`
  • Loading branch information
bors committed Feb 10, 2025
2 parents 8c04e39 + 52b42d7 commit 4b293d9
Show file tree
Hide file tree
Showing 47 changed files with 880 additions and 424 deletions.
125 changes: 52 additions & 73 deletions library/portable-simd/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ on:
env:
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
PROPTEST_CASES: 64

jobs:
rustfmt:
name: "rustfmt"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup component add rustfmt
- uses: actions/checkout@v4
- name: Run rustfmt
run: cargo fmt --all -- --check

Expand All @@ -37,7 +33,9 @@ jobs:
- i686-unknown-linux-gnu
- i586-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- arm64ec-pc-windows-msvc
- armv7-unknown-linux-gnueabihf
- loongarch64-unknown-linux-gnu
# non-nightly since https://github.com/rust-lang/rust/pull/113274
# - mips-unknown-linux-gnu
# - mips64-unknown-linux-gnuabi64
Expand All @@ -49,13 +47,9 @@ jobs:
- wasm32-unknown-unknown

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup target add ${{ matrix.target }}
rustup component add clippy
run: rustup target add ${{ matrix.target }}
- name: Run Clippy
run: cargo clippy --all-targets --target ${{ matrix.target }}

Expand All @@ -65,26 +59,19 @@ jobs:
strategy:
fail-fast: false
matrix:
target: [x86_64-pc-windows-msvc, i686-pc-windows-msvc, i586-pc-windows-msvc, x86_64-unknown-linux-gnu, x86_64-apple-darwin]
target: [x86_64-pc-windows-msvc, i686-pc-windows-msvc, i586-pc-windows-msvc, x86_64-unknown-linux-gnu]
# `default` means we use the default target config for the target,
# `native` means we run with `-Ctarget-cpu=native`, and anything else is
# an arg to `-Ctarget-feature`
target_feature: [default, native, +sse3, +ssse3, +sse4.1, +sse4.2, +avx, +avx2]

exclude:
# The macos runners seem to only reliably support up to `avx`.
- { target: x86_64-apple-darwin, target_feature: +avx2 }
# These features are statically known to be present for all 64 bit
# macs, and thus are covered by the `default` test
- { target: x86_64-apple-darwin, target_feature: +sse3 }
- { target: x86_64-apple-darwin, target_feature: +ssse3 }
# -Ctarget-cpu=native sounds like bad-news if target != host
- { target: i686-pc-windows-msvc, target_feature: native }
- { target: i586-pc-windows-msvc, target_feature: native }

include:
# Populate the `matrix.os` field
- { target: x86_64-apple-darwin, os: macos-latest }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: i686-pc-windows-msvc, os: windows-latest }
Expand All @@ -98,12 +85,9 @@ jobs:
# avx512vl, but occasionally doesn't. Maybe one day we can enable it.

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup target add ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}

- name: Configure RUSTFLAGS
shell: bash
Expand Down Expand Up @@ -145,6 +129,35 @@ jobs:
run: cargo doc --verbose --target=${{ matrix.target }}
env:
RUSTDOCFLAGS: -Dwarnings

macos-tests:
name: ${{ matrix.target }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
target:
- aarch64-apple-darwin
- x86_64-apple-darwin
steps:
- uses: actions/checkout@v4
- name: Setup Rust
run: rustup target add ${{ matrix.target }}

- name: Configure RUSTFLAGS
shell: bash
run: echo "RUSTFLAGS=-Dwarnings" >> $GITHUB_ENV

- name: Test (debug)
run: cargo test --verbose --target=${{ matrix.target }}

- name: Test (release)
run: cargo test --verbose --target=${{ matrix.target }} --release

- name: Generate docs
run: cargo doc --verbose --target=${{ matrix.target }}
env:
RUSTDOCFLAGS: -Dwarnings

wasm-tests:
name: "wasm (firefox, ${{ matrix.name }})"
Expand All @@ -155,11 +168,7 @@ jobs:
- { name: default, RUSTFLAGS: "" }
- { name: simd128, RUSTFLAGS: "-C target-feature=+simd128" }
steps:
- uses: actions/checkout@v2
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
- uses: actions/checkout@v4
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Test (debug)
Expand All @@ -174,6 +183,8 @@ jobs:
cross-tests:
name: "${{ matrix.target_feature }} on ${{ matrix.target }} (via cross)"
runs-on: ubuntu-latest
env:
PROPTEST_CASES: 16
strategy:
fail-fast: false

Expand All @@ -185,6 +196,7 @@ jobs:
- powerpc-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu # includes altivec by default
- riscv64gc-unknown-linux-gnu
- loongarch64-unknown-linux-gnu
# MIPS uses a nonstandard binary representation for NaNs which makes it worth testing
# non-nightly since https://github.com/rust-lang/rust/pull/113274
# - mips-unknown-linux-gnu
Expand All @@ -201,24 +213,14 @@ jobs:
# - { target: riscv64gc-unknown-linux-gnu, target_feature: "+v,+zvl128b" }

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
rustup target add ${{ matrix.target }}
rustup component add rust-src
run: rustup target add ${{ matrix.target }}

- name: Install Cross
# Equivalent to `cargo install cross`, but downloading a prebuilt
# binary. Ideally we wouldn't hardcode a version, but the version number
# being part of the tarball means we can't just use the download/latest
# URL :(
# Install the latest git version for newer targets.
run: |
CROSS_URL=https://github.com/cross-rs/cross/releases/download/v0.2.5/cross-x86_64-unknown-linux-gnu.tar.gz
mkdir -p "$HOME/.bin"
curl -sfSL --retry-delay 10 --retry 5 "${CROSS_URL}" | tar zxf - -C "$HOME/.bin"
echo "$HOME/.bin" >> $GITHUB_PATH
cargo install cross --git https://github.com/cross-rs/cross --rev 4090beca3cfffa44371a5bba524de3a578aa46c3
- name: Configure Emulated CPUs
run: |
Expand All @@ -242,34 +244,11 @@ jobs:
- name: Test (release)
run: cross test --verbose --target=${{ matrix.target }} --release

features:
name: "Test cargo features (${{ matrix.simd }} × ${{ matrix.features }})"
miri:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
simd:
- ""
- "avx512"
features:
- ""
- "--features std"
- "--features all_lane_counts"
- "--all-features"

env:
PROPTEST_CASES: 16
steps:
- uses: actions/checkout@v2
- name: Setup Rust
run: |
rustup update nightly --no-self-update
rustup default nightly
- name: Detect AVX512
run: echo "CPU_FEATURE=$(lscpu | grep -o avx512[a-z]* | sed s/avx/+avx/ | tr '\n' ',' )" >> $GITHUB_ENV
- name: Check build
if: ${{ matrix.simd == '' }}
run: RUSTFLAGS="-Dwarnings" cargo test --all-targets --no-default-features ${{ matrix.features }}
- name: Check AVX
if: ${{ matrix.simd == 'avx512' && contains(env.CPU_FEATURE, 'avx512') }}
run: |
echo "Found AVX features: $CPU_FEATURE"
RUSTFLAGS="-Dwarnings -Ctarget-feature=$CPU_FEATURE" cargo test --all-targets --no-default-features ${{ matrix.features }}
- uses: actions/checkout@v4
- name: Test (Miri)
run: cargo miri test
2 changes: 1 addition & 1 deletion library/portable-simd/.github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v1
uses: actions/checkout@v4

- name: Setup Rust
run: |
Expand Down
1 change: 1 addition & 0 deletions library/portable-simd/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
git-subtree.sh
6 changes: 6 additions & 0 deletions library/portable-simd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ members = [
"crates/std_float",
"crates/test_helpers",
]

[profile.test.package."*"]
opt-level = 2

[profile.test.package.test_helpers]
opt-level = 2
2 changes: 2 additions & 0 deletions library/portable-simd/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build.env]
passthrough = ["PROPTEST_CASES"]
3 changes: 1 addition & 2 deletions library/portable-simd/crates/core_simd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ categories = ["hardware-support", "no-std"]
license = "MIT OR Apache-2.0"

[features]
default = ["as_crate"]
default = ["as_crate", "std"]
as_crate = []
std = []
all_lane_counts = []

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = "0.2"
Expand Down
8 changes: 3 additions & 5 deletions library/portable-simd/crates/core_simd/src/lane_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ macro_rules! supported_lane_count {
};
}

supported_lane_count!(1, 2, 4, 8, 16, 32, 64);
#[cfg(feature = "all_lane_counts")]
supported_lane_count!(
3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
);
4 changes: 2 additions & 2 deletions library/portable-simd/crates/core_simd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![no_std]
#![feature(
const_refs_to_cell,
const_mut_refs,
const_eval_select,
convert_float_to_int,
core_intrinsics,
decl_macro,
Expand All @@ -26,6 +25,7 @@
all(target_arch = "arm", target_feature = "v7"),
feature(stdarch_arm_neon_intrinsics)
)]
#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
#![cfg_attr(
any(target_arch = "powerpc", target_arch = "powerpc64"),
feature(stdarch_powerpc)
Expand Down
42 changes: 0 additions & 42 deletions library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,48 +308,6 @@ where
Self(mask_impl::Mask::from_bitmask_integer(bitmask))
}

/// Creates a bitmask vector from a mask.
///
/// Each bit is set if the corresponding element in the mask is `true`.
/// The remaining bits are unset.
///
/// The bits are packed into the first N bits of the vector:
/// ```
/// # #![feature(portable_simd)]
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
/// # use simd::mask32x8;
/// let mask = mask32x8::from_array([true, false, true, false, false, false, true, false]);
/// assert_eq!(mask.to_bitmask_vector()[0], 0b01000101);
/// ```
#[inline]
#[must_use = "method returns a new integer and does not mutate the original value"]
pub fn to_bitmask_vector(self) -> Simd<u8, N> {
self.0.to_bitmask_vector()
}

/// Creates a mask from a bitmask vector.
///
/// For each bit, if it is set, the corresponding element in the mask is set to `true`.
///
/// The bits are packed into the first N bits of the vector:
/// ```
/// # #![feature(portable_simd)]
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
/// # use simd::{mask32x8, u8x8};
/// let bitmask = u8x8::from_array([0b01000101, 0, 0, 0, 0, 0, 0, 0]);
/// assert_eq!(
/// mask32x8::from_bitmask_vector(bitmask),
/// mask32x8::from_array([true, false, true, false, false, false, true, false]),
/// );
/// ```
#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
pub fn from_bitmask_vector(bitmask: Simd<u8, N>) -> Self {
Self(mask_impl::Mask::from_bitmask_vector(bitmask))
}

/// Finds the index of the first set element.
///
/// ```
Expand Down
17 changes: 0 additions & 17 deletions library/portable-simd/crates/core_simd/src/masks/bitmask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,6 @@ where
unsafe { Self(core::intrinsics::simd::simd_bitmask(value), PhantomData) }
}

#[inline]
#[must_use = "method returns a new vector and does not mutate the original value"]
pub fn to_bitmask_vector(self) -> Simd<u8, N> {
let mut bitmask = Simd::splat(0);
bitmask.as_mut_array()[..self.0.as_ref().len()].copy_from_slice(self.0.as_ref());
bitmask
}

#[inline]
#[must_use = "method returns a new mask and does not mutate the original value"]
pub fn from_bitmask_vector(bitmask: Simd<u8, N>) -> Self {
let mut bytes = <LaneCount<N> as SupportedLaneCount>::BitMask::default();
let len = bytes.as_ref().len();
bytes.as_mut().copy_from_slice(&bitmask.as_array()[..len]);
Self(bytes, PhantomData)
}

#[inline]
pub fn to_bitmask_integer(self) -> u64 {
let mut bitmask = [0u8; 8];
Expand Down
Loading

0 comments on commit 4b293d9

Please sign in to comment.