blob: 96c006d7e63f63b5a08ca801a80703177d356f9d [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 Hughes591a2a72022-12-05 20:58:15 +000021double fabs(double x) { return __builtin_fabs(x); }
22float fabsf(float x) { return __builtin_fabsf(x); }
Elliott Hughesf9f4a432015-08-24 22:57:08 +000023long double fabsl(long double x) { return __builtin_fabsl(x); }
Elliott Hughes9a1bb702017-11-09 22:40:11 +000024
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000025#if defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
Jake Weinstein1e108e32017-12-11 02:50:04 -050026float ceilf(float x) { return __builtin_ceilf(x); }
27double ceil(double x) { return __builtin_ceil(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000028#if defined(__ILP32__)
29__weak_reference(ceil, ceill);
30#endif
Elliott Hughesedf386b2022-12-09 20:54:38 +000031#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050032
Elliott Hughes46f24a12022-10-26 21:55:34 +000033double copysign(double x, double y) { return __builtin_copysign(x, y); }
34float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
Elliott Hughes0d2c71d2023-02-08 01:26:43 +000035long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); }
Elliott Hughes46f24a12022-10-26 21:55:34 +000036
Elliott Hughes37d72a32023-02-08 20:34:19 +000037#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"
41namespace s_floor {
42#include "upstream-freebsd/lib/msun/src/s_floor.c"
43}
44namespace s_floorf {
45#include "upstream-freebsd/lib/msun/src/s_floorf.c"
46}
47float floorf(float x) { return s_floorf::floorf(x); }
48double floor(double x) { return s_floor::floor(x); }
49#elif defined(__arm__) || defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
Jake Weinstein1e108e32017-12-11 02:50:04 -050050float floorf(float x) { return __builtin_floorf(x); }
51double floor(double x) { return __builtin_floor(x); }
Elliott Hughes47aa5b92023-02-02 02:22:06 +000052#if defined(__ILP32__)
53__weak_reference(floor, floorl);
54#endif
Elliott Hughesedf386b2022-12-09 20:54:38 +000055#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050056
Elliott Hughesedf386b2022-12-09 20:54:38 +000057#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes9a1bb702017-11-09 22:40:11 +000058float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
59double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
60
61float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
62double fmax(double x, double y) { return __builtin_fmax(x, y); }
63
64float fminf(float x, float y) { return __builtin_fminf(x, y); }
65double fmin(double x, double y) { return __builtin_fmin(x, y); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000066#endif
Elliott Hughes9a1bb702017-11-09 22:40:11 +000067
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000068#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000069long lrint(double x) { return __builtin_lrint(x); }
70long lrintf(float x) { return __builtin_lrintf(x); }
71long long llrint(double x) { return __builtin_llrint(x); }
72long long llrintf(float x) { return __builtin_llrintf(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000073#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000074
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000075#if defined(__aarch64__) || defined(__riscv)
Elliott Hughes0cbb9022022-10-28 00:00:00 +000076long lround(double x) { return __builtin_lround(x); }
77long lroundf(float x) { return __builtin_lroundf(x); }
78long long llround(double x) { return __builtin_llround(x); }
79long long llroundf(float x) { return __builtin_llroundf(x); }
Elliott Hughesedf386b2022-12-09 20:54:38 +000080#endif
Elliott Hughes0cbb9022022-10-28 00:00:00 +000081
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000082#if defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
Jake Weinstein1e108e32017-12-11 02:50:04 -050083float rintf(float x) { return __builtin_rintf(x); }
84double rint(double x) { return __builtin_rint(x); }
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000085#if defined(__ILP32__)
86__weak_reference(rint, rintl);
87#endif
88#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050089
Elliott Hughes2f1a7b92023-02-06 21:54:54 +000090#if defined(__aarch64__)
Elliott Hughes9a1bb702017-11-09 22:40:11 +000091float roundf(float x) { return __builtin_roundf(x); }
92double round(double x) { return __builtin_round(x); }
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000093#endif
Jake Weinstein1e108e32017-12-11 02:50:04 -050094
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +000095float sqrtf(float x) { return __builtin_sqrtf(x); }
96double sqrt(double x) { return __builtin_sqrt(x); }
Elliott Hughes47aa5b92023-02-02 02:22:06 +000097#if defined(__ILP32__)
98__weak_reference(sqrt, sqrtl);
99#endif
Elliott Hughes2dcc5ce2023-02-01 02:05:24 +0000100
Elliott Hughes2f1a7b92023-02-06 21:54:54 +0000101#if defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
Jake Weinstein1e108e32017-12-11 02:50:04 -0500102float truncf(float x) { return __builtin_truncf(x); }
103double trunc(double x) { return __builtin_trunc(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