summaryrefslogtreecommitdiffstats
path: root/vendor/compiler_builtins/src/math.rs
blob: 498e4d85ff09eead3f36999a6f8865fbbcbcb2eb (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#[allow(dead_code)]
#[path = "../libm/src/math/mod.rs"]
mod libm;

macro_rules! no_mangle {
    ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => {
        intrinsics! {
            $(
                pub extern "C" fn $fun($($iid: $ity),+) -> $oty {
                    self::libm::$fun($($iid),+)
                }
            )+
        }
    }
}

#[cfg(any(
    all(
        target_family = "wasm",
        target_os = "unknown",
        not(target_env = "wasi")
    ),
    target_os = "xous",
    all(target_arch = "x86_64", target_os = "uefi"),
    all(target_arch = "xtensa", target_os = "none"),
    all(target_vendor = "fortanix", target_env = "sgx")
))]
no_mangle! {
    fn acos(x: f64) -> f64;
    fn asin(x: f64) -> f64;
    fn cbrt(x: f64) -> f64;
    fn expm1(x: f64) -> f64;
    fn hypot(x: f64, y: f64) -> f64;
    fn tan(x: f64) -> f64;
    fn cos(x: f64) -> f64;
    fn expf(x: f32) -> f32;
    fn log2(x: f64) -> f64;
    fn log2f(x: f32) -> f32;
    fn log10(x: f64) -> f64;
    fn log10f(x: f32) -> f32;
    fn log(x: f64) -> f64;
    fn logf(x: f32) -> f32;
    fn fmin(x: f64, y: f64) -> f64;
    fn fminf(x: f32, y: f32) -> f32;
    fn fmax(x: f64, y: f64) -> f64;
    fn fmaxf(x: f32, y: f32) -> f32;
    fn round(x: f64) -> f64;
    fn roundf(x: f32) -> f32;
    fn rint(x: f64) -> f64;
    fn rintf(x: f32) -> f32;
    fn sin(x: f64) -> f64;
    fn pow(x: f64, y: f64) -> f64;
    fn powf(x: f32, y: f32) -> f32;
    fn fmod(x: f64, y: f64) -> f64;
    fn fmodf(x: f32, y: f32) -> f32;
    fn acosf(n: f32) -> f32;
    fn atan2f(a: f32, b: f32) -> f32;
    fn atanf(n: f32) -> f32;
    fn coshf(n: f32) -> f32;
    fn expm1f(n: f32) -> f32;
    fn fdim(a: f64, b: f64) -> f64;
    fn fdimf(a: f32, b: f32) -> f32;
    fn log1pf(n: f32) -> f32;
    fn sinhf(n: f32) -> f32;
    fn tanhf(n: f32) -> f32;
    fn ldexp(f: f64, n: i32) -> f64;
    fn ldexpf(f: f32, n: i32) -> f32;
    fn tgamma(x: f64) -> f64;
    fn tgammaf(x: f32) -> f32;
    fn atan(x: f64) -> f64;
    fn atan2(x: f64, y: f64) -> f64;
    fn cosh(x: f64) -> f64;
    fn log1p(x: f64) -> f64;
    fn sinh(x: f64) -> f64;
    fn tanh(x: f64) -> f64;
    fn cosf(x: f32) -> f32;
    fn exp(x: f64) -> f64;
    fn sinf(x: f32) -> f32;
    fn exp2(x: f64) -> f64;
    fn exp2f(x: f32) -> f32;
    fn fma(x: f64, y: f64, z: f64) -> f64;
    fn fmaf(x: f32, y: f32, z: f32) -> f32;
    fn asinf(n: f32) -> f32;
    fn cbrtf(n: f32) -> f32;
    fn hypotf(x: f32, y: f32) -> f32;
    fn tanf(n: f32) -> f32;
}

#[cfg(any(
    all(
        target_family = "wasm",
        target_os = "unknown",
        not(target_env = "wasi")
    ),
    target_os = "xous",
    all(target_arch = "x86_64", target_os = "uefi"),
    all(target_arch = "xtensa", target_os = "none"),
    all(target_vendor = "fortanix", target_env = "sgx")
))]
intrinsics! {
    pub extern "C" fn lgamma_r(x: f64, s: &mut i32) -> f64 {
        let r = self::libm::lgamma_r(x);
        *s = r.1;
        r.0
    }

    pub extern "C" fn lgammaf_r(x: f32, s: &mut i32) -> f32 {
        let r = self::libm::lgammaf_r(x);
        *s = r.1;
        r.0
    }
}

#[cfg(any(
    target_os = "xous",
    target_os = "uefi",
    all(target_arch = "xtensa", target_os = "none"),
))]
no_mangle! {
    fn sqrtf(x: f32) -> f32;
    fn sqrt(x: f64) -> f64;
}

#[cfg(any(
    all(target_vendor = "fortanix", target_env = "sgx"),
    all(target_arch = "xtensa", target_os = "none"),
    target_os = "xous",
    target_os = "uefi"
))]
no_mangle! {
    fn ceil(x: f64) -> f64;
    fn ceilf(x: f32) -> f32;
    fn floor(x: f64) -> f64;
    fn floorf(x: f32) -> f32;
    fn trunc(x: f64) -> f64;
    fn truncf(x: f32) -> f32;
}

// only for the thumb*-none-eabi*, riscv32*-none-elf and x86_64-unknown-none targets that lack the floating point instruction set
#[cfg(any(
    all(target_arch = "arm", target_os = "none"),
    all(target_arch = "riscv32", not(target_feature = "f"), target_os = "none"),
    all(target_arch = "x86_64", target_os = "none")
))]
no_mangle! {
    fn fmin(x: f64, y: f64) -> f64;
    fn fminf(x: f32, y: f32) -> f32;
    fn fmax(x: f64, y: f64) -> f64;
    fn fmaxf(x: f32, y: f32) -> f32;
    // `f64 % f64`
    fn fmod(x: f64, y: f64) -> f64;
    // `f32 % f32`
    fn fmodf(x: f32, y: f32) -> f32;
}