#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct F64BuiltinCapabilities {
pub basic_f64: bool,
pub exp: bool,
pub log: bool,
pub exp2: bool,
pub log2: bool,
pub sin: bool,
pub cos: bool,
pub sqrt: bool,
pub fma: bool,
pub abs_min_max: bool,
pub composite_transcendental: bool,
pub exp_log_chain: bool,
pub shared_mem_f64: bool,
pub df64_arith: bool,
pub df64_transcendentals_safe: bool,
pub df64_fma_two_prod: bool,
pub df64_workgroup_reduce: bool,
}
impl F64BuiltinCapabilities {
#[must_use]
pub const fn none() -> Self {
Self {
basic_f64: false,
exp: false,
log: false,
exp2: false,
log2: false,
sin: false,
cos: false,
sqrt: false,
fma: false,
abs_min_max: false,
composite_transcendental: false,
exp_log_chain: false,
shared_mem_f64: false,
df64_arith: false,
df64_transcendentals_safe: false,
df64_fma_two_prod: false,
df64_workgroup_reduce: false,
}
}
#[must_use]
pub const fn full() -> Self {
Self {
basic_f64: true,
exp: true,
log: true,
exp2: true,
log2: true,
sin: true,
cos: true,
sqrt: true,
fma: true,
abs_min_max: true,
composite_transcendental: true,
exp_log_chain: true,
shared_mem_f64: true,
df64_arith: true,
df64_transcendentals_safe: true,
df64_fma_two_prod: true,
df64_workgroup_reduce: true,
}
}
#[must_use]
pub fn can_compile_f64(&self) -> bool {
self.basic_f64
}
#[must_use]
pub fn has_f64_transcendentals(&self) -> bool {
self.basic_f64
&& self.sqrt
&& self.abs_min_max
&& self.sin
&& self.cos
&& self.exp
&& self.log
&& self.fma
&& self.composite_transcendental
&& self.exp_log_chain
}
#[must_use]
pub fn needs_exp_log_workaround(&self) -> bool {
!self.basic_f64 || !self.exp || !self.log
}
#[must_use]
pub fn needs_sqrt_f64_workaround(&self) -> bool {
!self.basic_f64 || !self.sqrt
}
#[must_use]
pub fn needs_sin_f64_workaround(&self) -> bool {
!self.basic_f64 || !self.sin
}
#[must_use]
pub fn needs_cos_f64_workaround(&self) -> bool {
!self.basic_f64 || !self.cos
}
#[must_use]
pub fn needs_shared_mem_f64_workaround(&self) -> bool {
!self.basic_f64 || !self.shared_mem_f64
}
#[must_use]
pub fn needs_df64_transcendental_stripping(&self) -> bool {
!self.df64_transcendentals_safe
}
#[must_use]
pub fn can_use_df64(&self) -> bool {
self.df64_arith
}
#[must_use]
pub fn needs_df64_reduce_workaround(&self) -> bool {
!self.df64_workgroup_reduce
}
#[must_use]
pub fn needs_df64_fma_workaround(&self) -> bool {
!self.df64_fma_two_prod
}
#[must_use]
pub fn native_count(&self) -> u8 {
if !self.basic_f64 {
return 0;
}
[
self.exp,
self.log,
self.exp2,
self.log2,
self.sin,
self.cos,
self.sqrt,
self.fma,
self.abs_min_max,
self.composite_transcendental,
self.exp_log_chain,
self.shared_mem_f64,
self.df64_arith,
self.df64_transcendentals_safe,
self.df64_fma_two_prod,
self.df64_workgroup_reduce,
]
.iter()
.filter(|&&b| b)
.count() as u8
}
}
impl std::fmt::Display for F64BuiltinCapabilities {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let sym = |b: bool| if b { "✓" } else { "✗" };
writeln!(f, " f64 builtin capabilities:")?;
writeln!(f, " basic_f64={}", sym(self.basic_f64))?;
writeln!(
f,
" exp={} log={} exp2={} log2={}",
sym(self.exp),
sym(self.log),
sym(self.exp2),
sym(self.log2)
)?;
writeln!(
f,
" sin={} cos={} sqrt={} fma={}",
sym(self.sin),
sym(self.cos),
sym(self.sqrt),
sym(self.fma)
)?;
writeln!(f, " abs/min/max={}", sym(self.abs_min_max))?;
writeln!(
f,
" composite_transcendental={} exp_log_chain={}",
sym(self.composite_transcendental),
sym(self.exp_log_chain)
)?;
writeln!(f, " shared_mem_f64={}", sym(self.shared_mem_f64))?;
writeln!(
f,
" df64_arith={} df64_transcendentals={}",
sym(self.df64_arith),
sym(self.df64_transcendentals_safe)
)?;
write!(
f,
" df64_fma_two_prod={} df64_workgroup_reduce={}",
sym(self.df64_fma_two_prod),
sym(self.df64_workgroup_reduce)
)
}
}