Skip to content

Commit 25607c4

Browse files
committed
chore: polish wasm simd resolution
1 parent 9a94fe5 commit 25607c4

12 files changed

Lines changed: 97 additions & 224 deletions

File tree

.cargo/config.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
[build]
2+
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
3+
14
[alias]
25
rsontest = "hack test -q --feature-powerset --skip default -F arbitrary -F serde --ignore-unknown-features"
3-
build-website = "build -p rsonpath-website --target wasm32-unknown-unknown"
46

57
[env]
68
RUST_BACKTRACE = "1"

Cargo.lock

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"crates/rsonpath-lib",
66
"crates/rsonpath-syntax",
77
"crates/rsonpath-syntax-proptest",
8+
"crates/rsonpath-test"
89
]
910

1011
exclude = ["crates/rsonpath-benchmarks", "crates/rsonpath-test-codegen", "web/rsonpath-website"]
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
4-
networkTimeout=10000
5-
validateDistributionUrl=true
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
64
zipStoreBase=GRADLE_USER_HOME
75
zipStorePath=wrapper/dists

crates/rsonpath-benchmarks/src/implementations/jsurferShim/gradlew

Lines changed: 13 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rsonpath-benchmarks/src/implementations/jsurferShim/gradlew.bat

Lines changed: 10 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rsonpath-lib/Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ rsonpath-syntax-proptest = { workspace = true }
4848
serde_json = { workspace = true }
4949
test-case = { workspace = true }
5050

51-
[patch.crates-io]
52-
getrandom_v03 = { package = "getrandom", version = "0.3.3", features = ["wasm_js"] }
53-
getrandom_v02 = { package = "getrandom", version = "0.2.12", features = ["wasm_js"] }
54-
getrandom_v01 = { package = "getrandom", version = "0.1.16", features = ["wasm_js"] }
55-
5651
[features]
5752
default = ["simd"]
5853
serde = ["dep:serde", "smallvec/serde", "rsonpath-syntax/serde"]

crates/rsonpath-lib/src/classification/depth/shared/mask_32.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub(crate) struct DepthVector32<'a, B: InputBlock<'a, SIZE>> {
2929
impl<'a, B: InputBlock<'a, SIZE>> DepthBlock<'a> for DepthVector32<'a, B> {
3030
#[inline(always)]
3131
fn advance_to_next_depth_decrease(&mut self) -> bool {
32-
#[cfg(target_arch = "x86")]
33-
debug_assert!(is_x86_feature_detected!("popcnt"));
32+
#[cfg(target_arch = "x86")] // On wasm32 popcnt is built-in.
33+
debug_assert!(!is_x86_feature_detected!("popcnt"));
3434
let next_closing = self.closing_mask.trailing_zeros() as usize;
3535

3636
if next_closing == SIZE {
@@ -69,7 +69,7 @@ impl<'a, B: InputBlock<'a, SIZE>> DepthBlock<'a> for DepthVector32<'a, B> {
6969

7070
#[inline(always)]
7171
fn depth_at_end(&self) -> isize {
72-
#[cfg(target_arch = "x86")]
72+
#[cfg(target_arch = "x86")] // On wasm32 popcnt is built-in.
7373
debug_assert!(is_x86_feature_detected!("popcnt"));
7474
(((self.opening_count as i32) - self.closing_mask.count_ones() as i32) + self.depth) as isize
7575
}
@@ -81,7 +81,7 @@ impl<'a, B: InputBlock<'a, SIZE>> DepthBlock<'a> for DepthVector32<'a, B> {
8181

8282
#[inline(always)]
8383
fn estimate_lowest_possible_depth(&self) -> isize {
84-
#[cfg(target_arch = "x86")]
84+
#[cfg(target_arch = "x86")] // On wasm32 popcnt is built-in.
8585
debug_assert!(is_x86_feature_detected!("popcnt"));
8686
(self.depth - self.closing_mask.count_ones() as i32) as isize
8787
}

crates/rsonpath-lib/src/classification/simd.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ pub(crate) enum SimdTag {
458458
Ssse3,
459459
/// AVX2 detected.
460460
Avx2,
461-
///WASM32 detected
462-
Wasm32,
461+
/// WasmSimd128 detected
462+
WasmSimd128,
463463
}
464464

465465
/// Runtime-detected SIMD configuration guiding how to construct a [`Simd`] implementation for the engine.
@@ -502,6 +502,7 @@ impl SimdConfiguration {
502502
"sse2" => Some(SimdTag::Sse2),
503503
"ssse3" => Some(SimdTag::Ssse3),
504504
"avx2" => Some(SimdTag::Avx2),
505+
"wasmsimd128" => Some(SimdTag::WasmSimd128),
505506
_ => None,
506507
};
507508
let quotes = match quotes_str.to_ascii_lowercase().as_ref() {
@@ -564,11 +565,14 @@ pub(crate) fn configure() -> SimdConfiguration {
564565
let fast_quotes = is_x86_feature_detected!("pclmulqdq");
565566
let fast_popcnt = is_x86_feature_detected!("popcnt");
566567
}
567-
else if #[cfg(target_arch = "wasm32")]
568+
// Wasm lacks dynamic feature detection (see https://doc.rust-lang.org/stable/core/arch/wasm32/index.html)
569+
// Since SIMD is technically a proposal, to keep rsonpath usable as a library from Wasm contexts
570+
// without simd128 we require the target_feature on compile-time to enable SIMD.
571+
else if #[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
568572
{
569-
let highest_simd = SimdTag::Wasm32;
573+
let highest_simd = SimdTag::SimdWasm32;
570574
let fast_quotes = false;
571-
let fast_popcnt = false;
575+
let fast_popcnt = true; // popcnt is built-in on Wasm32
572576
}
573577
else
574578
{
@@ -593,7 +597,7 @@ impl Display for SimdConfiguration {
593597
SimdTag::Sse2 => "sse2",
594598
SimdTag::Ssse3 => "ssse3",
595599
SimdTag::Avx2 => "avx2",
596-
SimdTag::Wasm32 => "wasm32",
600+
SimdTag::WasmSimd128 => "wasmsimd128",
597601
};
598602
let quote_desc = if self.fast_quotes { "fast_quotes" } else { "slow_quotes" };
599603
let popcnt_desc = if self.fast_popcnt { "fast_popcnt" } else { "slow_popcnt" };
@@ -821,16 +825,8 @@ cfg_if! {
821825
>::new();
822826
$b
823827
}
824-
$crate::classification::simd::SimdTag::Wasm32 => {
825-
let $simd = $crate::classification::simd::ResolvedSimd::<
826-
$crate::classification::quotes::nosimd::Constructor,
827-
$crate::classification::structural::nosimd::Constructor,
828-
$crate::classification::depth::nosimd::Constructor,
829-
$crate::classification::memmem::nosimd::Constructor,
830-
{$crate::classification::simd::NOSIMD}
831-
>::new();
832-
$b
833-
}
828+
$crate::classification::simd::SimdTag::WasmSimd128 =>
829+
unreachable!("WasmSimd128 tag on x86_64 arch; this is an error in SIMD configuration")
834830
}
835831
}
836832
};
@@ -958,16 +954,8 @@ cfg_if! {
958954
>::new();
959955
$b
960956
}
961-
$crate::classification::simd::SimdTag::Wasm32 => {
962-
let $simd = $crate::classification::simd::ResolvedSimd::<
963-
$crate::classification::quotes::nosimd::Constructor,
964-
$crate::classification::structural::nosimd::Constructor,
965-
$crate::classification::depth::nosimd::Constructor,
966-
$crate::classification::memmem::nosimd::Constructor,
967-
{$crate::classification::simd::NOSIMD}
968-
>::new();
969-
$b
970-
}
957+
$crate::classification::simd::SimdTag::WasmSimd128 =>
958+
unreachable!("WasmSimd128 tag on x86_64 arch; this is an error in SIMD configuration")
971959
}
972960
}
973961
};

0 commit comments

Comments
 (0)