Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]
[target.'cfg(not(target_arch = "wasm32"))'] # lld is not supported for wasm
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[alias]
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ members = [
"crates/rsonpath-lib",
"crates/rsonpath-syntax",
"crates/rsonpath-syntax-proptest",
"crates/rsonpath-test",
"crates/rsonpath-test"
]

exclude = ["crates/rsonpath-benchmarks", "crates/rsonpath-test-codegen"]
exclude = ["crates/rsonpath-benchmarks", "crates/rsonpath-test-codegen", "web/rsonpath-website"]

resolver = "2"

Expand Down
2 changes: 2 additions & 0 deletions crates/rsonpath-lib/src/classification/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub(crate) mod avx2_64;
pub(crate) mod sse2_32;
#[cfg(target_arch = "x86_64")]
pub(crate) mod sse2_64;
#[cfg(target_arch = "wasm32")]
pub(crate) mod wasm_32;

pub(crate) trait DepthImpl {
type Classifier<'i, I, Q>: DepthIterator<'i, I, Q, MaskType, BLOCK_SIZE>
Expand Down
4 changes: 2 additions & 2 deletions crates/rsonpath-lib/src/classification/depth/shared.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(target_arch = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "wasm32"))]
pub(super) mod mask_32;
#[cfg(target_arch = "x86_64")]
pub(super) mod mask_64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "wasm32"))]
pub(super) mod vector_128;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(super) mod vector_256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub(crate) struct DepthVector32<'a, B: InputBlock<'a, SIZE>> {
impl<'a, B: InputBlock<'a, SIZE>> DepthBlock<'a> for DepthVector32<'a, B> {
#[inline(always)]
fn advance_to_next_depth_decrease(&mut self) -> bool {
debug_assert!(is_x86_feature_detected!("popcnt"));
#[cfg(target_arch = "x86")] // On wasm32 popcnt is built-in.
debug_assert!(!is_x86_feature_detected!("popcnt"));
let next_closing = self.closing_mask.trailing_zeros() as usize;

if next_closing == SIZE {
Expand Down Expand Up @@ -68,6 +69,7 @@ impl<'a, B: InputBlock<'a, SIZE>> DepthBlock<'a> for DepthVector32<'a, B> {

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

#[inline(always)]
fn estimate_lowest_possible_depth(&self) -> isize {
#[cfg(target_arch = "x86")] // On wasm32 popcnt is built-in.
debug_assert!(is_x86_feature_detected!("popcnt"));
(self.depth - self.closing_mask.count_ones() as i32) as isize
}
Expand Down
40 changes: 40 additions & 0 deletions crates/rsonpath-lib/src/classification/depth/shared/vector_128.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::classification::structural::BracketType;

#[cfg(target_arch = "wasm32")]
use core::arch::wasm32::*;
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
Expand All @@ -9,6 +11,7 @@ pub(crate) struct DelimiterClassifierImpl128 {
opening: i8,
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
impl DelimiterClassifierImpl128 {
pub(crate) fn new(opening: BracketType) -> Self {
let opening = match opening {
Expand Down Expand Up @@ -45,3 +48,40 @@ impl DelimiterClassifierImpl128 {
}
}
}

#[cfg(target_arch = "wasm32")]
impl DelimiterClassifierImpl128 {
pub(crate) fn new(opening: BracketType) -> Self {
let opening = match opening {
BracketType::Square => b'[',
BracketType::Curly => b'{',
};
Self { opening: opening as i8 }
}

#[inline(always)]
unsafe fn opening_mask(&self) -> v128 {
i8x16_splat(self.opening)
}

#[inline(always)]
unsafe fn closing_mask(&self) -> v128 {
i8x16_splat(self.opening + 2)
}

#[target_feature(enable = "simd128")]
#[inline]
pub(crate) unsafe fn get_opening_and_closing_masks(&self, bytes: &[u8]) -> (u16, u16) {
assert_eq!(16, bytes.len());

let byte_vector = v128_load(bytes.as_ptr() as *const v128);

let opening_brace_cmp = i8x16_eq(byte_vector, self.opening_mask());
let closing_brace_cmp = i8x16_eq(byte_vector, self.closing_mask());

let opening_mask = i8x16_bitmask(opening_brace_cmp) as u16;
let closing_mask = i8x16_bitmask(closing_brace_cmp) as u16;

(opening_mask, closing_mask)
}
}
63 changes: 63 additions & 0 deletions crates/rsonpath-lib/src/classification/depth/wasm_32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//The errors about mask_32 don't need to be fixed because they go away when the website is compiled
use super::{
shared::{mask_32::DepthVector32, vector_128::DelimiterClassifierImpl128},
*,
};
use crate::{
classification::{mask::m32, QuoteClassifiedBlock, ResumeClassifierBlockState},
debug,
input::InputBlock,
};
use core::marker::PhantomData;

const SIZE: usize = 32;

shared::depth_classifier!(WasmVectorIterator32, DelimiterClassifierImpl128, DepthVector32, 32, u32);

#[inline(always)]
fn new_vector<'a, B: InputBlock<'a, SIZE>>(
bytes: QuoteClassifiedBlock<B, u32, SIZE>,
classifier: &DelimiterClassifierImpl128,
) -> DepthVector32<'a, B> {
new_vector_from(bytes, classifier, 0)
}

#[inline(always)]
fn new_vector_from<'a, B: InputBlock<'a, SIZE>>(
bytes: QuoteClassifiedBlock<B, u32, SIZE>,
classifier: &DelimiterClassifierImpl128,
idx: usize,
) -> DepthVector32<'a, B> {
// SAFETY: target_feature invariant
unsafe { new_wasm(bytes, classifier, idx) }
}

#[inline(always)]
unsafe fn new_wasm<'a, B: InputBlock<'a, SIZE>>(
bytes: QuoteClassifiedBlock<B, u32, SIZE>,
classifier: &DelimiterClassifierImpl128,
start_idx: usize,
) -> DepthVector32<'a, B> {
let idx_mask = 0xFFFF_FFFF_u32 << start_idx;

let (block1, block2) = bytes.block.halves();

let (opening_mask1, closing_mask1) = classifier.get_opening_and_closing_masks(block1);
let (opening_mask2, closing_mask2) = classifier.get_opening_and_closing_masks(block2);

let combined_opening_mask = m32::combine_16(opening_mask1, opening_mask2);
let combined_closing_mask = m32::combine_16(closing_mask1, closing_mask2);

let opening_mask = combined_opening_mask & (!bytes.within_quotes_mask) & idx_mask;
let closing_mask = combined_closing_mask & (!bytes.within_quotes_mask) & idx_mask;

DepthVector32 {
quote_classified: bytes,
opening_mask,
closing_mask,
opening_count: opening_mask.count_ones(),
depth: 0,
idx: 0,
phantom: PhantomData,
}
}
2 changes: 2 additions & 0 deletions crates/rsonpath-lib/src/classification/memmem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub(crate) mod avx2_64;
pub(crate) mod sse2_32;
#[cfg(target_arch = "x86_64")]
pub(crate) mod sse2_64;
#[cfg(target_arch = "wasm32")]
pub(crate) mod wasm_32;

pub(crate) trait MemmemImpl {
type Classifier<'i, 'b, 'r, I, R>: Memmem<'i, 'b, 'r, I, BLOCK_SIZE>
Expand Down
4 changes: 2 additions & 2 deletions crates/rsonpath-lib/src/classification/memmem/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use crate::{
string_pattern::StringPattern,
};

#[cfg(target_arch = "x86")]
#[cfg(any(target_arch = "x86", target_arch = "wasm32"))]
pub(super) mod mask_32;
#[cfg(target_arch = "x86_64")]
pub(super) mod mask_64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "wasm32"))]
pub(super) mod vector_128;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(super) mod vector_256;
Expand Down
35 changes: 35 additions & 0 deletions crates/rsonpath-lib/src/classification/memmem/shared/vector_128.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#[cfg(target_arch = "wasm32")]
use ::core::arch::wasm32::*;
#[cfg(target_arch = "x86")]
use ::core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use ::core::arch::x86_64::*;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub(crate) struct BlockClassifier128 {
first: __m128i,
second: __m128i,
}

#[cfg(target_arch = "wasm32")]
pub(crate) struct BlockClassifier128 {
first: v128,
second: v128,
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
impl BlockClassifier128 {
#[target_feature(enable = "sse2")]
pub(crate) unsafe fn new(first: u8, second: u8) -> Self {
Expand All @@ -31,6 +41,31 @@ impl BlockClassifier128 {
}
}

#[cfg(target_arch = "wasm32")]
impl BlockClassifier128 {
#[target_feature(enable = "simd128")]
pub(crate) unsafe fn new(first: u8, second: u8) -> Self {
Self {
first: i8x16_splat(first as i8),
second: i8x16_splat(second as i8),
}
}

#[target_feature(enable = "simd128")]
pub(crate) unsafe fn classify_block(&self, block: &[u8]) -> BlockClassification128 {
debug_assert_eq!(block.len(), 16);
let byte_vector = v128_load(block.as_ptr() as *const v128);

let first_cmp_vector = i8x16_eq(byte_vector, self.first);
let second_cmp_vector = i8x16_eq(byte_vector, self.second);

let first = i8x16_bitmask(first_cmp_vector) as u16;
let second = i8x16_bitmask(second_cmp_vector) as u16;

BlockClassification128 { first, second }
}
}

pub(crate) struct BlockClassification128 {
pub(crate) first: u16,
pub(crate) second: u16,
Expand Down
Loading
Loading