Skip to content

Commit

Permalink
Only build Paeth bpp=3 and bpp=6 routines on x86; fixes build on ARM
Browse files Browse the repository at this point in the history
  • Loading branch information
Shnatsel committed Dec 2, 2024
1 parent c97f54c commit 5c2538c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use crate::common::BytesPerPixel;
/// feature of Rust gets stabilized.
#[cfg(feature = "unstable")]
mod simd {
// unused imports may ocur in this module due to conditional compilation
#![allow(unused_imports)]
use std::simd::cmp::{SimdOrd, SimdPartialEq, SimdPartialOrd};
use std::simd::num::{SimdInt, SimdUint};
use std::simd::{u8x4, u8x8, LaneCount, Simd, SimdElement, SupportedLaneCount};
Expand All @@ -24,6 +26,7 @@ mod simd {
/// Funnily, the autovectorizer does a better job here
/// than a handwritten algorithm using std::simd!
/// We used to have a handwritten one but this is just faster.
#[cfg(target_arch = "x86_64")]
fn paeth_predictor<const N: usize>(
a: Simd<i16, N>,
b: Simd<i16, N>,
Expand Down Expand Up @@ -75,6 +78,7 @@ mod simd {
///
/// `b` is the current pixel in the previous row. `x` is the current pixel in the current row.
/// See also https://www.w3.org/TR/png/#filter-byte-positions
#[cfg(target_arch = "x86_64")]
fn paeth_step<const N: usize>(
state: &mut PaethState<i16, N>,
b: Simd<u8, N>,
Expand Down Expand Up @@ -112,15 +116,18 @@ mod simd {
state.a = *x;
}

#[cfg(target_arch = "x86_64")]
fn load3(src: &[u8]) -> u8x4 {
u8x4::from_array([src[0], src[1], src[2], 0])
}

#[cfg(target_arch = "x86_64")]
fn store3(src: u8x4, dest: &mut [u8]) {
dest[0..3].copy_from_slice(&src.to_array()[0..3])
}

/// Undoes `FilterType::Paeth` for `BytesPerPixel::Three`.
#[cfg(target_arch = "x86_64")]
pub fn unfilter_paeth3(mut prev_row: &[u8], mut curr_row: &mut [u8]) {
debug_assert_eq!(prev_row.len(), curr_row.len());
debug_assert_eq!(prev_row.len() % 3, 0);
Expand Down Expand Up @@ -175,15 +182,18 @@ mod simd {
}
}

#[cfg(target_arch = "x86_64")]
fn load6(src: &[u8]) -> u8x8 {
u8x8::from_array([src[0], src[1], src[2], src[3], src[4], src[5], 0, 0])
}

#[cfg(target_arch = "x86_64")]
fn store6(src: u8x8, dest: &mut [u8]) {
dest[0..6].copy_from_slice(&src.to_array()[0..6])
}

/// Undoes `FilterType::Paeth` for `BytesPerPixel::Six`.
#[cfg(target_arch = "x86_64")]
pub fn unfilter_paeth6(mut prev_row: &[u8], mut curr_row: &mut [u8]) {
debug_assert_eq!(prev_row.len(), curr_row.len());
debug_assert_eq!(prev_row.len() % 6, 0);
Expand Down

0 comments on commit 5c2538c

Please sign in to comment.