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