about summary refs log tree commit diff
path: root/library/compiler-builtins/libm/src/math/arch/mod.rs
blob: 984ae7f3129f9375789e8e3aacdc3026a4bab55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! Architecture-specific routines and operations.
//!
//! LLVM will already optimize calls to some of these in cases that there are hardware
//! instructions. Providing an implementation here just ensures that the faster implementation
//! is used when calling the function directly. This helps anyone who uses `libm` directly, as
//! well as improving things when these routines are called as part of other implementations.

// Most implementations should be defined here, to ensure they are not made available when
// soft floats are required.
#[cfg(arch_enabled)]
cfg_if! {
    if #[cfg(all(target_arch = "wasm32", intrinsics_enabled))] {
        mod wasm32;
        pub use wasm32::{
            ceil, ceilf, fabs, fabsf, floor, floorf, rint, rintf, sqrt, sqrtf, trunc, truncf,
        };
    } else if #[cfg(target_feature = "sse2")] {
        mod x86;
        pub use x86::{sqrt, sqrtf, fma, fmaf};
    } else if #[cfg(all(
        any(target_arch = "aarch64", target_arch = "arm64ec"),
        target_feature = "neon"
    ))] {
        mod aarch64;

        pub use aarch64::{
            fma,
            fmaf,
            rint,
            rintf,
            sqrt,
            sqrtf,
        };

        #[cfg(all(f16_enabled, target_feature = "fp16"))]
        pub use aarch64::{
            rintf16,
            sqrtf16,
        };
    }
}

// There are certain architecture-specific implementations that are needed for correctness
// even with `force-soft-float`. These are configured here.
cfg_if! {
    if #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))] {
        mod i586;
        pub use i586::{ceil, floor};
    }
}