Skip to content
Merged
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
23 changes: 22 additions & 1 deletion zlib-rs/src/inflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,28 @@ impl State<'_> {
}
}

fn inflate_fast_help(state: &mut State, _start: usize) {
fn inflate_fast_help(state: &mut State, start: usize) {
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
if crate::cpu_features::is_enabled_avx2() {
// SAFETY: we've verified the target features
return unsafe { inflate_fast_help_avx2(state, start) };
}

inflate_fast_help_vanilla(state, start);
}

#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
#[target_feature(enable = "avx2")]
unsafe fn inflate_fast_help_avx2(state: &mut State, start: usize) {
inflate_fast_help_impl(state, start);
}

fn inflate_fast_help_vanilla(state: &mut State, start: usize) {
inflate_fast_help_impl(state, start);
}

#[inline(always)]
fn inflate_fast_help_impl(state: &mut State, _start: usize) {
let mut bit_reader = BitReader::new(&[]);
core::mem::swap(&mut bit_reader, &mut state.bit_reader);

Expand Down
20 changes: 12 additions & 8 deletions zlib-rs/src/inflate/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ impl<'a> Writer<'a> {

#[inline(always)]
pub fn extend_from_window(&mut self, window: &super::window::Window, range: Range<usize>) {
#[cfg(target_arch = "x86_64")]
if crate::cpu_features::is_enabled_avx512() {
return self.extend_from_window_help::<core::arch::x86_64::__m512i>(window, range);
}
// NOTE: the dynamic check for avx512 makes avx2 slower. Measure this carefully before re-enabling
//
// #[cfg(target_arch = "x86_64")]
// if crate::cpu_features::is_enabled_avx512() {
// return self.extend_from_window_help::<core::arch::x86_64::__m512i>(window, range);
// }

#[cfg(target_arch = "x86_64")]
if crate::cpu_features::is_enabled_avx2() {
Expand Down Expand Up @@ -138,10 +140,12 @@ impl<'a> Writer<'a> {

#[inline(always)]
pub fn copy_match(&mut self, offset_from_end: usize, length: usize) {
#[cfg(target_arch = "x86_64")]
if crate::cpu_features::is_enabled_avx512() {
return self.copy_match_help::<core::arch::x86_64::__m512i>(offset_from_end, length);
}
// NOTE: the dynamic check for avx512 makes avx2 slower. Measure this carefully before re-enabling
//
// #[cfg(target_arch = "x86_64")]
// if crate::cpu_features::is_enabled_avx512() {
// return self.copy_match_help::<core::arch::x86_64::__m512i>(offset_from_end, length);
// }

#[cfg(target_arch = "x86_64")]
if crate::cpu_features::is_enabled_avx2() {
Expand Down