Elliott Hughes | f9f4a43 | 2015-08-24 22:57:08 +0000 | [diff] [blame] | 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 | |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 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 |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 25 | double ceil(double x) { return __builtin_ceil(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 26 | float ceilf(float x) { return __builtin_ceilf(x); } |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 27 | #if defined(__ILP32__) |
| 28 | __weak_reference(ceil, ceill); |
| 29 | #endif |
Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 30 | #endif |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 31 | |
Elliott Hughes | 46f24a1 | 2022-10-26 21:55:34 +0000 | [diff] [blame] | 32 | double copysign(double x, double y) { return __builtin_copysign(x, y); } |
| 33 | float copysignf(float x, float y) { return __builtin_copysignf(x, y); } |
Elliott Hughes | 0d2c71d | 2023-02-08 01:26:43 +0000 | [diff] [blame] | 34 | long double copysignl(long double x, long double y) { return __builtin_copysignl(x, y); } |
Elliott Hughes | 46f24a1 | 2022-10-26 21:55:34 +0000 | [diff] [blame] | 35 | |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 36 | double fabs(double x) { return __builtin_fabs(x); } |
| 37 | float fabsf(float x) { return __builtin_fabsf(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. |
Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 43 | #else |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 44 | double floor(double x) { return __builtin_floor(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 45 | float floorf(float x) { return __builtin_floorf(x); } |
Elliott Hughes | 47aa5b9 | 2023-02-02 02:22:06 +0000 | [diff] [blame] | 46 | #if defined(__ILP32__) |
| 47 | __weak_reference(floor, floorl); |
| 48 | #endif |
Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 49 | #endif |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 50 | |
Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 51 | #if defined(__aarch64__) || defined(__riscv) |
Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 52 | float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); } |
| 53 | double fma(double x, double y, double z) { return __builtin_fma(x, y, z); } |
| 54 | |
| 55 | float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); } |
| 56 | double fmax(double x, double y) { return __builtin_fmax(x, y); } |
| 57 | |
| 58 | float fminf(float x, float y) { return __builtin_fminf(x, y); } |
| 59 | double fmin(double x, double y) { return __builtin_fmin(x, y); } |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 60 | #endif |
Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 61 | |
Elliott Hughes | d02f979 | 2024-07-23 17:09:26 +0000 | [diff] [blame^] | 62 | #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__) |
Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 63 | long lrint(double x) { return __builtin_lrint(x); } |
| 64 | long lrintf(float x) { return __builtin_lrintf(x); } |
| 65 | long long llrint(double x) { return __builtin_llrint(x); } |
| 66 | long long llrintf(float x) { return __builtin_llrintf(x); } |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 67 | #endif |
Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 68 | |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 69 | #if defined(__aarch64__) || defined(__riscv) |
Elliott Hughes | 0cbb902 | 2022-10-28 00:00:00 +0000 | [diff] [blame] | 70 | long lround(double x) { return __builtin_lround(x); } |
| 71 | long lroundf(float x) { return __builtin_lroundf(x); } |
| 72 | long long llround(double x) { return __builtin_llround(x); } |
| 73 | long long llroundf(float x) { return __builtin_llroundf(x); } |
Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 74 | #endif |
Elliott Hughes | 0cbb902 | 2022-10-28 00:00:00 +0000 | [diff] [blame] | 75 | |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 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 |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 80 | double rint(double x) { return __builtin_rint(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 81 | float rintf(float x) { return __builtin_rintf(x); } |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 82 | #if defined(__ILP32__) |
| 83 | __weak_reference(rint, rintl); |
| 84 | #endif |
| 85 | #endif |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 86 | |
Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 87 | #if defined(__aarch64__) || defined(__riscv) |
Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 88 | double round(double x) { return __builtin_round(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 89 | float roundf(float x) { return __builtin_roundf(x); } |
Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 90 | #endif |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 91 | |
Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 92 | double sqrt(double x) { return __builtin_sqrt(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 93 | float sqrtf(float x) { return __builtin_sqrtf(x); } |
Elliott Hughes | 47aa5b9 | 2023-02-02 02:22:06 +0000 | [diff] [blame] | 94 | #if defined(__ILP32__) |
| 95 | __weak_reference(sqrt, sqrtl); |
| 96 | #endif |
Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 97 | |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 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 |
Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 102 | double trunc(double x) { return __builtin_trunc(x); } |
Elliott Hughes | 15b1855 | 2024-07-21 23:30:47 +0000 | [diff] [blame] | 103 | float truncf(float x) { return __builtin_truncf(x); } |
Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 104 | #if defined(__ILP32__) |
| 105 | __weak_reference(trunc, truncl); |
| 106 | #endif |
Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 107 | #endif |