use crate::tokens::SimdToken;
#[allow(deprecated)]
use crate::tokens::{Has128BitSimd, Has256BitSimd, Has512BitSimd, HasX64V2, HasX64V4};
use core::sync::atomic::{AtomicBool, AtomicU8, Ordering};
#[allow(dead_code)]
pub(super) static X64_V1_CACHE: AtomicU8 = AtomicU8::new(0);
#[allow(dead_code)]
pub(super) static X64_V1_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_V2_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_V2_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_CRYPTO_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_CRYPTO_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_V3_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_V3_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_V3_CRYPTO_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_V3_CRYPTO_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_V4_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_V4_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static X64_V4X_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static X64_V4X_DISABLED: AtomicBool = AtomicBool::new(false);
pub(super) static AVX512_FP16_CACHE: AtomicU8 = AtomicU8::new(0);
pub(super) static AVX512_FP16_DISABLED: AtomicBool = AtomicBool::new(false);
#[derive(Clone, Copy, Debug)]
pub struct X64V1Token {
_private: (),
}
impl crate::tokens::Sealed for X64V1Token {}
impl SimdToken for X64V1Token {
const NAME: &'static str = "x86-64-v1";
const TARGET_FEATURES: &'static str = "sse,sse2";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(not(feature = "testable_dispatch"))]
{
Some(true)
}
#[cfg(feature = "testable_dispatch")]
{
None
}
}
#[allow(deprecated)]
#[inline]
fn summon() -> Option<Self> {
#[cfg(not(feature = "testable_dispatch"))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(feature = "testable_dispatch")]
{
match X64_V1_CACHE.load(Ordering::Relaxed) {
1 => None,
_ => Some(unsafe { Self::forge_token_dangerously() }),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V1Token {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
not(feature = "testable_dispatch")
)))]
{
X64_V1_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V1_CACHE.store(v, Ordering::Relaxed);
X64_V2_DISABLED.store(disabled, Ordering::Relaxed);
X64_V2_CACHE.store(v, Ordering::Relaxed);
X64_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V3_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CACHE.store(v, Ordering::Relaxed);
X64_V3_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V4_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V1_DISABLED.load(Ordering::Relaxed))
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64V2Token {
_private: (),
}
impl crate::tokens::Sealed for X64V2Token {}
impl SimdToken for X64V2Token {
const NAME: &'static str = "x86-64-v2";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b";
const ENABLE_TARGET_FEATURES: &'static str =
"-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b";
const DISABLE_TARGET_FEATURES: &'static str =
"-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
)))]
{
match X64_V2_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_v2_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V2Token {
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64V2Token {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
)))]
{
X64_V2_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V2_CACHE.store(v, Ordering::Relaxed);
X64_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V3_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CACHE.store(v, Ordering::Relaxed);
X64_V3_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V4_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V2_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_v2_detect() -> Option<X64V2Token> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b");
X64_V2_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64V2Token as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64CryptoToken {
_private: (),
}
impl crate::tokens::Sealed for X64CryptoToken {}
impl SimdToken for X64CryptoToken {
const NAME: &'static str = "x86-64 Crypto";
const TARGET_FEATURES: &'static str =
"sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,pclmulqdq,aes";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+pclmulqdq,+aes";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-pclmulqdq,-aes";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
)))]
{
match X64_CRYPTO_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_crypto_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64CryptoToken {
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64CryptoToken {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
)))]
{
X64_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V3_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V4_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_CRYPTO_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "pclmulqdq",
target_feature = "aes",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_crypto_detect() -> Option<X64CryptoToken> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("pclmulqdq")
&& crate::is_x86_feature_available!("aes");
X64_CRYPTO_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64CryptoToken as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64V3Token {
_private: (),
}
impl crate::tokens::Sealed for X64V3Token {}
impl SimdToken for X64V3Token {
const NAME: &'static str = "x86-64-v3";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+movbe";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-movbe";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
)))]
{
match X64_V3_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_v3_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V3Token {
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64V3Token {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
)))]
{
X64_V3_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V3_CACHE.store(v, Ordering::Relaxed);
X64_V3_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
X64_V3_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V4_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V3_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_v3_detect() -> Option<X64V3Token> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("avx")
&& crate::is_x86_feature_available!("avx2")
&& crate::is_x86_feature_available!("fma")
&& crate::is_x86_feature_available!("bmi1")
&& crate::is_x86_feature_available!("bmi2")
&& crate::is_x86_feature_available!("f16c")
&& crate::is_x86_feature_available!("lzcnt")
&& crate::is_x86_feature_available!("movbe");
X64_V3_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64V3Token as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64V3CryptoToken {
_private: (),
}
impl crate::tokens::Sealed for X64V3CryptoToken {}
impl SimdToken for X64V3CryptoToken {
const NAME: &'static str = "x86-64-v3 Crypto";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe,pclmulqdq,aes,vpclmulqdq,vaes";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+movbe,+pclmulqdq,+aes,+vpclmulqdq,+vaes";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-movbe,-pclmulqdq,-aes,-vpclmulqdq,-vaes";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
match X64_V3_CRYPTO_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_v3_crypto_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V3CryptoToken {
#[allow(deprecated)]
#[inline(always)]
pub fn v3(self) -> X64V3Token {
unsafe { X64V3Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn x64_crypto(self) -> X64CryptoToken {
unsafe { X64CryptoToken::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64V3CryptoToken {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
X64_V3_CRYPTO_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V3_CRYPTO_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V3_CRYPTO_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "vpclmulqdq",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_v3_crypto_detect() -> Option<X64V3CryptoToken> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("avx")
&& crate::is_x86_feature_available!("avx2")
&& crate::is_x86_feature_available!("fma")
&& crate::is_x86_feature_available!("bmi1")
&& crate::is_x86_feature_available!("bmi2")
&& crate::is_x86_feature_available!("f16c")
&& crate::is_x86_feature_available!("lzcnt")
&& crate::is_x86_feature_available!("movbe")
&& crate::is_x86_feature_available!("pclmulqdq")
&& crate::is_x86_feature_available!("aes")
&& crate::is_x86_feature_available!("vpclmulqdq")
&& crate::is_x86_feature_available!("vaes");
X64_V3_CRYPTO_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64V3CryptoToken as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64V4Token {
_private: (),
}
impl crate::tokens::Sealed for X64V4Token {}
impl SimdToken for X64V4Token {
const NAME: &'static str = "AVX-512";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe,pclmulqdq,aes,avx512f,avx512bw,avx512cd,avx512dq,avx512vl";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+movbe,+pclmulqdq,+aes,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-movbe,-pclmulqdq,-aes,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
)))]
{
match X64_V4_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_v4_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V4Token {
#[allow(deprecated)]
#[inline(always)]
pub fn v3(self) -> X64V3Token {
unsafe { X64V3Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn x64_crypto(self) -> X64CryptoToken {
unsafe { X64CryptoToken::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64V4Token {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
)))]
{
X64_V4_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V4_CACHE.store(v, Ordering::Relaxed);
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
X64_V4X_CACHE.store(v, Ordering::Relaxed);
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V4_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_v4_detect() -> Option<X64V4Token> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("avx")
&& crate::is_x86_feature_available!("avx2")
&& crate::is_x86_feature_available!("fma")
&& crate::is_x86_feature_available!("bmi1")
&& crate::is_x86_feature_available!("bmi2")
&& crate::is_x86_feature_available!("f16c")
&& crate::is_x86_feature_available!("lzcnt")
&& crate::is_x86_feature_available!("movbe")
&& crate::is_x86_feature_available!("pclmulqdq")
&& crate::is_x86_feature_available!("aes")
&& crate::is_x86_feature_available!("avx512f")
&& crate::is_x86_feature_available!("avx512bw")
&& crate::is_x86_feature_available!("avx512cd")
&& crate::is_x86_feature_available!("avx512dq")
&& crate::is_x86_feature_available!("avx512vl");
X64_V4_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64V4Token as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct X64V4xToken {
_private: (),
}
impl crate::tokens::Sealed for X64V4xToken {}
impl SimdToken for X64V4xToken {
const NAME: &'static str = "x86-64-v4x";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe,pclmulqdq,aes,avx512f,avx512bw,avx512cd,avx512dq,avx512vl,avx512vpopcntdq,avx512ifma,avx512vbmi,avx512vbmi2,avx512bitalg,avx512vnni,vpclmulqdq,gfni,vaes";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+movbe,+pclmulqdq,+aes,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl,+avx512vpopcntdq,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512bitalg,+avx512vnni,+vpclmulqdq,+gfni,+vaes";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-movbe,-pclmulqdq,-aes,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-avx512vpopcntdq,-avx512ifma,-avx512vbmi,-avx512vbmi2,-avx512bitalg,-avx512vnni,-vpclmulqdq,-gfni,-vaes";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
match X64_V4X_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => x64_v4x_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl X64V4xToken {
#[allow(deprecated)]
#[inline(always)]
pub fn v4(self) -> X64V4Token {
unsafe { X64V4Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn avx512(self) -> X64V4Token {
unsafe { X64V4Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v3_crypto(self) -> X64V3CryptoToken {
unsafe { X64V3CryptoToken::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v3(self) -> X64V3Token {
unsafe { X64V3Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn x64_crypto(self) -> X64CryptoToken {
unsafe { X64CryptoToken::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl X64V4xToken {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
X64_V4X_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
X64_V4X_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
{
Ok(X64_V4X_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512vpopcntdq",
target_feature = "avx512ifma",
target_feature = "avx512vbmi",
target_feature = "avx512vbmi2",
target_feature = "avx512bitalg",
target_feature = "avx512vnni",
target_feature = "vpclmulqdq",
target_feature = "gfni",
target_feature = "vaes",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn x64_v4x_detect() -> Option<X64V4xToken> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("avx")
&& crate::is_x86_feature_available!("avx2")
&& crate::is_x86_feature_available!("fma")
&& crate::is_x86_feature_available!("bmi1")
&& crate::is_x86_feature_available!("bmi2")
&& crate::is_x86_feature_available!("f16c")
&& crate::is_x86_feature_available!("lzcnt")
&& crate::is_x86_feature_available!("movbe")
&& crate::is_x86_feature_available!("pclmulqdq")
&& crate::is_x86_feature_available!("aes")
&& crate::is_x86_feature_available!("avx512f")
&& crate::is_x86_feature_available!("avx512bw")
&& crate::is_x86_feature_available!("avx512cd")
&& crate::is_x86_feature_available!("avx512dq")
&& crate::is_x86_feature_available!("avx512vl")
&& crate::is_x86_feature_available!("avx512vpopcntdq")
&& crate::is_x86_feature_available!("avx512ifma")
&& crate::is_x86_feature_available!("avx512vbmi")
&& crate::is_x86_feature_available!("avx512vbmi2")
&& crate::is_x86_feature_available!("avx512bitalg")
&& crate::is_x86_feature_available!("avx512vnni")
&& crate::is_x86_feature_available!("vpclmulqdq")
&& crate::is_x86_feature_available!("gfni")
&& crate::is_x86_feature_available!("vaes");
X64_V4X_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <X64V4xToken as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
#[derive(Clone, Copy, Debug)]
pub struct Avx512Fp16Token {
_private: (),
}
impl crate::tokens::Sealed for Avx512Fp16Token {}
impl SimdToken for Avx512Fp16Token {
const NAME: &'static str = "AVX-512FP16";
const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,cmpxchg16b,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,movbe,pclmulqdq,aes,avx512f,avx512bw,avx512cd,avx512dq,avx512vl,avx512fp16";
const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+cmpxchg16b,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+movbe,+pclmulqdq,+aes,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl,+avx512fp16";
const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-cmpxchg16b,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-movbe,-pclmulqdq,-aes,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-avx512fp16";
#[inline]
fn compiled_with() -> Option<bool> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
))]
{
Some(true)
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
)))]
{
None
}
}
#[allow(deprecated)]
#[inline(always)]
fn summon() -> Option<Self> {
#[cfg(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
))]
{
Some(unsafe { Self::forge_token_dangerously() })
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
)))]
{
match AVX512_FP16_CACHE.load(Ordering::Relaxed) {
2 => Some(unsafe { Self::forge_token_dangerously() }),
1 => None,
_ => avx512_fp16_detect(),
}
}
}
#[inline(always)]
#[allow(deprecated)]
unsafe fn forge_token_dangerously() -> Self {
Self { _private: () }
}
}
impl Avx512Fp16Token {
#[allow(deprecated)]
#[inline(always)]
pub fn v4(self) -> X64V4Token {
unsafe { X64V4Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn avx512(self) -> X64V4Token {
unsafe { X64V4Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v3(self) -> X64V3Token {
unsafe { X64V3Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn x64_crypto(self) -> X64CryptoToken {
unsafe { X64CryptoToken::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v2(self) -> X64V2Token {
unsafe { X64V2Token::forge_token_dangerously() }
}
#[allow(deprecated)]
#[inline(always)]
pub fn v1(self) -> X64V1Token {
unsafe { X64V1Token::forge_token_dangerously() }
}
}
impl Avx512Fp16Token {
#[allow(clippy::needless_return)]
pub fn dangerously_disable_token_process_wide(
disabled: bool,
) -> Result<(), crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
))]
{
let _ = disabled;
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
)))]
{
AVX512_FP16_DISABLED.store(disabled, Ordering::Relaxed);
let v = if disabled { 1 } else { 0 };
AVX512_FP16_CACHE.store(v, Ordering::Relaxed);
Ok(())
}
}
#[allow(clippy::needless_return)]
pub fn manually_disabled() -> Result<bool, crate::tokens::CompileTimeGuaranteedError> {
#[cfg(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
))]
{
return Err(crate::tokens::CompileTimeGuaranteedError {
token_name: Self::NAME,
target_features: Self::TARGET_FEATURES,
disable_flags: Self::DISABLE_TARGET_FEATURES,
});
}
#[cfg(not(all(
target_feature = "sse",
target_feature = "sse2",
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
)))]
{
Ok(AVX512_FP16_DISABLED.load(Ordering::Relaxed))
}
}
}
#[cfg(not(all(
target_feature = "sse3",
target_feature = "ssse3",
target_feature = "sse4.1",
target_feature = "sse4.2",
target_feature = "popcnt",
target_feature = "cmpxchg16b",
target_feature = "avx",
target_feature = "avx2",
target_feature = "fma",
target_feature = "bmi1",
target_feature = "bmi2",
target_feature = "f16c",
target_feature = "lzcnt",
target_feature = "movbe",
target_feature = "pclmulqdq",
target_feature = "aes",
target_feature = "avx512f",
target_feature = "avx512bw",
target_feature = "avx512cd",
target_feature = "avx512dq",
target_feature = "avx512vl",
target_feature = "avx512fp16",
not(feature = "testable_dispatch")
)))]
#[cold]
#[inline(never)]
#[allow(deprecated)]
fn avx512_fp16_detect() -> Option<Avx512Fp16Token> {
let available = crate::is_x86_feature_available!("sse3")
&& crate::is_x86_feature_available!("ssse3")
&& crate::is_x86_feature_available!("sse4.1")
&& crate::is_x86_feature_available!("sse4.2")
&& crate::is_x86_feature_available!("popcnt")
&& crate::is_x86_feature_available!("cmpxchg16b")
&& crate::is_x86_feature_available!("avx")
&& crate::is_x86_feature_available!("avx2")
&& crate::is_x86_feature_available!("fma")
&& crate::is_x86_feature_available!("bmi1")
&& crate::is_x86_feature_available!("bmi2")
&& crate::is_x86_feature_available!("f16c")
&& crate::is_x86_feature_available!("lzcnt")
&& crate::is_x86_feature_available!("movbe")
&& crate::is_x86_feature_available!("pclmulqdq")
&& crate::is_x86_feature_available!("aes")
&& crate::is_x86_feature_available!("avx512f")
&& crate::is_x86_feature_available!("avx512bw")
&& crate::is_x86_feature_available!("avx512cd")
&& crate::is_x86_feature_available!("avx512dq")
&& crate::is_x86_feature_available!("avx512vl")
&& crate::is_x86_feature_available!("avx512fp16");
AVX512_FP16_CACHE.store(if available { 2 } else { 1 }, Ordering::Relaxed);
if available {
Some(unsafe { <Avx512Fp16Token as SimdToken>::forge_token_dangerously() })
} else {
None
}
}
pub type Sse2Token = X64V1Token;
pub type Desktop64 = X64V3Token;
#[deprecated(
since = "0.9.9",
note = "Use X64V3Token or Desktop64 instead. Avx2FmaToken is misleading — V3 includes BMI1/2, F16C, and more, not just AVX2+FMA."
)]
pub type Avx2FmaToken = X64V3Token;
pub type Avx512Token = X64V4Token;
pub type Server64 = X64V4Token;
pub type Avx512ModernToken = X64V4xToken;
#[allow(deprecated)]
impl Has128BitSimd for X64V1Token {}
#[allow(deprecated)]
impl Has128BitSimd for X64V2Token {}
#[allow(deprecated)]
impl Has128BitSimd for X64CryptoToken {}
#[allow(deprecated)]
impl Has128BitSimd for X64V3Token {}
#[allow(deprecated)]
impl Has128BitSimd for X64V3CryptoToken {}
#[allow(deprecated)]
impl Has128BitSimd for X64V4Token {}
#[allow(deprecated)]
impl Has128BitSimd for X64V4xToken {}
#[allow(deprecated)]
impl Has128BitSimd for Avx512Fp16Token {}
#[allow(deprecated)]
impl Has256BitSimd for X64V3Token {}
#[allow(deprecated)]
impl Has256BitSimd for X64V3CryptoToken {}
#[allow(deprecated)]
impl Has256BitSimd for X64V4Token {}
#[allow(deprecated)]
impl Has256BitSimd for X64V4xToken {}
#[allow(deprecated)]
impl Has256BitSimd for Avx512Fp16Token {}
#[allow(deprecated)]
impl Has512BitSimd for X64V4Token {}
#[allow(deprecated)]
impl Has512BitSimd for X64V4xToken {}
#[allow(deprecated)]
impl Has512BitSimd for Avx512Fp16Token {}
impl HasX64V2 for X64V2Token {}
impl HasX64V2 for X64CryptoToken {}
impl HasX64V2 for X64V3Token {}
impl HasX64V2 for X64V3CryptoToken {}
impl HasX64V2 for X64V4Token {}
impl HasX64V2 for X64V4xToken {}
impl HasX64V2 for Avx512Fp16Token {}
impl HasX64V4 for X64V4Token {}
impl HasX64V4 for X64V4xToken {}
impl HasX64V4 for Avx512Fp16Token {}