[libcxx-commits] [PATCH] D116338: Set std::numeric_limits<>::tinyness_before to true for floating point types on ARM platforms.

Owen Anderson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 28 20:06:35 PST 2021


resistor updated this revision to Diff 396460.
resistor added a comment.

Update tests to account for the change in behavior, and add a
specific test that checks the value of tinyness_before against
the actual platform behavior.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116338/new/

https://reviews.llvm.org/D116338

Files:
  libcxx/include/limits
  libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/tinyness_before.pass.cpp


Index: libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/tinyness_before.pass.cpp
===================================================================
--- libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/tinyness_before.pass.cpp
+++ libcxx/test/std/language.support/support.limits/limits/numeric.limits.members/tinyness_before.pass.cpp
@@ -11,6 +11,9 @@
 // tinyness_before
 
 #include <limits>
+#include <cassert>
+#include <cfenv>
+#include <cmath>
 
 #include "test_macros.h"
 
@@ -22,6 +25,19 @@
     static_assert(std::numeric_limits<const T>::tinyness_before == expected, "tinyness_before test 2");
     static_assert(std::numeric_limits<volatile T>::tinyness_before == expected, "tinyness_before test 3");
     static_assert(std::numeric_limits<const volatile T>::tinyness_before == expected, "tinyness_before test 4");
+
+    if (std::is_floating_point<T>::value) {
+        T denorm_max = std::nextafter(std::numeric_limits<double>::min(), 0);
+        T multiplier = 1 + std::numeric_limits<T>::epsilon();
+    
+        std::feclearexcept(FE_ALL_EXCEPT);
+    
+        T result = denorm_max * multiplier;
+        (void)result;
+        
+        // Underflow will occur only if tinyness is evaluated before rounding.
+        assert(std::fetestexcept(FE_UNDERFLOW) == std::numeric_limits<T>::tinyness_before);
+    }
 }
 
 int main(int, char**)
@@ -50,9 +66,15 @@
     test<__int128_t, false>();
     test<__uint128_t, false>();
 #endif
+#ifdef __arm__
+    test<float, true>();
+    test<double, true>();
+    test<long double, true>();
+#else
     test<float, false>();
     test<double, false>();
     test<long double, false>();
+#endif
 
   return 0;
 }
Index: libcxx/include/limits
===================================================================
--- libcxx/include/limits
+++ libcxx/include/limits
@@ -339,7 +339,11 @@
     static _LIBCPP_CONSTEXPR const bool is_modulo = false;
 
     static _LIBCPP_CONSTEXPR const bool traps = false;
+#ifdef __arm__
+    static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
+#else
     static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
+#endif
     static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
 };
 
@@ -385,7 +389,11 @@
     static _LIBCPP_CONSTEXPR const bool is_modulo = false;
 
     static _LIBCPP_CONSTEXPR const bool traps = false;
+#ifdef __arm__
+    static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
+#else
     static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
+#endif
     static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
 };
 
@@ -435,7 +443,11 @@
     static _LIBCPP_CONSTEXPR const bool is_modulo = false;
 
     static _LIBCPP_CONSTEXPR const bool traps = false;
+#ifdef __arm__
+    static _LIBCPP_CONSTEXPR const bool tinyness_before = true;
+#else
     static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
+#endif
     static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116338.396460.patch
Type: text/x-patch
Size: 3056 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211229/87970440/attachment-0001.bin>


More information about the libcxx-commits mailing list