|
1 |
| -/// Choose among using an intrinsic (if available) and falling back to the default function body. |
2 |
| -/// Returns directly if the intrinsic version is used, otherwise continues to the rest of the |
3 |
| -/// function. |
| 1 | +/// `libm` cannot have dependencies, so this is vendored directly from the `cfg-if` crate |
| 2 | +/// (with some comments stripped for compactness). |
| 3 | +macro_rules! cfg_if { |
| 4 | + // match if/else chains with a final `else` |
| 5 | + ($( |
| 6 | + if #[cfg($meta:meta)] { $($tokens:tt)* } |
| 7 | + ) else * else { |
| 8 | + $($tokens2:tt)* |
| 9 | + }) => { |
| 10 | + cfg_if! { @__items () ; $( ( ($meta) ($($tokens)*) ), )* ( () ($($tokens2)*) ), } |
| 11 | + }; |
| 12 | + |
| 13 | + // match if/else chains lacking a final `else` |
| 14 | + ( |
| 15 | + if #[cfg($i_met:meta)] { $($i_tokens:tt)* } |
| 16 | + $( else if #[cfg($e_met:meta)] { $($e_tokens:tt)* } )* |
| 17 | + ) => { |
| 18 | + cfg_if! { |
| 19 | + @__items |
| 20 | + () ; |
| 21 | + ( ($i_met) ($($i_tokens)*) ), |
| 22 | + $( ( ($e_met) ($($e_tokens)*) ), )* |
| 23 | + ( () () ), |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + // Internal and recursive macro to emit all the items |
| 28 | + // |
| 29 | + // Collects all the negated cfgs in a list at the beginning and after the |
| 30 | + // semicolon is all the remaining items |
| 31 | + (@__items ($($not:meta,)*) ; ) => {}; |
| 32 | + (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($tokens:tt)*) ), $($rest:tt)*) => { |
| 33 | + #[cfg(all($($m,)* not(any($($not),*))))] cfg_if! { @__identity $($tokens)* } |
| 34 | + cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* } |
| 35 | + }; |
| 36 | + |
| 37 | + // Internal macro to make __apply work out right for different match types, |
| 38 | + // because of how macros matching/expand stuff. |
| 39 | + (@__identity $($tokens:tt)*) => { $($tokens)* }; |
| 40 | +} |
| 41 | + |
| 42 | +/// Choose between using an intrinsic (if available) and the function body. Returns directly if |
| 43 | +/// the intrinsic is used, otherwise the rest of the function body is used. |
4 | 44 | ///
|
5 | 45 | /// Use this if the intrinsic is likely to be more performant on the platform(s) specified
|
6 | 46 | /// in `intrinsic_available`.
|
|
0 commit comments