blob: a638aa3433def7da9b007ec914289bbb0508b4ef [file] [log] [blame]
Elliott Hughesf9f4a432015-08-24 22:57:08 +00001/*
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
Elliott Hughes15b18552024-07-21 23:30:47 +000021#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
Jake Weinstein1e108e32017-12-11 02:50:04 -050025double ceil(double x) { return __builtin_ceil(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000026float ceilf(float x) { return __builtin_ceilf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000027#if defined(__ILP32__)
28__weak_reference(ceil, ceill);
29#endif
Elliott Hughesedf386b2022-12-09 20:54:38 +000030#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050031
Elliott Hughes46f24a12022-10-26 21:55:34 +000032double copysign(double x, double y) { return __builtin_copysign(x, y); }
33float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
Elliott Hughes0d2c71d2023-02-08 01:26:43 +000034long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); }
Elliott Hughes46f24a12022-10-26 21:55:34 +000035
Elliott Hughes15b18552024-07-21 23:30:47 +000036double fabs(double x) { return __builtin_fabs(x); }
37float fabsf(float x) { return __builtin_fabsf(x); }
38long 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.
Elliott Hughes2289ca22023-03-22 14:11:35 -070043#else
Jake Weinstein1e108e32017-12-11 02:50:04 -050044double floor(double x) { return __builtin_floor(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000045float floorf(float x) { return __builtin_floorf(x); }
Elliott Hughes47aa5b92023-02-02 02:22:06 +000046#if defined(__ILP32__)
47__weak_reference(floor, floorl);
48#endif
Elliott Hughesedf386b2022-12-09 20:54:38 +000049#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050050
Elliott Hughes1ebde4c2025-05-12 08:59:58 -040051#if (defined(__arm__) && (__ARM_ARCH >= 8)) || defined(__aarch64__) || defined(__riscv)
Elliott Hughes9a1bb702017-11-09 22:40:11 +000052float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
53double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
Elliott Hughes1ebde4c2025-05-12 08:59:58 -040054#if defined(__ILP32__)
55__weak_reference(fma, fmal);
56#endif
Elliott Hughes42209322025-05-09 16:34:43 -040057#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +000058
Elliott Hughes1ebde4c2025-05-12 08:59:58 -040059#if (defined(__arm__) && (__ARM_ARCH <= 7))
60// armv7 arm32 has no instructions to implement these builtins,
61// so we include the msun source in the .bp file instead.
62#else
Elliott Hughes9a1bb702017-11-09 22:40:11 +000063float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
64double fmax(double x, double y) { return __builtin_fmax(x, y); }
Elliott Hughes9a1bb702017-11-09 22:40:11 +000065float fminf(float x, float y) { return __builtin_fminf(x, y); }
66double fmin(double x, double y) { return __builtin_fmin(x, y); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000067#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +000068
Elliott Hughesd02f9792024-07-23 17:09:26 +000069#if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000070long lrint(double x) { return __builtin_lrint(x); }
71long lrintf(float x) { return __builtin_lrintf(x); }
72long long llrint(double x) { return __builtin_llrint(x); }
73long long llrintf(float x) { return __builtin_llrintf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000074#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000075
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000076#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes0cbb9022022-10-28 00:00:00 +000077long lround(double x) { return __builtin_lround(x); }
78long lroundf(float x) { return __builtin_lroundf(x); }
79long long llround(double x) { return __builtin_llround(x); }
80long long llroundf(float x) { return __builtin_llroundf(x); }
Elliott Hughesedf386b2022-12-09 20:54:38 +000081#endif
Elliott Hughes0cbb9022022-10-28 00:00:00 +000082
Elliott Hughes15b18552024-07-21 23:30:47 +000083#if defined(__arm__) && (__ARM_ARCH <= 7)
84// armv7 arm32 has no instructions to implement these builtins,
85// so we include the msun source in the .bp file instead.
86#else
Jake Weinstein1e108e32017-12-11 02:50:04 -050087double rint(double x) { return __builtin_rint(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000088float rintf(float x) { return __builtin_rintf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000089#if defined(__ILP32__)
90__weak_reference(rint, rintl);
91#endif
92#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050093
Elliott Hughes1ebde4c2025-05-12 08:59:58 -040094#if (defined(__arm__) && (__ARM_ARCH >= 8)) || defined(__aarch64__) || defined(__riscv)
Elliott Hughes9a1bb702017-11-09 22:40:11 +000095double round(double x) { return __builtin_round(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000096float roundf(float x) { return __builtin_roundf(x); }
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000097#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050098
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000099double sqrt(double x) { return __builtin_sqrt(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +0000100float sqrtf(float x) { return __builtin_sqrtf(x); }
Elliott Hughes47aa5b92023-02-02 02:22:06 +0000101#if defined(__ILP32__)
102__weak_reference(sqrt, sqrtl);
103#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +0000104
Elliott Hughes15b18552024-07-21 23:30:47 +0000105#if defined(__arm__) && (__ARM_ARCH <= 7)
106// armv7 arm32 has no instructions to implement these builtins,
107// so we include the msun source in the .bp file instead.
108#else
Jake Weinstein1e108e32017-12-11 02:50:04 -0500109double trunc(double x) { return __builtin_trunc(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +0000110float truncf(float x) { return __builtin_truncf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +0000111#if defined(__ILP32__)
112__weak_reference(trunc, truncl);
113#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +0000114#endif