Skip to content

Commit

Permalink
wasm: use wider loads/stores in copy_match
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Sep 26, 2024
1 parent f7c2f01 commit 64feab4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions zlib-rs/src/inflate/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl<'a> Writer<'a> {
return self.extend_from_window_help::<core::arch::aarch64::uint8x16_t>(window, range);
}

#[cfg(target_arch = "wasm32")]
if crate::cpu_features::is_enabled_simd128() {
return self.extend_from_window_help::<core::arch::wasm32::v128>(window, range);
}

self.extend_from_window_help::<u64>(window, range)
}

Expand Down Expand Up @@ -141,6 +146,11 @@ impl<'a> Writer<'a> {
.copy_match_help::<core::arch::aarch64::uint8x16_t>(offset_from_end, length);
}

#[cfg(target_arch = "wasm32")]
if crate::cpu_features::is_enabled_simd128() {
return self.copy_match_help::<core::arch::wasm32::v128>(offset_from_end, length);
}

self.copy_match_help::<u64>(offset_from_end, length)
}

Expand Down Expand Up @@ -324,6 +334,19 @@ impl Chunk for core::arch::aarch64::uint8x16_t {
}
}

#[cfg(target_arch = "wasm32")]
impl Chunk for core::arch::wasm32::v128 {
#[inline(always)]
unsafe fn load_chunk(from: *const MaybeUninit<u8>) -> Self {
core::arch::wasm32::v128_load(from.cast())
}

#[inline(always)]
unsafe fn store_chunk(out: *mut MaybeUninit<u8>, chunk: Self) {
core::arch::wasm32::v128_store(out as *mut Self, chunk)
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -368,6 +391,12 @@ mod test {
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::{__m128i, __m256i, __m512i};

#[cfg(target_arch = "aarch64")]
use core::arch::aarch64::uint8x16_t;

#[cfg(target_arch = "wasm32")]
use core::arch::wasm32::v128;

macro_rules! helper {
($func:expr) => {
let mut buf = test_array();
Expand Down Expand Up @@ -395,6 +424,16 @@ mod test {
helper!(Writer::copy_match_help::<__m128i>);
}

#[cfg(target_arch = "aarch64")]
if crate::cpu_features::is_enabled_neon() {
helper!(Writer::copy_match_help::<uint8x16_t>);
}

#[cfg(target_arch = "wasm32")]
if crate::cpu_features::is_enabled_simd128() {
helper!(Writer::copy_match_help::<v128>);
}

helper!(Writer::copy_match_help::<u64>);
}

Expand Down

0 comments on commit 64feab4

Please sign in to comment.