aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2024-02-13 11:17:28 +0100
committerGitHub <noreply@github.com>2024-02-13 11:17:28 +0100
commitf506192c016fb6909eb2c17e183f6223db012f8c (patch)
tree6b3a9c3cb07152f54422fff6e00ea29a5ed54296
parent8c6e96d9eb35849762fa3ab4d3cc9517c4e14e74 (diff)
downloadllvm-f506192c016fb6909eb2c17e183f6223db012f8c.zip
llvm-f506192c016fb6909eb2c17e183f6223db012f8c.tar.gz
llvm-f506192c016fb6909eb2c17e183f6223db012f8c.tar.bz2
[libc][NFC] Small `abs` related simplifications (#79858)
-rw-r--r--libc/src/__support/FPUtil/BasicOperations.h4
-rw-r--r--libc/src/math/generic/acoshf.cpp6
-rw-r--r--libc/src/math/generic/asinhf.cpp4
3 files changed, 3 insertions, 11 deletions
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index ccc61a8..a19d6d0 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -19,9 +19,7 @@ namespace fputil {
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE T abs(T x) {
- FPBits<T> bits(x);
- bits.set_sign(Sign::POS);
- return bits.get_val();
+ return FPBits<T>(x).abs().get_val();
}
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
diff --git a/libc/src/math/generic/acoshf.cpp b/libc/src/math/generic/acoshf.cpp
index 54b66bf..a4a75a7 100644
--- a/libc/src/math/generic/acoshf.cpp
+++ b/libc/src/math/generic/acoshf.cpp
@@ -33,12 +33,8 @@ LLVM_LIBC_FUNCTION(float, acoshf, (float x)) {
}
if (LIBC_UNLIKELY(x_u >= 0x4f8ffb03)) {
- // Check for exceptional values.
- uint32_t x_abs = xbits.abs().uintval();
- if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
- // x is +inf or NaN.
+ if (LIBC_UNLIKELY(xbits.is_inf_or_nan()))
return x;
- }
// Helper functions to set results for exceptional cases.
auto round_result_slightly_down = [](float r) -> float {
diff --git a/libc/src/math/generic/asinhf.cpp b/libc/src/math/generic/asinhf.cpp
index ac05991..6e35178 100644
--- a/libc/src/math/generic/asinhf.cpp
+++ b/libc/src/math/generic/asinhf.cpp
@@ -59,10 +59,8 @@ LLVM_LIBC_FUNCTION(float, asinhf, (float x)) {
};
if (LIBC_UNLIKELY(x_abs >= 0x4bdd'65a5U)) {
- if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
- // x is +-inf or nan
+ if (LIBC_UNLIKELY(xbits.is_inf_or_nan()))
return x;
- }
// Exceptional cases when x > 2^24.
switch (x_abs) {