[libc-commits] [libc] [libc] Modify `roundf128` to use emulated Float128 type (PR #216563)
via libc-commits
libc-commits at lists.llvm.org
Sun Aug 16 05:19:22 PDT 2026
https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/216563
None
>From 5bf64b6a6af54face2971bf8d39d64db2af3ce9f Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 16 Aug 2026 17:05:30 +0530
Subject: [PATCH] initial commit + no src/math test files added
---
libc/config/baremetal/aarch64/entrypoints.txt | 2 +-
libc/config/baremetal/arm/entrypoints.txt | 2 +-
libc/config/baremetal/riscv/entrypoints.txt | 2 +-
libc/config/darwin/aarch64/entrypoints.txt | 2 +-
libc/config/darwin/x86_64/entrypoints.txt | 1 +
libc/config/freebsd/x86_64/entrypoints.txt | 2 +-
libc/config/gpu/amdgpu/entrypoints.txt | 1 +
libc/config/gpu/nvptx/entrypoints.txt | 1 +
libc/config/linux/aarch64/entrypoints.txt | 2 +-
libc/config/linux/arm/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 2 +-
libc/config/linux/x86_64/entrypoints.txt | 2 +-
libc/config/windows/entrypoints.txt | 1 +
libc/shared/math/roundf128.h | 6 ------
libc/src/__support/math/CMakeLists.txt | 2 +-
libc/src/__support/math/roundf128.h | 11 ++++-------
libc/src/math/generic/CMakeLists.txt | 1 +
libc/src/math/generic/roundf128.cpp | 5 ++++-
libc/src/math/roundf128.h | 5 +++++
libc/test/shared/shared_math_constexpr_test.cpp | 4 ++--
libc/test/shared/shared_math_test.cpp | 2 +-
libc/test/src/math/smoke/CMakeLists.txt | 1 +
libc/test/src/math/smoke/roundf128_test.cpp | 6 +++++-
23 files changed, 37 insertions(+), 27 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 81958d224f70d..4b6571f6c4d2f 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -547,6 +547,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -785,7 +786,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ee3ec63132cc2..501b9f03a4ec3 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -559,6 +559,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -796,7 +797,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c9f7c042bf4a8..0b98f6b60b6d7 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -555,6 +555,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -793,7 +794,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 0ca00419a916c..4d4f4f3e5b381 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -366,6 +366,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -605,7 +606,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 136d5a458d484..ec546fd8bf8c7 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -217,6 +217,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.rintl
#libc.src.math.round
#libc.src.math.roundf
+ #libc.src.math.roundf128
#libc.src.math.roundl
#libc.src.math.sincosf
#libc.src.math.sinhf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 2223504718444..e5bb14d20f720 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -267,6 +267,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintl
libc.src.math.round
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -543,7 +544,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 12783aa4e5316..980c5d25ef9c1 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -490,6 +490,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenl
libc.src.math.round
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 5820448e06663..e897825cfff48 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -487,6 +487,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenl
libc.src.math.round
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 071a7830b43d3..60e7b2224ab7c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -700,6 +700,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -932,7 +933,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 1adbb04bb4cbe..0c882665063a5 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -518,6 +518,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintl
libc.src.math.round
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 66dd9dd790737..fecaa0ac1af29 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -773,6 +773,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -1022,7 +1023,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6045886c2f11c..d5467b7f65f49 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -778,6 +778,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.roundevenf
libc.src.math.roundevenl
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
@@ -1027,7 +1028,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remquof128
libc.src.math.rintf128
libc.src.math.roundevenf128
- libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 142b83e71efe6..131ee4396267d 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -300,6 +300,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintl
libc.src.math.round
libc.src.math.roundf
+ libc.src.math.roundf128
libc.src.math.roundl
libc.src.math.scalbln
libc.src.math.scalblnf
diff --git a/libc/shared/math/roundf128.h b/libc/shared/math/roundf128.h
index e781d2d82f5d5..44eb2854842f9 100644
--- a/libc/shared/math/roundf128.h
+++ b/libc/shared/math/roundf128.h
@@ -9,10 +9,6 @@
#ifndef LLVM_LIBC_SHARED_MATH_ROUNDF128_H
#define LLVM_LIBC_SHARED_MATH_ROUNDF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#include "shared/libc_common.h"
#include "src/__support/math/roundf128.h"
@@ -24,6 +20,4 @@ using math::roundf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#endif // LLVM_LIBC_SHARED_MATH_ROUNDF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index db514db61a9df..2cbc55acf70e3 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2549,7 +2549,7 @@ add_header_library(
HDRS
roundf128.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/roundf128.h b/libc/src/__support/math/roundf128.h
index bb4767ad88d83..3c04b2cd83e89 100644
--- a/libc/src/__support/math/roundf128.h
+++ b/libc/src/__support/math/roundf128.h
@@ -9,23 +9,20 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#include "src/__support/FPUtil/NearestIntegerOperations.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
namespace LIBC_NAMESPACE_DECL {
namespace math {
-LIBC_INLINE constexpr float128 roundf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 roundf128(Float128 x) {
return fputil::round(x);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 80c2053066f16..9463e64534aaf 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -724,6 +724,7 @@ add_entrypoint_object(
HDRS
../roundf128.h
DEPENDS
+ libc.src.__support.CPP.bit
libc.src.__support.math.roundf128
)
diff --git a/libc/src/math/generic/roundf128.cpp b/libc/src/math/generic/roundf128.cpp
index 5b2b4c44b2f98..760735cd10a68 100644
--- a/libc/src/math/generic/roundf128.cpp
+++ b/libc/src/math/generic/roundf128.cpp
@@ -7,12 +7,15 @@
//===----------------------------------------------------------------------===//
#include "src/math/roundf128.h"
+#include "src/__support/CPP/bit.h"
#include "src/__support/math/roundf128.h"
namespace LIBC_NAMESPACE_DECL {
+using LIBC_NAMESPACE::fputil::Float128;
+
LLVM_LIBC_FUNCTION(float128, roundf128, (float128 x)) {
- return math::roundf128(x);
+ return cpp::bit_cast<float128>(math::roundf128(cpp::bit_cast<Float128>(x)));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/roundf128.h b/libc/src/math/roundf128.h
index ef56d04a1696d..bf787f4fc42f7 100644
--- a/libc/src/math/roundf128.h
+++ b/libc/src/math/roundf128.h
@@ -9,11 +9,16 @@
#ifndef LLVM_LIBC_SRC_MATH_ROUNDF128_H
#define LLVM_LIBC_SRC_MATH_ROUNDF128_H
+#include "src/__support/FPUtil/float128.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
namespace LIBC_NAMESPACE_DECL {
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
float128 roundf128(float128 x);
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 6f9df85f3bb1c..d860bced9b8f7 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -381,6 +381,8 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
//===----------------------------------------------------------------------===//
static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+static_assert(Float128(0.0) ==
+ LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
//===----------------------------------------------------------------------===//
// Native Float128 Tests
@@ -507,8 +509,6 @@ static_assert(1 == [] {
LIBC_NAMESPACE::shared::nanf128(&arg))
.is_nan();
}());
-static_assert(float128(0.0) ==
- LIBC_NAMESPACE::shared::roundf128(float128(0.0)));
static_assert(float128(0.0) ==
LIBC_NAMESPACE::shared::roundevenf128(float128(0.0)));
static_assert(float128(0.0) ==
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 8850deda1c805..8060018090145 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -582,6 +582,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
// Emulated float128 tests
TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+ EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::roundf128(Float128(0.0)));
}
#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
@@ -752,7 +753,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::isnanf128(float128(0.0)));
EXPECT_EQ(0, LIBC_NAMESPACE::shared::issignalingf128(float128(0.0)));
EXPECT_TRUE(FPBits(LIBC_NAMESPACE::shared::nanf128("")).is_nan());
- EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::roundf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0),
LIBC_NAMESPACE::shared::roundevenf128(float128(0.0)));
EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::truncf128(float128(0.0)));
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 91d76f2c7973c..7d86a1307ba9e 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -827,6 +827,7 @@ add_fp_unittest(
RoundTest.h
DEPENDS
libc.src.math.roundf128
+ libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/smoke/roundf128_test.cpp b/libc/test/src/math/smoke/roundf128_test.cpp
index 01c70c87667b6..c1e1a497a7d50 100644
--- a/libc/test/src/math/smoke/roundf128_test.cpp
+++ b/libc/test/src/math/smoke/roundf128_test.cpp
@@ -7,7 +7,11 @@
//===----------------------------------------------------------------------===//
#include "RoundTest.h"
-
+#include "src/__support/FPUtil/float128.h"
#include "src/math/roundf128.h"
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
LIST_ROUND_TESTS(float128, LIBC_NAMESPACE::roundf128)
More information about the libc-commits
mailing list