[libc-commits] [libc] [libc] Make ceilf128 use the emulated float128 type (PR #207735)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 30 07:56:18 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/207735
>From 462a18e7111be07f9ffcdea8821fb5f52be5c545 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:00:33 +0530
Subject: [PATCH 01/22] test: emulated float128 with ceilf128
---
libc/shared/math/ceilf128.h | 9 +++------
libc/src/__support/math/ceilf128.h | 11 ++++-------
libc/src/math/ceilf128.h | 5 ++++-
libc/src/math/generic/ceilf128.cpp | 5 ++++-
libc/test/src/math/ceilf128_test.cpp | 5 ++++-
5 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/libc/shared/math/ceilf128.h b/libc/shared/math/ceilf128.h
index b9e6655393e14..25611636e2233 100644
--- a/libc/shared/math/ceilf128.h
+++ b/libc/shared/math/ceilf128.h
@@ -9,12 +9,11 @@
#ifndef LLVM_LIBC_SHARED_MATH_CEILF128_H
#define LLVM_LIBC_SHARED_MATH_CEILF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "shared/libc_common.h"
#include "src/__support/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace shared {
@@ -24,6 +23,4 @@ using math::ceilf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SHARED_MATH_CEILF128_H
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 8877594d58d68..f12fc6a11a07c 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -9,21 +9,18 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_FLOAT128
-
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr float128 ceilf128(float128 x) { return fputil::ceil(x); }
+LIBC_INLINE constexpr Float128 ceilf128(Float128 x) { return fputil::ceil(x); }
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_FLOAT128
-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
diff --git a/libc/src/math/ceilf128.h b/libc/src/math/ceilf128.h
index 211b8131a9559..40de768feb299 100644
--- a/libc/src/math/ceilf128.h
+++ b/libc/src/math/ceilf128.h
@@ -11,10 +11,13 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
-float128 ceilf128(float128 x);
+Float128 ceilf128(Float128 x);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index fd9c206612207..e359ef9cb18b7 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -8,10 +8,13 @@
#include "src/math/ceilf128.h"
#include "src/__support/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
+LLVM_LIBC_FUNCTION(Float128, ceilf128, (Float128 x)) {
return math::ceilf128(x);
}
diff --git a/libc/test/src/math/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index f0da8258f79bc..e01221f4ac6cd 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -9,5 +9,8 @@
#include "CeilTest.h"
#include "src/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
-LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
>From 16aab0e84966609bb6fc25a1670665b7873afbbc Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:15:56 +0530
Subject: [PATCH 02/22] test: float128
---
libc/src/__support/math/ceilf128.h | 3 ---
libc/test/shared/shared_math_test.cpp | 11 ++++++++++-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index f12fc6a11a07c..0361251b664a9 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -11,9 +11,6 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
-#include "src/__support/FPUtil/float128.h"
-
-using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace math {
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 9da54744b5307..76c2d8c8fe7b7 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -576,6 +576,16 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+// Emulated float128
+// TODO: style
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcSharedMathTest, AllEmuFloat128){
+ EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+}
+
#ifdef LIBC_TYPES_HAS_FLOAT128
TEST(LlvmLibcSharedMathTest, AllFloat128) {
@@ -621,7 +631,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(bfloat16(2.0), LIBC_NAMESPACE::shared::bf16divf128(
float128(4.0), float128(2.0)));
- EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::copysignf128(
float128(0.0), float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
>From 4b195cc3193a2b00a2db189868471f33e409ed74 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:23:17 +0530
Subject: [PATCH 03/22] nit
---
libc/test/shared/CMakeLists.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 71b8bcd8d4ff1..9e9985a78f524 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -17,6 +17,7 @@ add_fp_unittest(
SRCS
shared_math_test.cpp
DEPENDS
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.fp_bits
libc.src.__support.math.acos
libc.src.__support.math.acosbf16
>From 974d4f5f9af82b3ecd0d7df72c23e9bf0f8893ab Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:35:44 +0530
Subject: [PATCH 04/22] cmake edits
---
libc/src/__support/math/CMakeLists.txt | 2 +-
libc/src/__support/math/ceilf128.h | 3 +++
libc/src/math/generic/CMakeLists.txt | 1 +
libc/test/src/math/CMakeLists.txt | 1 +
libc/test/src/math/smoke/CMakeLists.txt | 1 +
libc/test/src/math/smoke/ceilf128_test.cpp | 5 ++++-
6 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 9f4624682eafe..93d226b807a67 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -813,7 +813,7 @@ add_header_library(
HDRS
ceilf128.h
DEPENDS
- libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 0361251b664a9..d8d82970df7e7 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -11,7 +11,10 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/macros/config.h"
+#include "src/__support/FPUtil/float128.h"
+using LIBC_NAMESPACE::fputil::Float128;
+c
namespace LIBC_NAMESPACE_DECL {
namespace math {
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d5661f6f55e91..83c6d7bf55bd7 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -162,6 +162,7 @@ add_entrypoint_object(
../ceilf128.h
DEPENDS
libc.src.__support.math.ceilf128
+ libc.src.__support.FPUtil.float128
)
add_entrypoint_object(
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 240689c0de02f..59a6d75b504d5 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -435,6 +435,7 @@ add_fp_unittest(
libc.src.math.ceilf128
libc.src.__support.CPP.algorithm
libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.float128
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 81f76fa7681fd..6710fb1196e0f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -618,6 +618,7 @@ add_fp_unittest(
CeilTest.h
DEPENDS
libc.src.math.ceilf128
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/smoke/ceilf128_test.cpp b/libc/test/src/math/smoke/ceilf128_test.cpp
index f0da8258f79bc..e01221f4ac6cd 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -9,5 +9,8 @@
#include "CeilTest.h"
#include "src/math/ceilf128.h"
+#include "src/__support/FPUtil/float128.h"
-LIST_CEIL_TESTS(float128, LIBC_NAMESPACE::ceilf128)
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIST_CEIL_TESTS(Float128, LIBC_NAMESPACE::ceilf128)
>From f033b479933edf8ed2a5705da34c6178cfc2bd78 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 29 Jun 2026 16:41:00 +0530
Subject: [PATCH 05/22] nits
---
libc/src/__support/math/ceilf128.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index d8d82970df7e7..f12fc6a11a07c 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -14,7 +14,7 @@
#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
-c
+
namespace LIBC_NAMESPACE_DECL {
namespace math {
>From ad53585b8c69e05fdfe3c2b3dbbe4fd58524e88c Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:17:21 +0530
Subject: [PATCH 06/22] test mpfr
---
libc/utils/MPFRWrapper/CMakeLists.txt | 120 +++++++++++++-------------
libc/utils/MPFRWrapper/MPCommon.cpp | 7 ++
libc/utils/MPFRWrapper/MPCommon.h | 9 +-
3 files changed, 76 insertions(+), 60 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 73151c61a7fcc..a1324e9af33c9 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,59 +1,61 @@
-if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
- add_library(libcMPCommon STATIC
- MPCommon.cpp
- MPCommon.h
- mpfr_inc.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
- add_dependencies(
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.string
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.type_traits
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.cast
- libc.src.__support.FPUtil.fp_bits
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
-
-if(LIBC_TESTS_CAN_USE_MPFR)
- add_library(libcMPFRWrapper STATIC
- MPFRUtils.cpp
- MPFRUtils.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
- add_dependencies(
- libcMPFRWrapper
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.array
- libc.src.__support.CPP.stringstream
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.fpbits_str
- LibcTest.unit
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
+if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
+ add_library(libcMPCommon STATIC
+ MPCommon.cpp
+ MPCommon.h
+ mpfr_inc.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+ add_dependencies(
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.string
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fp_bits
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
+
+if(LIBC_TESTS_CAN_USE_MPFR)
+ add_library(libcMPFRWrapper STATIC
+ MPFRUtils.cpp
+ MPFRUtils.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+ add_dependencies(
+ libcMPFRWrapper
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.stringstream
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.fpbits_str
+ LibcTest.unit
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index 2422bcf45222f..8546aef2a2ff5 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -13,6 +13,9 @@
#include "src/__support/FPUtil/cast.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -650,6 +653,10 @@ template <> bfloat16 MPFRNumber::as<bfloat16>() const {
return fputil::cast<bfloat16>(mpfr_get_flt(value, mpfr_rounding));
}
+template <> Float128 MPFRNumber::as<Float128>() const {
+ return fputil::cast<Float128>(mpfr_get_flt(value, mpfr_rounding));
+}
+
} // namespace mpfr
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 38fd15fcc956c..518144fd9160a 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -16,6 +16,9 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
#include "test/UnitTest/RoundingModeUtils.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
#include "mpfr_inc.h"
@@ -69,6 +72,10 @@ template <> struct ExtraPrecision<bfloat16> {
static constexpr unsigned int VALUE = 64;
};
+template <> struct ExtraPrecision<Float128> {
+ static constexpr unsigned int VALUE = VALUE = 512;
+}
+
// If the ulp tolerance is less than or equal to 0.5, we would check that the
// result is rounded correctly with respect to the rounding mode by using the
// same precision as the inputs.
@@ -116,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp:::is_same<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From c25a19c423eb218129346386abc6987663fefec1 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:23:07 +0530
Subject: [PATCH 07/22] shared_math_constexpr update
---
libc/test/shared/CMakeLists.txt | 1 +
libc/test/shared/shared_math_constexpr_test.cpp | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9e9985a78f524..7a02e0a193606 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -529,6 +529,7 @@ add_fp_unittest(
shared_math_constexpr_test.cpp
DEPENDS
libc.src.__support.math.asinbf16
+ libc.src.__support.FPUtil.float128
libc.src.__support.math.bf16subl
libc.src.__support.math.canonicalize
libc.src.__support.math.canonicalizebf16
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index d5d14dcc65f02..9e766977e5c81 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -10,6 +10,9 @@
#include "shared/math.h"
#include "test/UnitTest/Test.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;s
#ifdef LIBC_USE_CONSTEXPR
@@ -373,6 +376,11 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
#endif
+//emulated float128
+
+static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+
+
//===----------------------------------------------------------------------===//
// Float128 Tests
//===----------------------------------------------------------------------===//
@@ -384,7 +392,6 @@ static_assert(0 == [] {
float128 x = float128(0.0);
return LIBC_NAMESPACE::shared::canonicalizef128(&cx, &x);
}());
-static_assert(float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(float128(0.0)));
static_assert(float128(1.0) ==
LIBC_NAMESPACE::shared::fabsf128(float128(-1.0)));
static_assert(float128(0.0) ==
>From e5afb6c0aa06562a0b164b71ae5d8cfda469905e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:46:33 +0530
Subject: [PATCH 08/22] nits
---
libc/test/shared/shared_math_constexpr_test.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 9e766977e5c81..e5d22ffcfdd37 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -12,7 +12,7 @@
#include "test/UnitTest/Test.h"
#include "src/__support/FPUtil/float128.h"
-using LIBC_NAMESPACE::fputil::Float128;s
+using LIBC_NAMESPACE::fputil::Float128;
#ifdef LIBC_USE_CONSTEXPR
>From 96f9888602e2496de03a84fd2a2f3df77ae91857 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 11:50:28 +0530
Subject: [PATCH 09/22] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 518144fd9160a..6339283fe5e05 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -123,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp:::is_same<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp::is_same<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From e203d4032352aba803729db824a055f9d7b8d1e7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:39:29 +0530
Subject: [PATCH 10/22] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 6339283fe5e05..43acdfd28e9ae 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -73,7 +73,7 @@ template <> struct ExtraPrecision<bfloat16> {
};
template <> struct ExtraPrecision<Float128> {
- static constexpr unsigned int VALUE = VALUE = 512;
+ static constexpr unsigned int VALUE = 512;
}
// If the ulp tolerance is less than or equal to 0.5, we would check that the
>From ed7e6956bc113489c8bf05d5b49ac9be35308fd0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:45:17 +0530
Subject: [PATCH 11/22] nits
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 43acdfd28e9ae..a5c2af909445f 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -74,7 +74,7 @@ template <> struct ExtraPrecision<bfloat16> {
template <> struct ExtraPrecision<Float128> {
static constexpr unsigned int VALUE = 512;
-}
+};
// If the ulp tolerance is less than or equal to 0.5, we would check that the
// result is rounded correctly with respect to the rounding mode by using the
>From dfceb17972366cefe149f483ce6e48d7d4ebec6e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 12:50:06 +0530
Subject: [PATCH 12/22] nit
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index a5c2af909445f..60d89edcf4287 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -123,7 +123,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp::is_same<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType> || cpp::is_same_v<Float128,XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
>From adc56a5d5ab97cdb1ff345f7f41460c9d7d5558d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:21:38 +0530
Subject: [PATCH 13/22] nit
---
libc/utils/MPFRWrapper/MPFRUtils.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index d585baa2e0d2c..e3f612dc4c008 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -15,6 +15,9 @@
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
+#include "src/__support/FPUtil/float128.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -288,6 +291,12 @@ template void explain_unary_operation_single_output_error(Operation op,
bfloat16, bfloat16,
double, RoundingMode);
+// Emulated Float128 is always available regardless of native float128 support.
+template void
+explain_unary_operation_single_output_error(Operation op, fputil::Float128,
+ fputil::Float128, double,
+ RoundingMode);
+
template <typename T>
void explain_unary_operation_two_outputs_error(
Operation op, T input, const BinaryOutput<T> &libc_result,
@@ -580,6 +589,10 @@ template bool compare_unary_operation_single_output(Operation, float128,
template bool compare_unary_operation_single_output(Operation, bfloat16,
bfloat16, double,
RoundingMode);
+// Emulated Float128
+template bool compare_unary_operation_single_output(Operation, fputil::Float128,
+ fputil::Float128, double,
+ RoundingMode);
template <typename T>
bool compare_unary_operation_two_outputs(Operation op, T input,
>From bc1ed1ae4d94a406ea00314892367057b54005c5 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 30 Jun 2026 14:29:13 +0530
Subject: [PATCH 14/22] nit
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 60d89edcf4287..ee5a69f0353d1 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -298,7 +298,7 @@ class MPFRNumber {
if (FPBits<T>(input).is_subnormal())
++inputExponent;
- if (thisAsT * input < 0 || thisExponent == inputExponent) {
+ if (thisAsT * input < T(0) || thisExponent == inputExponent) {
MPFRNumber inputMPFR(input);
mpfr_sub(inputMPFR.value, value, inputMPFR.value, MPFR_RNDN);
mpfr_abs(inputMPFR.value, inputMPFR.value, MPFR_RNDN);
>From 57f6894070d616d1054b0d9d47779cdc611791a8 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 20:44:29 +0530
Subject: [PATCH 15/22] test mpfr_get_float128
---
libc/utils/MPFRWrapper/CMakeLists.txt | 122 +++++++++++++-------------
libc/utils/MPFRWrapper/MPCommon.cpp | 2 +-
2 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index a1324e9af33c9..fe328062c2b1c 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -1,61 +1,61 @@
-if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
- add_library(libcMPCommon STATIC
- MPCommon.cpp
- MPCommon.h
- mpfr_inc.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
- add_dependencies(
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.string
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.type_traits
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.float128
- libc.src.__support.FPUtil.cast
- libc.src.__support.FPUtil.fp_bits
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
-
-if(LIBC_TESTS_CAN_USE_MPFR)
- add_library(libcMPFRWrapper STATIC
- MPFRUtils.cpp
- MPFRUtils.h
- )
- _get_common_test_compile_options(compile_options "" "")
- # mpfr/gmp headers do not work with -ffreestanding flag.
- list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
- add_dependencies(
- libcMPFRWrapper
- libcMPCommon
- libc.hdr.stdint_proxy
- libc.src.__support.CPP.array
- libc.src.__support.CPP.stringstream
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.FPUtil.float128
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.fpbits_str
- LibcTest.unit
- )
- if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
- target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
- target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
- endif()
- target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
- target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
-elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
- message(WARNING "Math tests using MPFR will be skipped.")
-endif()
+if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
+ add_library(libcMPCommon STATIC
+ MPCommon.cpp
+ MPCommon.h
+ mpfr_inc.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+ add_dependencies(
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.string
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.cast
+ libc.src.__support.FPUtil.fp_bits
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPCommon PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPCommon PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPCommon PUBLIC LibcFPTestHelpers.unit mpfr gmp)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
+
+if(LIBC_TESTS_CAN_USE_MPFR)
+ add_library(libcMPFRWrapper STATIC
+ MPFRUtils.cpp
+ MPFRUtils.h
+ )
+ _get_common_test_compile_options(compile_options "" "")
+ # mpfr/gmp headers do not work with -ffreestanding flag.
+ list(REMOVE_ITEM compile_options "-ffreestanding")
+ target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+ add_dependencies(
+ libcMPFRWrapper
+ libcMPCommon
+ libc.hdr.stdint_proxy
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.stringstream
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.float128
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.fpbits_str
+ LibcTest.unit
+ )
+ if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH})
+ target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include)
+ target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib)
+ endif()
+ target_include_directories(libcMPFRWrapper PUBLIC ${LIBC_SOURCE_DIR})
+ target_link_libraries(libcMPFRWrapper PUBLIC libcMPCommon LibcFPTestHelpers.unit LibcTest.unit)
+elseif(NOT LIBC_TARGET_OS_IS_GPU AND NOT LLVM_LIBC_FULL_BUILD)
+ message(WARNING "Math tests using MPFR will be skipped.")
+endif()
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index 8546aef2a2ff5..fb9573ca424f8 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -654,7 +654,7 @@ template <> bfloat16 MPFRNumber::as<bfloat16>() const {
}
template <> Float128 MPFRNumber::as<Float128>() const {
- return fputil::cast<Float128>(mpfr_get_flt(value, mpfr_rounding));
+ return fputil::cast<Float128>(mpfr_get_float128(value, mpfr_rounding));
}
} // namespace mpfr
>From 8b5cd2462216c78ba7de7f6d02562e3ed33e2081 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 2 Jul 2026 21:10:58 +0530
Subject: [PATCH 16/22] non-native mpfr_get_float128
---
libc/utils/MPFRWrapper/MPCommon.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index ee5a69f0353d1..72444375c262d 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -27,6 +27,11 @@ extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
+#else
+extern "C"{
+int mpfr_set_float128(mpfr_ptr, Float128, mpfr_rnd_t);
+Float128 mpfr_get_float128(mpfr_srcptr,mpfr_rnd_t);
+}
#endif
namespace LIBC_NAMESPACE_DECL {
>From 00877d0af85d83f982a64fc3af3d4d9aa4f0e447 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 12:57:55 +0530
Subject: [PATCH 17/22] add template for Float128 separately
---
libc/utils/MPFRWrapper/MPCommon.h | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 72444375c262d..981f6ba23df93 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -128,7 +128,7 @@ class MPFRNumber {
#ifdef LIBC_TYPES_HAS_FLOAT16
|| cpp::is_same_v<float16, XType>
#endif
- || cpp::is_same_v<bfloat16, XType> || cpp::is_same_v<Float128,XType>,
+ || cpp::is_same_v<bfloat16, XType>,
int> = 0>
explicit MPFRNumber(XType x,
unsigned int precision = ExtraPrecision<XType>::VALUE,
@@ -174,6 +174,17 @@ class MPFRNumber {
}
#endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+ template <typename XType,
+ cpp::enable_if_t<cpp::is_same_v<Float128, XType>, int> = 0>
+ explicit MPFRNumber(XType x,
+ unsigned int precision = ExtraPrecision<XType>::VALUE,
+ RoundingMode rounding = RoundingMode::Nearest)
+ : mpfr_precision(precision),
+ mpfr_rounding(get_mpfr_rounding_mode(rounding)) {
+ mpfr_init2(value, mpfr_precision);
+ mpfr_set_float128(value, x, mpfr_rounding);
+ }
+
template <typename XType,
cpp::enable_if_t<cpp::is_integral_v<XType>, int> = 0>
explicit MPFRNumber(XType x,
>From f931df662af4fa84be75d75ca4313744a8082350 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:00:30 +0530
Subject: [PATCH 18/22] formatting
---
libc/shared/math/ceilf128.h | 2 +-
libc/src/__support/math/ceilf128.h | 2 +-
libc/src/math/ceilf128.h | 2 +-
libc/src/math/generic/ceilf128.cpp | 2 +-
libc/test/shared/shared_math_test.cpp | 4 ++--
libc/test/src/math/ceilf128_test.cpp | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/shared/math/ceilf128.h b/libc/shared/math/ceilf128.h
index 25611636e2233..d7fe00fe86a3e 100644
--- a/libc/shared/math/ceilf128.h
+++ b/libc/shared/math/ceilf128.h
@@ -10,8 +10,8 @@
#define LLVM_LIBC_SHARED_MATH_CEILF128_H
#include "shared/libc_common.h"
-#include "src/__support/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index f12fc6a11a07c..31b3debb890da 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -10,8 +10,8 @@
#define LLVM_LIBC_SRC___SUPPORT_MATH_CEILF128_H
#include "src/__support/FPUtil/NearestIntegerOperations.h"
-#include "src/__support/macros/config.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/macros/config.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/math/ceilf128.h b/libc/src/math/ceilf128.h
index 40de768feb299..32b69433767b5 100644
--- a/libc/src/math/ceilf128.h
+++ b/libc/src/math/ceilf128.h
@@ -9,9 +9,9 @@
#ifndef LLVM_LIBC_SRC_MATH_CEILF128_H
#define LLVM_LIBC_SRC_MATH_CEILF128_H
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index e359ef9cb18b7..acb5ed3b8b8ab 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "src/math/ceilf128.h"
-#include "src/__support/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/__support/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 76c2d8c8fe7b7..3d52f190f55c1 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -576,13 +576,13 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
#endif // LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
-// Emulated float128
+// Emulated float128
// TODO: style
#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
-TEST(LlvmLibcSharedMathTest, AllEmuFloat128){
+TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
}
diff --git a/libc/test/src/math/ceilf128_test.cpp b/libc/test/src/math/ceilf128_test.cpp
index e01221f4ac6cd..accb766e1526d 100644
--- a/libc/test/src/math/ceilf128_test.cpp
+++ b/libc/test/src/math/ceilf128_test.cpp
@@ -8,8 +8,8 @@
#include "CeilTest.h"
-#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
>From d4b0934afbcb4cbe180ed90bd3bbf641a4697c7d Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 5 Jul 2026 13:36:00 +0530
Subject: [PATCH 19/22] chore: format
---
libc/test/shared/shared_math_constexpr_test.cpp | 5 ++---
libc/test/src/math/smoke/ceilf128_test.cpp | 2 +-
libc/utils/MPFRWrapper/MPCommon.cpp | 2 +-
libc/utils/MPFRWrapper/MPCommon.h | 8 ++++----
libc/utils/MPFRWrapper/MPFRUtils.cpp | 10 +++++-----
5 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index e5d22ffcfdd37..ed44fa4aa0be9 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -9,8 +9,8 @@
#define LIBC_ENABLE_CONSTEXPR 1
#include "shared/math.h"
-#include "test/UnitTest/Test.h"
#include "src/__support/FPUtil/float128.h"
+#include "test/UnitTest/Test.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -376,11 +376,10 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
#endif
-//emulated float128
+// emulated float128
static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
-
//===----------------------------------------------------------------------===//
// Float128 Tests
//===----------------------------------------------------------------------===//
diff --git a/libc/test/src/math/smoke/ceilf128_test.cpp b/libc/test/src/math/smoke/ceilf128_test.cpp
index e01221f4ac6cd..accb766e1526d 100644
--- a/libc/test/src/math/smoke/ceilf128_test.cpp
+++ b/libc/test/src/math/smoke/ceilf128_test.cpp
@@ -8,8 +8,8 @@
#include "CeilTest.h"
-#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
+#include "src/math/ceilf128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/utils/MPFRWrapper/MPCommon.cpp b/libc/utils/MPFRWrapper/MPCommon.cpp
index fb9573ca424f8..b3d0b3ca77122 100644
--- a/libc/utils/MPFRWrapper/MPCommon.cpp
+++ b/libc/utils/MPFRWrapper/MPCommon.cpp
@@ -11,9 +11,9 @@
#include "src/__support/CPP/string_view.h"
#include "src/__support/FPUtil/bfloat16.h"
#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 981f6ba23df93..3d364cdcd8dee 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -13,10 +13,10 @@
#include "src/__support/CPP/string.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
#include "test/UnitTest/RoundingModeUtils.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -27,10 +27,10 @@ extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
-#else
-extern "C"{
+#else
+extern "C" {
int mpfr_set_float128(mpfr_ptr, Float128, mpfr_rnd_t);
-Float128 mpfr_get_float128(mpfr_srcptr,mpfr_rnd_t);
+Float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
}
#endif
diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index e3f612dc4c008..14a6f908f6062 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -12,10 +12,10 @@
#include "src/__support/CPP/array.h"
#include "src/__support/CPP/stringstream.h"
#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/FPUtil/fpbits_str.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
-#include "src/__support/FPUtil/float128.h"
using LIBC_NAMESPACE::fputil::Float128;
@@ -292,10 +292,10 @@ template void explain_unary_operation_single_output_error(Operation op,
double, RoundingMode);
// Emulated Float128 is always available regardless of native float128 support.
-template void
-explain_unary_operation_single_output_error(Operation op, fputil::Float128,
- fputil::Float128, double,
- RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+ fputil::Float128,
+ fputil::Float128,
+ double, RoundingMode);
template <typename T>
void explain_unary_operation_two_outputs_error(
>From a2527438ddf2427ef70cd5fa46b02e0328e10ae7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 6 Jul 2026 16:18:57 +0530
Subject: [PATCH 20/22] guard for LD
---
libc/utils/MPFRWrapper/MPCommon.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/utils/MPFRWrapper/MPCommon.h b/libc/utils/MPFRWrapper/MPCommon.h
index 3d364cdcd8dee..96e1d35b7777a 100644
--- a/libc/utils/MPFRWrapper/MPCommon.h
+++ b/libc/utils/MPFRWrapper/MPCommon.h
@@ -22,7 +22,7 @@ using LIBC_NAMESPACE::fputil::Float128;
#include "mpfr_inc.h"
-#ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#ifdef LIBC_TYPES_HAS_FLOAT128
extern "C" {
int mpfr_set_float128(mpfr_ptr, float128, mpfr_rnd_t);
float128 mpfr_get_float128(mpfr_srcptr, mpfr_rnd_t);
>From f123a177d48587e7f709c49afa15821e9f4901e4 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 01:37:18 +0530
Subject: [PATCH 21/22] test
---
libc/src/__support/math/CMakeLists.txt | 1 +
libc/src/__support/math/ceilf128.h | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 93d226b807a67..902fad2a08eb5 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -816,6 +816,7 @@ add_header_library(
libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.nearest_integer_operations
libc.src.__support.macros.config
+ libc.src.__support.macros.properties.types
)
add_header_library(
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index 31b3debb890da..c89198780696a 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -12,13 +12,22 @@
#include "src/__support/FPUtil/NearestIntegerOperations.h"
#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr Float128 ceilf128(Float128 x) { return fputil::ceil(x); }
+#ifdef LIBC_TYPES_HAS_FLOAT128
+LIBC_INLINE constexpr float128 ceilf128(float128 x) {
+ return static_cast<float128>(fputil::ceil(fputil::Float128(x)));
+}
+#else
+LIBC_INLINE constexpr fputil::Float128 ceilf128(fputil::Float128 x) {
+ return fputil::ceil(x);
+}
+#endif // LIBC_TYPES_HAS_FLOAT128
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
>From 73d6181030eab64c466ac70c4603e6c9d7220ccb Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 30 Jul 2026 20:25:15 +0530
Subject: [PATCH 22/22] test
---
libc/src/__support/math/ceilf128.h | 4 ++--
libc/src/math/generic/CMakeLists.txt | 1 +
libc/src/math/generic/ceilf128.cpp | 7 +++++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/math/ceilf128.h b/libc/src/__support/math/ceilf128.h
index c89198780696a..32050b9c80c99 100644
--- a/libc/src/__support/math/ceilf128.h
+++ b/libc/src/__support/math/ceilf128.h
@@ -21,10 +21,10 @@ namespace math {
#ifdef LIBC_TYPES_HAS_FLOAT128
LIBC_INLINE constexpr float128 ceilf128(float128 x) {
- return static_cast<float128>(fputil::ceil(fputil::Float128(x)));
+ return static_cast<float128>(fputil::ceil(Float128(x)));
}
#else
-LIBC_INLINE constexpr fputil::Float128 ceilf128(fputil::Float128 x) {
+LIBC_INLINE constexpr Float128 ceilf128(Float128 x) {
return fputil::ceil(x);
}
#endif // LIBC_TYPES_HAS_FLOAT128
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 83c6d7bf55bd7..924c9b83f5e85 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -163,6 +163,7 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.math.ceilf128
libc.src.__support.FPUtil.float128
+ libc.src.__support.macros.properties.types
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/ceilf128.cpp b/libc/src/math/generic/ceilf128.cpp
index acb5ed3b8b8ab..685518ed49d32 100644
--- a/libc/src/math/generic/ceilf128.cpp
+++ b/libc/src/math/generic/ceilf128.cpp
@@ -9,13 +9,20 @@
#include "src/math/ceilf128.h"
#include "src/__support/FPUtil/float128.h"
#include "src/__support/math/ceilf128.h"
+#include "src/__support/macros/properties/types.h"
using LIBC_NAMESPACE::fputil::Float128;
namespace LIBC_NAMESPACE_DECL {
+#ifdef LIBC_TYPES_HAS_FLOAT128
+LLVM_LIBC_FUNCTION(float128, ceilf128, (float128 x)) {
+ return static_cast<float128>(math::ceilf128(Float128(x)));
+}
+#else
LLVM_LIBC_FUNCTION(Float128, ceilf128, (Float128 x)) {
return math::ceilf128(x);
}
+#endif // LIBC_TYPES_HAS_FLOAT128
} // namespace LIBC_NAMESPACE_DECL
More information about the libc-commits
mailing list