Skip to content

Commit

Permalink
fn dav1d_get_cpu_flags_arm: Use `is_{arm,aarch64}_feature_detected!…
Browse files Browse the repository at this point in the history
…` for CPU feature detection.

`is_arm_feature_detected!` is still unstable (rust-lang/rust#111190),
so we have to enable `#![feature(stdsimd)]` on `arm`,
though it doesn't look like this part of `stdsimd` is likely to change.
  • Loading branch information
kkysen committed Sep 25, 2023
1 parent 6b8d28b commit 8fdc218
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(c_variadic)]
#![feature(core_intrinsics)]
#![feature(extern_types)]
#![cfg_attr(target_arch = "arm", feature(stdsimd))]

#[cfg(not(any(feature = "bitdepth_8", feature = "bitdepth_16")))]
compile_error!("No bitdepths enabled. Enable one or more of the following features: `bitdepth_8`, `bitdepth_16`");
Expand Down
28 changes: 9 additions & 19 deletions src/arm/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
use bitflags::bitflags;
use cfg_if::cfg_if;
use std::arch;
use std::ffi::c_uint;
use std::ffi::c_ulong;

bitflags! {
pub struct CpuFlags: c_uint {
const NEON = 1 << 0;
}
}

pub const NEON_HWCAP: c_ulong = 1 << 12;

#[cold]
pub unsafe fn dav1d_get_cpu_flags_arm() -> CpuFlags {
let mut flags = CpuFlags::empty();

cfg_if! {
if #[cfg(any(
target_arch = "aarch64",
target_os = "windows",
target_os = "macos"
))] {
flags |= CpuFlags::NEON;
} else if #[cfg(target_arch = "arm")] {
if (libc::getauxval(libc::AT_HWCAP) & NEON_HWCAP) != 0 {
flags |= CpuFlags::NEON;
}
} else if #[cfg(target_os = "android")] {
// TODO: Support Android by parsing `/proc/cpuinfo` the way the original C does.
todo!("Android is not yet supported")
}
#[cfg(target_arch = "arm")]
if arch::is_arm_feature_detected!("neon") {
flags |= CpuFlags::NEON;
}

#[cfg(target_arch = "aarch64")]
if arch::is_aarch64_feature_detected!("neon") {
flags |= CpuFlags::NEON;
}

flags
Expand Down

0 comments on commit 8fdc218

Please sign in to comment.