[libc-commits] [PATCH] D117812: [libc] Make log2f correctly rounded for all rounding modes when FMA is not available.

Tue Ly via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Jan 20 13:16:27 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG1f3f90ab8869: [libc] Make log2f correctly rounded for all rounding modes when FMA is not… (authored by lntue).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117812

Files:
  libc/src/math/generic/log2f.cpp
  libc/test/src/math/log2f_test.cpp


Index: libc/test/src/math/log2f_test.cpp
===================================================================
--- libc/test/src/math/log2f_test.cpp
+++ libc/test/src/math/log2f_test.cpp
@@ -31,10 +31,10 @@
 }
 
 TEST(LlvmLibcLog2fTest, TrickyInputs) {
-  constexpr int N = 9;
-  constexpr uint32_t INPUTS[N] = {0x3f7d57f5U, 0x3f7ed848U, 0x3f7fd6ccU,
-                                  0x3f7fffffU, 0x3f80079bU, 0x3f81d0b5U,
-                                  0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
+  constexpr int N = 10;
+  constexpr uint32_t INPUTS[N] = {
+      0x3f7d57f5U, 0x3f7e3274U, 0x3f7ed848U, 0x3f7fd6ccU, 0x3f7fffffU,
+      0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
 
   for (int i = 0; i < N; ++i) {
     float x = float(FPBits(INPUTS[i]));
Index: libc/src/math/generic/log2f.cpp
===================================================================
--- libc/src/math/generic/log2f.cpp
+++ libc/src/math/generic/log2f.cpp
@@ -105,11 +105,24 @@
   int m = 0;
 
   // Hard to round value(s).
-  if (FPBits(x).uintval() == 0x3f81d0b5U) {
+  switch (FPBits(x).uintval()) {
+  case 0x3f81d0b5U: {
     int rounding_mode = fputil::get_round();
     if (rounding_mode == FE_DOWNWARD || rounding_mode == FE_TOWARDZERO) {
       return 0x1.4cdc4cp-6f;
     }
+    break;
+  }
+  case 0x3f7e3274U:
+    if (fputil::get_round() == FE_TONEAREST) {
+      return -0x1.4e1d16p-7f;
+    }
+    break;
+  case 0x3f7d57f5U:
+    if (fputil::get_round() == FE_TOWARDZERO) {
+      return -0x1.ed1c32p-7f;
+    }
+    break;
   }
 
   // Exceptional inputs.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117812.401761.patch
Type: text/x-patch
Size: 1576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220120/cc7c9680/attachment.bin>


More information about the libc-commits mailing list