Skip to content

Commit a07870f

Browse files
authored
Handle a non-Fallback baseline (#105)
Fixes #74 A couple of notes: 1) For ease, I removed `simd_dispatch` in this PR. As such, I don't want to land this before [#simd > v0.3.0](https://xi.zulipchat.com/#narrow/channel/514230-simd/topic/v0.2E3.2E0/with/543274721) 2) The cfg variants in here are gnarly; I believe that's unavoidable to express what we want. We do need to be clear that we are doing runtime dispatch properly 3) The automated testing story of this PR is an open question. I have a manual test, in the new `sh ./check_targets.sh` at the root. I want to defer running this in CI; I suspect it would be very expensive. This does not address #92. This does however add a `force_support_fallback` feature, so it doesn't completely remove the fallback functionality.
1 parent 5fe2c6b commit a07870f

13 files changed

Lines changed: 289 additions & 181 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env:
88
# If the compilation fails, then the version specified here needs to be bumped up to reality.
99
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
1010
# plus all the README.md files of the affected packages.
11-
RUST_MIN_VER: "1.86"
11+
RUST_MIN_VER: "1.88"
1212
# List of packages that will be checked with the minimum supported Rust version.
1313
# This should be limited to packages that are intended for publishing.
1414
RUST_MIN_VER_PKGS: "-p fearless_simd"

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,20 @@ You can find its changes [documented below](#030-2025-10-14).
1313

1414
## [Unreleased]
1515

16-
This release has an [MSRV][] of 1.86.
16+
This release has an [MSRV][] of 1.88.
17+
18+
### Changed
19+
20+
- Breaking change: `Level::fallback` has been removed, replaced with `Level::baseline`. ([#105][] by [@DJMcNab][])
21+
This corresponds with a change to avoid compiling in support for the fallback level on compilation targets which don't
22+
require it; this is most impactful for binary size on WASM, Apple Silicon Macs or Android.
23+
A consequence of this is that the available variants on `Level` are now dependent on the target features you are compiling with.
24+
The fallback level can be restored with the `force_support_fallback` cargo feature. We don't expect this to be necessary outside
25+
of tests.
26+
27+
### Removed
28+
29+
- Breaking change: The (deprecated) `simd_dispatch!` macro. ([#105][] by [@DJMcNab][])
1730

1831
## [0.3.0][] (2025-10-14)
1932

@@ -85,6 +98,7 @@ No changelog was kept for this release.
8598
[#93]: https://github.com/linebender/fearless_simd/pull/93
8699
[#96]: https://github.com/linebender/fearless_simd/pull/96
87100
[#99]: https://github.com/linebender/fearless_simd/pull/99
101+
[#105]: https://github.com/linebender/fearless_simd/pull/105
88102

89103
[Unreleased]: https://github.com/linebender/fearless_simd/compare/v0.3.0...HEAD
90104
[0.3.0]: https://github.com/linebender/fearless_simd/compare/v0.3.0...v0.2.0

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = "Apache-2.0 OR MIT"
1313
repository = "https://github.com/linebender/fearless_simd"
1414
# Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml, with the relevant README.md files
1515
# and with the MSRV in the `Unreleased` section of CHANGELOG.md.
16-
rust-version = "1.86"
16+
rust-version = "1.88"
1717

1818
[workspace.lints]
1919

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ It benefited from conversations with Luca Versari, though he is not responsible
5959

6060
## Minimum supported Rust Version (MSRV)
6161

62-
This version of Fearless SIMD has been verified to compile with **Rust 1.86** and later.
62+
This version of Fearless SIMD has been verified to compile with **Rust 1.88** and later.
6363

6464
Future versions of Fearless SIMD might increase the Rust version requirement.
6565
It will not be treated as a breaking change and as such can even happen with small patch releases.

check_targets.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# A script to run cargo check for fearless_simd on each supported platform.
2+
# We currently don't run this in CI, as we expect it would take too long.
3+
# Before using, you must run:
4+
# rustup target add aarch64-linux-android x86_64-unknown-linux-gnu i686-pc-windows-msvc wasm32-unknown-unknown riscv64gc-unknown-linux-gnu
5+
6+
# Run using `sh ./check_targets.sh`
7+
# TODO: Make into an xtask like thing so that windows users can use easily.
8+
9+
# aarch64, both with and without neon support.
10+
# Note that doing `-neon` is not sound due to the standard library's ABI, but the
11+
# binary is never executed (nor indeed is it even created), and it's still a useful sanity check.
12+
RUSTFLAGS=-Ctarget-feature=-neon cargo check -p fearless_simd --target aarch64-linux-android
13+
RUSTFLAGS=-Ctarget-feature=-neon cargo check -p fearless_simd --target aarch64-linux-android --features force_support_fallback
14+
cargo check -p fearless_simd --target aarch64-linux-android --features force_support_fallback
15+
cargo check -p fearless_simd --target aarch64-linux-android
16+
17+
# x86_64, at all supported static SIMD levels.
18+
RUSTFLAGS=-Ctarget-feature=+avx2,+fma cargo check -p fearless_simd --target x86_64-unknown-linux-gnu
19+
RUSTFLAGS=-Ctarget-feature=+avx2,+fma cargo check -p fearless_simd --target x86_64-unknown-linux-gnu --features force_support_fallback
20+
RUSTFLAGS=-Ctarget-feature=+sse4.2 cargo check -p fearless_simd --target x86_64-unknown-linux-gnu
21+
RUSTFLAGS=-Ctarget-feature=+sse4.2 cargo check -p fearless_simd --target x86_64-unknown-linux-gnu --features force_support_fallback
22+
cargo check -p fearless_simd --target x86_64-unknown-linux-gnu
23+
cargo check -p fearless_simd --target x86_64-unknown-linux-gnu --features force_support_fallback
24+
25+
# x86 (i.e. 32 bit) at all supported static SIMD levels.
26+
RUSTFLAGS=-Ctarget-feature=+avx2,+fma cargo check -p fearless_simd --target i686-pc-windows-msvc
27+
RUSTFLAGS=-Ctarget-feature=+avx2,+fma cargo check -p fearless_simd --target i686-pc-windows-msvc --features force_support_fallback
28+
RUSTFLAGS=-Ctarget-feature=+sse4.2 cargo check -p fearless_simd --target i686-pc-windows-msvc
29+
RUSTFLAGS=-Ctarget-feature=+sse4.2 cargo check -p fearless_simd --target i686-pc-windows-msvc --features force_support_fallback
30+
cargo check -p fearless_simd --target i686-pc-windows-msvc
31+
cargo check -p fearless_simd --target i686-pc-windows-msvc --features force_support_fallback
32+
33+
# Wasm, both with and without SIMD.
34+
cargo check -p fearless_simd --target wasm32-unknown-unknown
35+
cargo check -p fearless_simd --target wasm32-unknown-unknown --features force_support_fallback
36+
RUSTFLAGS=-Ctarget-feature=+simd128 cargo check -p fearless_simd --target wasm32-unknown-unknown
37+
RUSTFLAGS=-Ctarget-feature=+simd128 cargo check -p fearless_simd --target wasm32-unknown-unknown --features force_support_fallback
38+
39+
# riscv64, which is importantly a target we don't support any SIMD levels for.
40+
cargo check -p fearless_simd --target riscv64gc-unknown-linux-gnu
41+
cargo check -p fearless_simd --target riscv64gc-unknown-linux-gnu --features force_support_fallback

fearless_simd/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ libm = ["dep:libm"]
3030
# beyond the basic SIMD operations abstracted on all platforms
3131
safe_wrappers = []
3232

33+
# Force the "fallback" SIMD level to be supported
34+
# This is primarily used for tests
35+
force_support_fallback = []
36+
3337
[lints]
3438
workspace = true
3539

fearless_simd/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The following crate [feature flags](https://doc.rust-lang.org/cargo/reference/fe
115115
- `libm`: Use floating point implementations from [libm].
116116
- `safe_wrappers`: Include safe wrappers for (some) target feature specific intrinsics,
117117
beyond the basic SIMD operations abstracted on all platforms.
118+
- `force_support_fallback`: Force scalar fallback, to be supported, even if your compilation target has a better baseline.
118119

119120
At least one of `std` and `libm` is required; `std` overrides `libm`.
120121

@@ -124,7 +125,7 @@ At least one of `std` and `libm` is required; `std` overrides `libm`.
124125

125126
## Minimum supported Rust Version (MSRV)
126127

127-
This version of Fearless SIMD has been verified to compile with **Rust 1.86** and later.
128+
This version of Fearless SIMD has been verified to compile with **Rust 1.88** and later.
128129

129130
Future versions of Fearless SIMD might increase the Rust version requirement.
130131
It will not be treated as a breaking change and as such can even happen with small patch releases.

fearless_simd/src/generated/fallback.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ impl Simd for Fallback {
8383
type mask32s = mask32x4<Self>;
8484
#[inline(always)]
8585
fn level(self) -> Level {
86-
Level::Fallback(self)
86+
#[cfg(feature = "force_support_fallback")]
87+
return Level::Fallback(self);
88+
#[cfg(not(feature = "force_support_fallback"))]
89+
Level::baseline()
8790
}
8891
#[inline]
8992
fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {

fearless_simd/src/generated/sse4_2.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ impl Simd for Sse4_2 {
5252
type mask32s = mask32x4<Self>;
5353
#[inline(always)]
5454
fn level(self) -> Level {
55-
Level::Sse4_2(self)
55+
#[cfg(not(all(target_feature = "avx2", target_feature = "fma")))]
56+
return Level::Sse4_2(self);
57+
#[cfg(all(target_feature = "avx2", target_feature = "fma"))]
58+
{
59+
Level::baseline()
60+
}
5661
}
5762
#[inline]
5863
fn vectorize<F: FnOnce() -> R, R>(self, f: F) -> R {

0 commit comments

Comments
 (0)