libm-macros: Allow a way to bulk match f16 and f128 functions
These are never available in musl, so introduce easier ways to skip them rather than needing to exclude f16/f128 functions in three different places.
This commit is contained in:
committed by
Trevor Gross
parent
1dd39e27f0
commit
99202af075
@@ -116,6 +116,9 @@ pub fn base_name_enum(attributes: pm::TokenStream, tokens: pm::TokenStream) -> p
|
||||
/// // a simplified match-like syntax.
|
||||
/// fn_extra: match MACRO_FN_NAME {
|
||||
/// hypot | hypotf => |x| x.hypot(),
|
||||
/// // `ALL_*` magic matchers also work to extract specific types
|
||||
/// ALL_F64 => |x| x,
|
||||
/// // The default pattern gets applied to everything that did not match
|
||||
/// _ => |x| x,
|
||||
/// },
|
||||
/// }
|
||||
@@ -138,6 +141,27 @@ pub fn for_each_function(tokens: pm::TokenStream) -> pm::TokenStream {
|
||||
///
|
||||
/// Returns the list of function names that we should expand for.
|
||||
fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>> {
|
||||
// Replace magic mappers with a list of relevant functions.
|
||||
if let Some(map) = &mut input.fn_extra {
|
||||
for (name, ty) in [
|
||||
("ALL_F16", FloatTy::F16),
|
||||
("ALL_F32", FloatTy::F32),
|
||||
("ALL_F64", FloatTy::F64),
|
||||
("ALL_F128", FloatTy::F128),
|
||||
] {
|
||||
let Some(k) = map.keys().find(|key| *key == name) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let key = k.clone();
|
||||
let val = map.remove(&key).unwrap();
|
||||
|
||||
for op in ALL_OPERATIONS.iter().filter(|op| op.float_ty == ty) {
|
||||
map.insert(Ident::new(op.name, key.span()), val.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collect lists of all functions that are provied as macro inputs in various fields (only,
|
||||
// skip, attributes).
|
||||
let attr_mentions = input
|
||||
@@ -195,6 +219,12 @@ fn validate(input: &mut StructuredInput) -> syn::Result<Vec<&'static MathOpInfo>
|
||||
continue;
|
||||
}
|
||||
|
||||
// Omit f16 and f128 functions if requested
|
||||
if input.skip_f16_f128 && (func.float_ty == FloatTy::F16 || func.float_ty == FloatTy::F128)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Run everything else
|
||||
fn_list.push(func);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user