#![no_std]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_root_url = "https://docs.rs/cpufeatures/0.1.3"
)]
#[cfg(all(target_arch = "aarch64", any(target_os = "linux", target_os = "macos")))]
#[doc(hidden)]
pub mod aarch64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86;
#[cfg(not(any(
all(target_arch = "aarch64", any(target_os = "linux", target_os = "macos")),
target_arch = "x86",
target_arch = "x86_64"
)))]
compile_error!("This crate works only on `aarch64` (Linux/Mac), `x86`, and `x86-64` targets.");
#[macro_export]
macro_rules! new {
($mod_name:ident, $($tf:tt),+ $(,)?) => {
mod $mod_name {
use core::sync::atomic::{AtomicU8, Ordering::Relaxed};
const UNINIT: u8 = u8::max_value();
static STORAGE: AtomicU8 = AtomicU8::new(UNINIT);
#[derive(Copy, Clone, Debug)]
pub struct InitToken(());
impl InitToken {
#[inline(always)]
pub fn get(&self) -> bool {
$crate::__unless_target_features! {
$($tf),+ => {
STORAGE.load(Relaxed) == 1
}
}
}
}
#[inline]
pub fn init_get() -> (InitToken, bool) {
let res = $crate::__unless_target_features! {
$($tf),+ => {
let val = STORAGE.load(Relaxed);
if val == UNINIT {
let res = $crate::__detect_target_features!($($tf),+);
STORAGE.store(res as u8, Relaxed);
res
} else {
val == 1
}
}
};
(InitToken(()), res)
}
#[inline]
pub fn init() -> InitToken {
init_get().0
}
#[inline]
pub fn get() -> bool {
init_get().1
}
}
};
}