| 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 | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 25 | #if defined(__aarch64__) || defined(__riscv) || 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 | 37d72a3 | 2023-02-08 20:34:19 +0000 | [diff] [blame] | 37 | #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" | 
|  | 41 | namespace s_floor { | 
|  | 42 | #include "upstream-freebsd/lib/msun/src/s_floor.c" | 
|  | 43 | } | 
|  | 44 | namespace s_floorf { | 
|  | 45 | #include "upstream-freebsd/lib/msun/src/s_floorf.c" | 
|  | 46 | } | 
|  | 47 | float floorf(float x) { return s_floorf::floorf(x); } | 
|  | 48 | double floor(double x) { return s_floor::floor(x); } | 
| Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 49 | #else | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 50 | float floorf(float x) { return __builtin_floorf(x); } | 
|  | 51 | double floor(double x) { return __builtin_floor(x); } | 
| Elliott Hughes | 47aa5b9 | 2023-02-02 02:22:06 +0000 | [diff] [blame] | 52 | #if defined(__ILP32__) | 
|  | 53 | __weak_reference(floor, floorl); | 
|  | 54 | #endif | 
| Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 55 | #endif | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 56 |  | 
| Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 57 | #if defined(__aarch64__) || defined(__riscv) | 
| Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 58 | float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); } | 
|  | 59 | double fma(double x, double y, double z) { return __builtin_fma(x, y, z); } | 
|  | 60 |  | 
|  | 61 | float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); } | 
|  | 62 | double fmax(double x, double y) { return __builtin_fmax(x, y); } | 
|  | 63 |  | 
|  | 64 | float fminf(float x, float y) { return __builtin_fminf(x, y); } | 
|  | 65 | double fmin(double x, double y) { return __builtin_fmin(x, y); } | 
| Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 66 | #endif | 
| Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 67 |  | 
| Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 68 | #if defined(__aarch64__) || defined(__riscv) | 
| Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 69 | long lrint(double x) { return __builtin_lrint(x); } | 
|  | 70 | long lrintf(float x) { return __builtin_lrintf(x); } | 
|  | 71 | long long llrint(double x) { return __builtin_llrint(x); } | 
|  | 72 | long long llrintf(float x) { return __builtin_llrintf(x); } | 
| Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 73 | #endif | 
| Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 74 |  | 
| Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 75 | #if defined(__aarch64__) || defined(__riscv) | 
| Elliott Hughes | 0cbb902 | 2022-10-28 00:00:00 +0000 | [diff] [blame] | 76 | long lround(double x) { return __builtin_lround(x); } | 
|  | 77 | long lroundf(float x) { return __builtin_lroundf(x); } | 
|  | 78 | long long llround(double x) { return __builtin_llround(x); } | 
|  | 79 | long long llroundf(float x) { return __builtin_llroundf(x); } | 
| Elliott Hughes | edf386b | 2022-12-09 20:54:38 +0000 | [diff] [blame] | 80 | #endif | 
| Elliott Hughes | 0cbb902 | 2022-10-28 00:00:00 +0000 | [diff] [blame] | 81 |  | 
| Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 82 | #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__) | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 83 | float rintf(float x) { return __builtin_rintf(x); } | 
|  | 84 | double rint(double x) { return __builtin_rint(x); } | 
| Elliott Hughes | 2f1a7b9 | 2023-02-06 21:54:54 +0000 | [diff] [blame] | 85 | #if defined(__ILP32__) | 
|  | 86 | __weak_reference(rint, rintl); | 
|  | 87 | #endif | 
|  | 88 | #endif | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 89 |  | 
| Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 90 | #if defined(__aarch64__) || defined(__riscv) | 
| Elliott Hughes | 9a1bb70 | 2017-11-09 22:40:11 +0000 | [diff] [blame] | 91 | float roundf(float x) { return __builtin_roundf(x); } | 
|  | 92 | double round(double x) { return __builtin_round(x); } | 
| Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 93 | #endif | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 94 |  | 
| Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 95 | float sqrtf(float x) { return __builtin_sqrtf(x); } | 
|  | 96 | double sqrt(double x) { return __builtin_sqrt(x); } | 
| Elliott Hughes | 47aa5b9 | 2023-02-02 02:22:06 +0000 | [diff] [blame] | 97 | #if defined(__ILP32__) | 
|  | 98 | __weak_reference(sqrt, sqrtl); | 
|  | 99 | #endif | 
| Elliott Hughes | 2dcc5ce | 2023-02-01 02:05:24 +0000 | [diff] [blame] | 100 |  | 
| Elliott Hughes | 2289ca2 | 2023-03-22 14:11:35 -0700 | [diff] [blame] | 101 | #if defined(__aarch64__) || defined(__riscv) || defined(__i386__) || defined(__x86_64__) | 
| Jake Weinstein | 1e108e3 | 2017-12-11 02:50:04 -0500 | [diff] [blame] | 102 | float truncf(float x) { return __builtin_truncf(x); } | 
|  | 103 | double trunc(double x) { return __builtin_trunc(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 |