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