blob: 97db425d12705bd6ccbf61700659cec1c8333e9d [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 Hughesedf386b2022-12-09 20:54:38 +000051#if 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); }
54
55float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
56double fmax(double x, double y) { return __builtin_fmax(x, y); }
57
58float fminf(float x, float y) { return __builtin_fminf(x, y); }
59double fmin(double x, double y) { return __builtin_fmin(x, y); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000060#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +000061
Elliott Hughesd02f9792024-07-23 17:09:26 +000062#if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__)
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000063long lrint(double x) { return __builtin_lrint(x); }
64long lrintf(float x) { return __builtin_lrintf(x); }
65long long llrint(double x) { return __builtin_llrint(x); }
66long long llrintf(float x) { return __builtin_llrintf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000067#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000068
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000069#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes0cbb9022022-10-28 00:00:00 +000070long lround(double x) { return __builtin_lround(x); }
71long lroundf(float x) { return __builtin_lroundf(x); }
72long long llround(double x) { return __builtin_llround(x); }
73long long llroundf(float x) { return __builtin_llroundf(x); }
Elliott Hughesedf386b2022-12-09 20:54:38 +000074#endif
Elliott Hughes0cbb9022022-10-28 00:00:00 +000075
Elliott Hughes15b18552024-07-21 23:30:47 +000076#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
Jake Weinstein1e108e32017-12-11 02:50:04 -050080double rint(double x) { return __builtin_rint(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000081float rintf(float x) { return __builtin_rintf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000082#if defined(__ILP32__)
83__weak_reference(rint, rintl);
84#endif
85#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050086
Elliott Hughes2289ca22023-03-22 14:11:35 -070087#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes9a1bb702017-11-09 22:40:11 +000088double round(double x) { return __builtin_round(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000089float roundf(float x) { return __builtin_roundf(x); }
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000090#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050091
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000092double sqrt(double x) { return __builtin_sqrt(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +000093float sqrtf(float x) { return __builtin_sqrtf(x); }
Elliott Hughes47aa5b92023-02-02 02:22:06 +000094#if defined(__ILP32__)
95__weak_reference(sqrt, sqrtl);
96#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000097
Elliott Hughes15b18552024-07-21 23:30:47 +000098#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
Jake Weinstein1e108e32017-12-11 02:50:04 -0500102double trunc(double x) { return __builtin_trunc(x); }
Elliott Hughes15b18552024-07-21 23:30:47 +0000103float truncf(float x) { return __builtin_truncf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +0000104#if defined(__ILP32__)
105__weak_reference(trunc, truncl);
106#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +0000107#endif