Skip to content

Commit

Permalink
feat: use is_x86_feature_detected! for aarch64 too
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Feb 24, 2024
1 parent c2a6849 commit 5346f33
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ use core::arch::aarch64::*;
pub(crate) const USE_CHECK_FN: bool = false;
const CHUNK_SIZE: usize = core::mem::size_of::<uint8x16_t>();

cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
#[inline(always)]
fn has_neon() -> bool {
is_aarch64_feature_detected!("neon")
}
} else {
#[inline(always)]
fn has_neon() -> bool {
cfg!(target_feature = "neon")
}
}
}

#[inline]
pub(crate) unsafe fn encode<const UPPER: bool>(input: &[u8], output: *mut u8) {
if input.len() < CHUNK_SIZE || !cfg!(target_feature = "neon") || cfg!(miri) {
if cfg!(miri) || !has_neon() || input.len() < CHUNK_SIZE {
return generic::encode::<UPPER>(input, output);
}
encode_neon::<UPPER>(input, output);
Expand Down
4 changes: 1 addition & 3 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use cfg_if::cfg_if;

pub(crate) mod generic;

// The main implementation functions.
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(feature = "force-generic")] {
pub(crate) use generic as imp;
} else if #[cfg(feature = "portable-simd")] {
Expand Down
6 changes: 3 additions & 3 deletions src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const T_MASK: i32 = 65535;
cfg_if::cfg_if! {
if #[cfg(feature = "std")] {
#[inline(always)]
pub(super) fn has_sse2() -> bool {
fn has_sse2() -> bool {
is_x86_feature_detected!("sse2")
}
#[inline(always)]
pub(super) fn has_ssse3() -> bool {
fn has_ssse3() -> bool {
is_x86_feature_detected!("ssse3")
}
#[inline(always)]
pub(super) fn has_avx2() -> bool {
fn has_avx2() -> bool {
is_x86_feature_detected!("avx2")
}
} else {
Expand Down

0 comments on commit 5346f33

Please sign in to comment.