[libc-commits] [libc] d4baf3b - [libc] Use get_round() instead of floating point tricks in generic hypot implementation.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Thu Jan 20 11:55:15 PST 2022


Author: Tue Ly
Date: 2022-01-20T14:54:57-05:00
New Revision: d4baf3b1322b84816aa623d8e8cb45a49cb68b84

URL: https://github.com/llvm/llvm-project/commit/d4baf3b1322b84816aa623d8e8cb45a49cb68b84
DIFF: https://github.com/llvm/llvm-project/commit/d4baf3b1322b84816aa623d8e8cb45a49cb68b84.diff

LOG: [libc] Use get_round() instead of floating point tricks in generic hypot implementation.

The floating point tricks used to get rounding mode require -frounding-math flag, which behaves differently on aarch64.  Reverting back to use get_round instead.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117824

Added: 
    

Modified: 
    libc/src/__support/FPUtil/Hypot.h
    libc/src/math/generic/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index 4b2987138d1bd..15b26798ccb54 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -144,9 +144,7 @@ static inline T hypot(T x, T y) {
   if ((x_bits.get_unbiased_exponent() >=
        y_bits.get_unbiased_exponent() + MantissaWidth<T>::VALUE + 2) ||
       (y == 0)) {
-    // Check if the rounding mode is FE_UPWARD, will need -frounding-math so
-    // that the compiler does not optimize it away.
-    if ((y != 0) && (0x1p0f + 0x1p-24f != 0x1p0f)) {
+    if ((y != 0) && (get_round() == FE_UPWARD)) {
       UIntType out_bits = FPBits_t(abs(x)).uintval();
       return T(FPBits_t(++out_bits));
     }
@@ -154,9 +152,7 @@ static inline T hypot(T x, T y) {
   } else if ((y_bits.get_unbiased_exponent() >=
               x_bits.get_unbiased_exponent() + MantissaWidth<T>::VALUE + 2) ||
              (x == 0)) {
-    // Check if the rounding mode is FE_UPWARD, will need -frounding-math so
-    // that the compiler does not optimize it away.
-    if ((x != 0) && (0x1p0f + 0x1p-24f != 0x1p0f)) {
+    if ((x != 0) && (get_round() == FE_UPWARD)) {
       UIntType out_bits = FPBits_t(abs(y)).uintval();
       return T(FPBits_t(++out_bits));
     }

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 59bca76fc5f84..c3914b8c45af3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -955,8 +955,6 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.fputil
   COMPILE_OPTIONS
     -O3
-    -frounding-math
-    -Wno-c++17-extensions
 )
 
 add_entrypoint_object(
@@ -1005,8 +1003,6 @@ add_entrypoint_object(
     libc.src.__support.FPUtil.fputil
   COMPILE_OPTIONS
     -O3
-    -frounding-math
-    -Wno-c++17-extensions
 )
 
 add_entrypoint_object(


        


More information about the libc-commits mailing list