1 | //! Architecture-specific routines and operations. |
2 | //! |
3 | //! LLVM will already optimize calls to some of these in cases that there are hardware |
4 | //! instructions. Providing an implementation here just ensures that the faster implementation |
5 | //! is used when calling the function directly. This helps anyone who uses `libm` directly, as |
6 | //! well as improving things when these routines are called as part of other implementations. |
7 | |
8 | // Most implementations should be defined here, to ensure they are not made available when |
9 | // soft floats are required. |
10 | #[cfg (arch_enabled)] |
11 | cfg_if! { |
12 | if #[cfg(all(target_arch = "wasm32" , intrinsics_enabled))] { |
13 | mod wasm32; |
14 | pub use wasm32::{ |
15 | ceil, ceilf, fabs, fabsf, floor, floorf, rint, rintf, sqrt, sqrtf, trunc, truncf, |
16 | }; |
17 | } else if #[cfg(target_feature = "sse2" )] { |
18 | mod x86; |
19 | pub use x86::{sqrt, sqrtf, fma, fmaf}; |
20 | } else if #[cfg(all( |
21 | any(target_arch = "aarch64" , target_arch = "arm64ec" ), |
22 | target_feature = "neon" |
23 | ))] { |
24 | mod aarch64; |
25 | |
26 | pub use aarch64::{ |
27 | fma, |
28 | fmaf, |
29 | rint, |
30 | rintf, |
31 | sqrt, |
32 | sqrtf, |
33 | }; |
34 | |
35 | #[cfg(all(f16_enabled, target_feature = "fp16" ))] |
36 | pub use aarch64::{ |
37 | rintf16, |
38 | sqrtf16, |
39 | }; |
40 | } |
41 | } |
42 | |
43 | // There are certain architecture-specific implementations that are needed for correctness |
44 | // even with `force-soft-float`. These are configured here. |
45 | cfg_if! { |
46 | if #[cfg(all(target_arch = "x86" , not(target_feature = "sse2" )))] { |
47 | mod i586; |
48 | pub use i586::{ceil, floor}; |
49 | } |
50 | } |
51 | |