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