[libc-commits] [libc] [libc] Add NEED_MPFR_F128 argument to add_fp_unittest. (PR #215657)

via libc-commits libc-commits at lists.llvm.org
Thu Aug 13 04:33:53 PDT 2026


https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/215657

>From a3792832d71d6a87a41b64dd8804b19dfb566dd3 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 12 Aug 2026 02:12:18 +0530
Subject: [PATCH 1/5] add NEED_MPFR128

---
 libc/test/src/CMakeLists.txt | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index 2beeb5517ff3e..3101730b8a0e1 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 function(add_fp_unittest name)
   cmake_parse_arguments(
     "MATH_UNITTEST"
-    "NEED_MPFR;NEED_MPC;FULL_BUILD_ONLY;OVERLAY_BUILD_ONLY" # Optional arguments
+    "NEED_MPFR;NEED_MPFR128;NEED_MPC;FULL_BUILD_ONLY;OVERLAY_BUILD_ONLY" # Optional arguments
     "" # Single value arguments
     "LINK_LIBRARIES;DEPENDS" # Multi-value arguments
     ${ARGN}
@@ -16,6 +16,16 @@ function(add_fp_unittest name)
     list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPCWrapper)
   endif()
 
+  # TODO: To be removed when we find a workaround to run MPFR tests for
+  # emulated type where compiler doesn't support the native float128
+  if(MATH_UNITTEST_NEED_MPFR128)
+    set(MATH_UNITTEST_NEED_MPFR TRUE)
+    if(NOT LIBC_TYPES_HAS_NATIVE_FLOAT128)
+      message(VERBOSE "Math test ${name} will be skipped as native float128 type is not available.")
+      return()
+    endif()
+  endif()
+
   if(MATH_UNITTEST_NEED_MPFR)
     if(NOT LIBC_TESTS_CAN_USE_MPFR)
       message(VERBOSE "Math test ${name} will be skipped as MPFR library is not available.")

>From 71b802aa9b721e44abebb3f4c2232a6921981e37 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 12 Aug 2026 23:06:04 +0530
Subject: [PATCH 2/5] nits

---
 libc/test/src/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index 3101730b8a0e1..a8e1fabc15377 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -1,7 +1,7 @@
 function(add_fp_unittest name)
   cmake_parse_arguments(
     "MATH_UNITTEST"
-    "NEED_MPFR;NEED_MPFR128;NEED_MPC;FULL_BUILD_ONLY;OVERLAY_BUILD_ONLY" # Optional arguments
+    "NEED_MPFR;NEED_MPFR_F128;NEED_MPC;FULL_BUILD_ONLY;OVERLAY_BUILD_ONLY" # Optional arguments
     "" # Single value arguments
     "LINK_LIBRARIES;DEPENDS" # Multi-value arguments
     ${ARGN}
@@ -21,7 +21,7 @@ function(add_fp_unittest name)
   if(MATH_UNITTEST_NEED_MPFR128)
     set(MATH_UNITTEST_NEED_MPFR TRUE)
     if(NOT LIBC_TYPES_HAS_NATIVE_FLOAT128)
-      message(VERBOSE "Math test ${name} will be skipped as native float128 type is not available.")
+      message(VERBOSE "Math test ${name} will be skipped as native float128 support in MPFR is not available.")
       return()
     endif()
   endif()

>From 0b6b7a601569785b4991a5f3d3bf5c97222d5c93 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Wed, 12 Aug 2026 23:32:13 +0530
Subject: [PATCH 3/5] use NEED_MPFR_F128 with float128 functions

---
 libc/test/src/CMakeLists.txt            |  2 +-
 libc/test/src/math/CMakeLists.txt       | 18 +++++++++---------
 libc/test/src/math/smoke/CMakeLists.txt |  1 -
 3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index a8e1fabc15377..b0cde52e32075 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -18,7 +18,7 @@ function(add_fp_unittest name)
 
   # TODO: To be removed when we find a workaround to run MPFR tests for
   # emulated type where compiler doesn't support the native float128
-  if(MATH_UNITTEST_NEED_MPFR128)
+  if(MATH_UNITTEST_NEED_MPFR_F128)
     set(MATH_UNITTEST_NEED_MPFR TRUE)
     if(NOT LIBC_TYPES_HAS_NATIVE_FLOAT128)
       message(VERBOSE "Math test ${name} will be skipped as native float128 support in MPFR is not available.")
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 04a17664a425b..850cf31e8f44f 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -424,7 +424,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   ceilf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -1781,7 +1781,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   sqrtf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -2756,7 +2756,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   scalbnf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -2866,7 +2866,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   atan2f128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -3421,7 +3421,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   bf16addf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -3477,7 +3477,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   bf16divf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -3539,7 +3539,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   bf16fmaf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -3603,7 +3603,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   bf16mulf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
@@ -3661,7 +3661,7 @@ add_fp_unittest(
 
 add_fp_unittest(
   bf16subf128_test
-  NEED_MPFR
+  NEED_MPFR_F128
   SUITE
     libc-math-unittests
   SRCS
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index dfc1e411cdfed..9eb6e687a06c1 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -290,7 +290,6 @@ add_fp_unittest(
 
 add_fp_unittest(
   faddf128_test
-  NEED_MPFR
   SUITE
     libc-math-unittests
   SRCS

>From e15116ca442588354ce6be2050e2974b04c96d23 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 13 Aug 2026 16:46:43 +0530
Subject: [PATCH 4/5] acosbf16

---
 libc/test/src/math/smoke/CMakeLists.txt    |  1 -
 libc/test/src/math/smoke/acosbf16_test.cpp | 23 +++++++++++++---------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9eb6e687a06c1..ecc58ef7c2b1e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4914,7 +4914,6 @@ add_fp_unittest(
 
 add_fp_unittest(
   acosbf16_test
-  NEED_MPFR
   SUITE
     libc-math-smoke-tests
   SRCS
diff --git a/libc/test/src/math/smoke/acosbf16_test.cpp b/libc/test/src/math/smoke/acosbf16_test.cpp
index ec2f9e34f8fbd..b78367caaa0df 100644
--- a/libc/test/src/math/smoke/acosbf16_test.cpp
+++ b/libc/test/src/math/smoke/acosbf16_test.cpp
@@ -6,14 +6,12 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "hdr/errno_macros.h"
 #include "src/__support/FPUtil/bfloat16.h"
 #include "src/math/acosbf16.h"
 #include "test/UnitTest/FEnvSafeTest.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
 class LlvmLibcAcosBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   DECLARE_SPECIAL_CONSTANTS(bfloat16)
@@ -26,6 +24,14 @@ class LlvmLibcAcosBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
         aNaN, LIBC_NAMESPACE::acosbf16(sNaN), FE_INVALID);
     EXPECT_MATH_ERRNO(0);
 
+    EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+        aNaN, LIBC_NAMESPACE::acosbf16(inf), FE_INVALID);
+    EXPECT_MATH_ERRNO(EDOM);
+
+    EXPECT_FP_EQ_WITH_EXCEPTION_ALL_ROUNDING(
+        aNaN, LIBC_NAMESPACE::acosbf16(neg_inf), FE_INVALID);
+    EXPECT_MATH_ERRNO(EDOM);
+
     EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(0x1.921fb6p0f),
                               LIBC_NAMESPACE::acosbf16(zero));
     EXPECT_MATH_ERRNO(0);
@@ -34,13 +40,12 @@ class LlvmLibcAcosBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
                               LIBC_NAMESPACE::acosbf16(neg_zero));
     EXPECT_MATH_ERRNO(0);
 
-    bfloat16 VALUES[] = {inf, neg_inf, bfloat16(1.0f), bfloat16(-1.0)};
-    for (size_t i = 0; i < 4; ++i) {
-      bfloat16 x = VALUES[i];
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::acosbf16(1.0));
+    EXPECT_MATH_ERRNO(0);
 
-      EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Acos, x,
-                                     LIBC_NAMESPACE::acosbf16(x), 0.5);
-    }
+    EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(0x1.921fb6p1f),
+                              LIBC_NAMESPACE::acosbf16(-1.0));
+    EXPECT_MATH_ERRNO(0);
   }
 };
 TEST_F(LlvmLibcAcosBf16Test, SpecialNumbers) { test_special_numbers(); }

>From 3a0d1241ee922cfbdca3a112d802e461c2622b3e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 13 Aug 2026 16:56:32 +0530
Subject: [PATCH 5/5] atanbf16

---
 libc/test/src/math/smoke/CMakeLists.txt    |  1 -
 libc/test/src/math/smoke/acosbf16_test.cpp |  4 ++--
 libc/test/src/math/smoke/atanbf16_test.cpp | 23 +++++++++++++---------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ecc58ef7c2b1e..8cf9c36095aa5 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -5006,7 +5006,6 @@ add_fp_unittest(
 
 add_fp_unittest(
   atanbf16_test
-  NEED_MPFR
   SUITE
     libc-math-smoke-tests
   SRCS
diff --git a/libc/test/src/math/smoke/acosbf16_test.cpp b/libc/test/src/math/smoke/acosbf16_test.cpp
index b78367caaa0df..4ca738446b990 100644
--- a/libc/test/src/math/smoke/acosbf16_test.cpp
+++ b/libc/test/src/math/smoke/acosbf16_test.cpp
@@ -40,11 +40,11 @@ class LlvmLibcAcosBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
                               LIBC_NAMESPACE::acosbf16(neg_zero));
     EXPECT_MATH_ERRNO(0);
 
-    EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::acosbf16(1.0));
+    EXPECT_FP_EQ_ALL_ROUNDING(zero, LIBC_NAMESPACE::acosbf16(bfloat16(1.0)));
     EXPECT_MATH_ERRNO(0);
 
     EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(0x1.921fb6p1f),
-                              LIBC_NAMESPACE::acosbf16(-1.0));
+                              LIBC_NAMESPACE::acosbf16(bfloat16(-1.0)));
     EXPECT_MATH_ERRNO(0);
   }
 };
diff --git a/libc/test/src/math/smoke/atanbf16_test.cpp b/libc/test/src/math/smoke/atanbf16_test.cpp
index 6e15955316946..36b0fd69566b6 100644
--- a/libc/test/src/math/smoke/atanbf16_test.cpp
+++ b/libc/test/src/math/smoke/atanbf16_test.cpp
@@ -11,9 +11,6 @@
 #include "test/UnitTest/FEnvSafeTest.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
-#include "utils/MPFRWrapper/MPFRUtils.h"
-
-namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
 
 class LlvmLibcAtanBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   DECLARE_SPECIAL_CONSTANTS(bfloat16)
@@ -32,13 +29,21 @@ class LlvmLibcAtanBf16Test : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     EXPECT_FP_EQ_ALL_ROUNDING(neg_zero, LIBC_NAMESPACE::atanbf16(neg_zero));
     EXPECT_MATH_ERRNO(0);
 
-    bfloat16 VALUES[] = {inf, neg_inf, bfloat16(1.0f), bfloat16(-1.0)};
-    for (size_t i = 0; i < 4; ++i) {
-      bfloat16 x = VALUES[i];
+    EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(0x1.921fb6p0f),
+                              LIBC_NAMESPACE::atanbf16(inf));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(-0x1.921fb6p0f),
+                              LIBC_NAMESPACE::atanbf16(neg_inf));
+    EXPECT_MATH_ERRNO(0);
 
-      EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Atan, x,
-                                     LIBC_NAMESPACE::atanbf16(x), 0.5);
-    }
+    EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(0x1.921fb6p-1f),
+                              LIBC_NAMESPACE::atanbf16(bfloat16(1.0)));
+    EXPECT_MATH_ERRNO(0);
+
+    EXPECT_FP_EQ_ALL_ROUNDING(bfloat16(-0x1.921fb6p-1f),
+                              LIBC_NAMESPACE::atanbf16(bfloat16(-1.0)));
+    EXPECT_MATH_ERRNO(0);
   }
 };
 TEST_F(LlvmLibcAtanBf16Test, SpecialNumbers) { test_special_numbers(); }



More information about the libc-commits mailing list