macro_rules! cfg_if {
($(
if #[cfg($meta:meta)] { $($tokens:tt)* }
) else * else {
$($tokens2:tt)*
}) => {
cfg_if! { @__items () ; $( ( ($meta) ($($tokens)*) ), )* ( () ($($tokens2)*) ), }
};
(
if #[cfg($i_met:meta)] { $($i_tokens:tt)* }
$( else if #[cfg($e_met:meta)] { $($e_tokens:tt)* } )*
) => {
cfg_if! {
@__items
() ;
( ($i_met) ($($i_tokens)*) ),
$( ( ($e_met) ($($e_tokens)*) ), )*
( () () ),
}
};
(@__items ($($not:meta,)*) ; ) => {};
(@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($tokens:tt)*) ), $($rest:tt)*) => {
#[cfg(all($($m,)* not(any($($not),*))))] cfg_if! { @__identity $($tokens)* }
cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* }
};
(@__identity $($tokens:tt)*) => { $($tokens)* };
}
macro_rules! select_implementation {
(
name: $fn_name:ident,
// Configuration meta for when to use arch-specific implementation that requires hard
// float ops
$( use_arch: $use_arch:meta, )?
// Configuration meta for when to use the arch module regardless of whether softfloats
// have been requested.
$( use_arch_required: $use_arch_required:meta, )?
args: $($arg:ident),+ ,
) => {
select_implementation! {
@cfg $($use_arch_required)?;
if true {
return super::arch::$fn_name( $($arg),+ );
}
}
#[cfg(arch_enabled)]
select_implementation! {
@cfg $($use_arch)?;
if true {
return super::arch::$fn_name( $($arg),+ );
}
}
};
(@cfg ; $ex:expr) => { };
(@cfg $provided:meta; $ex:expr) => { #[cfg($provided)] $ex };
}
#[cfg(f16_enabled)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
#[allow(unused_macros)]
macro_rules! hf16 {
($s:literal) => {{
const X: f16 = $crate::support::hf16($s);
X
}};
}
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf32 {
($s:literal) => {{
const X: f32 = $crate::support::hf32($s);
X
}};
}
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf64 {
($s:literal) => {{
const X: f64 = $crate::support::hf64($s);
X
}};
}
#[cfg(f128_enabled)]
#[allow(unused_macros)]
#[cfg_attr(feature = "unstable-public-internals", macro_export)]
macro_rules! hf128 {
($s:literal) => {{
const X: f128 = $crate::support::hf128($s);
X
}};
}
#[cfg(test)]
macro_rules! assert_biteq {
($left:expr, $right:expr, $($tt:tt)*) => {{
let l = $left;
let r = $right;
let bits = $crate::support::Int::leading_zeros(l.to_bits() - l.to_bits());
assert!(
$crate::support::Float::biteq(l, r),
"{}\nl: {l:?} ({lb:#0width$x} {lh})\nr: {r:?} ({rb:#0width$x} {rh})",
format_args!($($tt)*),
lb = l.to_bits(),
lh = $crate::support::Hexf(l),
rb = r.to_bits(),
rh = $crate::support::Hexf(r),
width = ((bits / 4) + 2) as usize,
);
}};
($left:expr, $right:expr $(,)?) => {
assert_biteq!($left, $right, "")
};
}