1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <math.h>
18
19 #include "fpmath.h"
20
fabs(double x)21 double fabs(double x) { return __builtin_fabs(x); }
fabsf(float x)22 float fabsf(float x) { return __builtin_fabsf(x); }
fabsl(long double x)23 long double fabsl(long double x) { return __builtin_fabsl(x); }
24
25 #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
ceilf(float x)26 float ceilf(float x) { return __builtin_ceilf(x); }
ceil(double x)27 double ceil(double x) { return __builtin_ceil(x); }
28 #if defined(__ILP32__)
29 __weak_reference(ceil, ceill);
30 #endif
31 #endif
32
copysign(double x,double y)33 double copysign(double x, double y) { return __builtin_copysign(x, y); }
copysignf(float x,float y)34 float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
copysignl(long double x,long double y)35 long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); }
36
37 #if defined(__arm__) && (__ARM_ARCH < 8)
38 // armv8 arm32 has a single-instruction implementation for these, but
39 // armv7 arm32 doesn't, so __builtin_ doesn't work for arm32.
40 #include "math_private.h"
41 namespace s_floor {
42 #include "upstream-freebsd/lib/msun/src/s_floor.c"
43 }
44 namespace s_floorf {
45 #include "upstream-freebsd/lib/msun/src/s_floorf.c"
46 }
floorf(float x)47 float floorf(float x) { return s_floorf::floorf(x); }
floor(double x)48 double floor(double x) { return s_floor::floor(x); }
49 #else
floorf(float x)50 float floorf(float x) { return __builtin_floorf(x); }
floor(double x)51 double floor(double x) { return __builtin_floor(x); }
52 #if defined(__ILP32__)
53 __weak_reference(floor, floorl);
54 #endif
55 #endif
56
57 #if defined(__aarch64__) || defined(__riscv)
fmaf(float x,float y,float z)58 float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
fma(double x,double y,double z)59 double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
60
fmaxf(float x,float y)61 float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
fmax(double x,double y)62 double fmax(double x, double y) { return __builtin_fmax(x, y); }
63
fminf(float x,float y)64 float fminf(float x, float y) { return __builtin_fminf(x, y); }
fmin(double x,double y)65 double fmin(double x, double y) { return __builtin_fmin(x, y); }
66 #endif
67
68 #if defined(__aarch64__) || defined(__riscv)
lrint(double x)69 long lrint(double x) { return __builtin_lrint(x); }
lrintf(float x)70 long lrintf(float x) { return __builtin_lrintf(x); }
llrint(double x)71 long long llrint(double x) { return __builtin_llrint(x); }
llrintf(float x)72 long long llrintf(float x) { return __builtin_llrintf(x); }
73 #endif
74
75 #if defined(__aarch64__) || defined(__riscv)
lround(double x)76 long lround(double x) { return __builtin_lround(x); }
lroundf(float x)77 long lroundf(float x) { return __builtin_lroundf(x); }
llround(double x)78 long long llround(double x) { return __builtin_llround(x); }
llroundf(float x)79 long long llroundf(float x) { return __builtin_llroundf(x); }
80 #endif
81
82 #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
rintf(float x)83 float rintf(float x) { return __builtin_rintf(x); }
rint(double x)84 double rint(double x) { return __builtin_rint(x); }
85 #if defined(__ILP32__)
86 __weak_reference(rint, rintl);
87 #endif
88 #endif
89
90 #if defined(__aarch64__) || defined(__riscv)
roundf(float x)91 float roundf(float x) { return __builtin_roundf(x); }
round(double x)92 double round(double x) { return __builtin_round(x); }
93 #endif
94
sqrtf(float x)95 float sqrtf(float x) { return __builtin_sqrtf(x); }
sqrt(double x)96 double sqrt(double x) { return __builtin_sqrt(x); }
97 #if defined(__ILP32__)
98 __weak_reference(sqrt, sqrtl);
99 #endif
100
101 #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
truncf(float x)102 float truncf(float x) { return __builtin_truncf(x); }
trunc(double x)103 double trunc(double x) { return __builtin_trunc(x); }
104 #if defined(__ILP32__)
105 __weak_reference(trunc, truncl);
106 #endif
107 #endif
108