xref: /aosp_15_r20/bionic/libm/builtins.cpp (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
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 
21 #if defined(__arm__) && (__ARM_ARCH <= 7)
22 // armv7 arm32 has no instructions to implement these builtins,
23 // so we include the msun source in the .bp file instead.
24 #else
ceil(double x)25 double ceil(double x) { return __builtin_ceil(x); }
ceilf(float x)26 float ceilf(float x) { return __builtin_ceilf(x); }
27 #if defined(__ILP32__)
28 __weak_reference(ceil, ceill);
29 #endif
30 #endif
31 
copysign(double x,double y)32 double copysign(double x, double y) { return __builtin_copysign(x, y); }
copysignf(float x,float y)33 float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
copysignl(long double x,long double y)34 long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); }
35 
fabs(double x)36 double fabs(double x) { return __builtin_fabs(x); }
fabsf(float x)37 float fabsf(float x) { return __builtin_fabsf(x); }
fabsl(long double x)38 long double fabsl(long double x) { return __builtin_fabsl(x); }
39 
40 #if defined(__arm__) && (__ARM_ARCH <= 7)
41 // armv7 arm32 has no instructions to implement these builtins,
42 // so we include the msun source in the .bp file instead.
43 #else
floor(double x)44 double floor(double x) { return __builtin_floor(x); }
floorf(float x)45 float floorf(float x) { return __builtin_floorf(x); }
46 #if defined(__ILP32__)
47 __weak_reference(floor, floorl);
48 #endif
49 #endif
50 
51 #if defined(__aarch64__) || defined(__riscv)
fmaf(float x,float y,float z)52 float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
fma(double x,double y,double z)53 double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
54 
fmaxf(float x,float y)55 float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
fmax(double x,double y)56 double fmax(double x, double y) { return __builtin_fmax(x, y); }
57 
fminf(float x,float y)58 float fminf(float x, float y) { return __builtin_fminf(x, y); }
fmin(double x,double y)59 double fmin(double x, double y) { return __builtin_fmin(x, y); }
60 #endif
61 
62 #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
lrint(double x)63 long lrint(double x) { return __builtin_lrint(x); }
lrintf(float x)64 long lrintf(float x) { return __builtin_lrintf(x); }
llrint(double x)65 long long llrint(double x) { return __builtin_llrint(x); }
llrintf(float x)66 long long llrintf(float x) { return __builtin_llrintf(x); }
67 #endif
68 
69 #if defined(__aarch64__) || defined(__riscv)
lround(double x)70 long lround(double x) { return __builtin_lround(x); }
lroundf(float x)71 long lroundf(float x) { return __builtin_lroundf(x); }
llround(double x)72 long long llround(double x) { return __builtin_llround(x); }
llroundf(float x)73 long long llroundf(float x) { return __builtin_llroundf(x); }
74 #endif
75 
76 #if defined(__arm__) && (__ARM_ARCH <= 7)
77 // armv7 arm32 has no instructions to implement these builtins,
78 // so we include the msun source in the .bp file instead.
79 #else
rint(double x)80 double rint(double x) { return __builtin_rint(x); }
rintf(float x)81 float rintf(float x) { return __builtin_rintf(x); }
82 #if defined(__ILP32__)
83 __weak_reference(rint, rintl);
84 #endif
85 #endif
86 
87 #if defined(__aarch64__) || defined(__riscv)
round(double x)88 double round(double x) { return __builtin_round(x); }
roundf(float x)89 float roundf(float x) { return __builtin_roundf(x); }
90 #endif
91 
sqrt(double x)92 double sqrt(double x) { return __builtin_sqrt(x); }
sqrtf(float x)93 float sqrtf(float x) { return __builtin_sqrtf(x); }
94 #if defined(__ILP32__)
95 __weak_reference(sqrt, sqrtl);
96 #endif
97 
98 #if defined(__arm__) && (__ARM_ARCH <= 7)
99 // armv7 arm32 has no instructions to implement these builtins,
100 // so we include the msun source in the .bp file instead.
101 #else
trunc(double x)102 double trunc(double x) { return __builtin_trunc(x); }
truncf(float x)103 float truncf(float x) { return __builtin_truncf(x); }
104 #if defined(__ILP32__)
105 __weak_reference(trunc, truncl);
106 #endif
107 #endif
108