[libc-commits] [libc] [libc] Modify `roundevenf128` to use emulated Float128 type (PR #216568)
via libc-commits
libc-commits at lists.llvm.org
Sun Aug 16 06:04:32 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/216568
>From d8dab7ad505e908c0c7229af8eee4e67ef2e2482 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 16 Aug 2026 17:47:13 +0530
Subject: [PATCH 1/2] initial commit
---
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/roundevenf128.h | 6 ------
libc/src/__support/math/CMakeLists.txt | 2 +-
libc/src/__support/math/roundevenf128.h | 11 ++++-------
libc/src/math/generic/CMakeLists.txt | 1 +
libc/src/math/generic/roundevenf128.cpp | 6 +++++-
libc/src/math/roundevenf128.h | 5 +++++
libc/test/shared/shared_math_constexpr_test.cpp | 2 +-
libc/test/shared/shared_math_test.cpp | 2 +-
libc/test/src/math/smoke/CMakeLists.txt | 1 +
libc/test/src/math/smoke/roundevenf128_test.cpp | 5 +++++
23 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 81958d224f70d..d37647a8bddbb 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -545,6 +545,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -784,7 +785,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ee3ec63132cc2..2963cc031386b 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -557,6 +557,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -795,7 +796,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c9f7c042bf4a8..f311c8e32c1e2 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -553,6 +553,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -792,7 +793,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 0ca00419a916c..765e2d4997113 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -364,6 +364,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -604,7 +605,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 136d5a458d484..cc747dbe74f65 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -216,6 +216,7 @@ set(TARGET_LIBM_ENTRYPOINTS
#libc.src.math.rintf
#libc.src.math.rintl
#libc.src.math.round
+ #libc.src.math.roundevenf128
#libc.src.math.roundf
#libc.src.math.roundl
#libc.src.math.sincosf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 2223504718444..b8292178a2335 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -266,6 +266,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintf
libc.src.math.rintl
libc.src.math.round
+ libc.src.math.roundevenf128
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbln
@@ -542,7 +543,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 12783aa4e5316..2a43d7cdc5f71 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -487,6 +487,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintl
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.round
libc.src.math.roundf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 5820448e06663..6172b6cb9968c 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -484,6 +484,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintl
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.round
libc.src.math.roundf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 071a7830b43d3..36bb375f7c7f9 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -698,6 +698,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -931,7 +932,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 1adbb04bb4cbe..39f58f6615346 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -517,6 +517,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintf
libc.src.math.rintl
libc.src.math.round
+ libc.src.math.roundevenf128
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbln
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 66dd9dd790737..b51cef0d6a9a8 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -771,6 +771,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -1021,7 +1022,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6045886c2f11c..08babba9f237d 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -776,6 +776,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.round
libc.src.math.roundeven
libc.src.math.roundevenf
+ libc.src.math.roundevenf128
libc.src.math.roundevenl
libc.src.math.roundf
libc.src.math.roundl
@@ -1026,7 +1027,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
libc.src.math.remainderf128
libc.src.math.remquof128
libc.src.math.rintf128
- libc.src.math.roundevenf128
libc.src.math.roundf128
libc.src.math.scalblnf128
libc.src.math.scalbnf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 142b83e71efe6..c47adc75a4e9a 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -299,6 +299,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.rintf
libc.src.math.rintl
libc.src.math.round
+ libc.src.math.roundevenf128
libc.src.math.roundf
libc.src.math.roundl
libc.src.math.scalbln
diff --git a/libc/shared/math/roundevenf128.h b/libc/shared/math/roundevenf128.h
index 10c2585db193d..f3b8513c86991 100644
--- a/libc/shared/math/roundevenf128.h
+++ b/libc/shared/math/roundevenf128.h
@@ -9,10 +9,6 @@
#ifndef LLVM_LIBC_SHARED_MATH_ROUNDEVENF128_H
#define LLVM_LIBC_SHARED_MATH_ROUNDEVENF128_H
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#include "shared/libc_common.h"
#include "src/__support/math/roundevenf128.h"
@@ -24,6 +20,4 @@ using math::roundevenf128;
} // namespace shared
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#endif // LLVM_LIBC_SHARED_MATH_ROUNDEVENF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index db514db61a9df..8d2f9de2d0d0b 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2506,7 +2506,7 @@ add_header_library(
HDRS
roundevenf128.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/roundevenf128.h b/libc/src/__support/math/roundevenf128.h
index e95df93290434..c2e39220fb4af 100644
--- a/libc/src/__support/math/roundevenf128.h
+++ b/libc/src/__support/math/roundevenf128.h
@@ -9,23 +9,20 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDEVENF128_H
#define LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDEVENF128_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 roundevenf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 roundevenf128(Float128 x) {
return fputil::round_using_specific_rounding_mode(x, FP_INT_TONEAREST);
}
} // namespace math
} // namespace LIBC_NAMESPACE_DECL
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_ROUNDEVENF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 80c2053066f16..2d414a55a0cc7 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -784,6 +784,7 @@ add_entrypoint_object(
HDRS
../roundevenf128.h
DEPENDS
+ libc.src.__support.CPP.bit
libc.src.__support.math.roundevenf128
)
diff --git a/libc/src/math/generic/roundevenf128.cpp b/libc/src/math/generic/roundevenf128.cpp
index 6b36c53d50756..3198eef1e61cc 100644
--- a/libc/src/math/generic/roundevenf128.cpp
+++ b/libc/src/math/generic/roundevenf128.cpp
@@ -7,12 +7,16 @@
//===----------------------------------------------------------------------===//
#include "src/math/roundevenf128.h"
+#include "src/__support/CPP/bit.h"
#include "src/__support/math/roundevenf128.h"
namespace LIBC_NAMESPACE_DECL {
+using LIBC_NAMESPACE::fputil::Float128;
+
LLVM_LIBC_FUNCTION(float128, roundevenf128, (float128 x)) {
- return math::roundevenf128(x);
+ return cpp::bit_cast<float128>(
+ math::roundevenf128(cpp::bit_cast<Float128>(x)));
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/roundevenf128.h b/libc/src/math/roundevenf128.h
index ca2ef3703e8ae..680ae2a0ea91c 100644
--- a/libc/src/math/roundevenf128.h
+++ b/libc/src/math/roundevenf128.h
@@ -9,11 +9,16 @@
#ifndef LLVM_LIBC_SRC_MATH_ROUNDEVENF128_H
#define LLVM_LIBC_SRC_MATH_ROUNDEVENF128_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 roundevenf128(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..5b971d5758a21 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -381,6 +381,7 @@ static_assert(0 == LIBC_NAMESPACE::shared::isnanl(0.0L));
//===----------------------------------------------------------------------===//
static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+ LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
//===----------------------------------------------------------------------===//
// Native Float128 Tests
@@ -510,7 +511,6 @@ static_assert(1 == [] {
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) ==
LIBC_NAMESPACE::shared::truncf128(float128(0.0)));
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 8850deda1c805..4d32370f0a6f7 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)));
+ LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
}
#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
@@ -754,7 +755,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
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..34a9d57b3328b 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -903,6 +903,7 @@ add_fp_unittest(
HDRS
RoundEvenTest.h
DEPENDS
+ libc.src.__support.FPUtil.float128
libc.src.math.roundevenf128
libc.src.__support.FPUtil.fp_bits
)
diff --git a/libc/test/src/math/smoke/roundevenf128_test.cpp b/libc/test/src/math/smoke/roundevenf128_test.cpp
index a1fdc40d577e7..190f091ed1eef 100644
--- a/libc/test/src/math/smoke/roundevenf128_test.cpp
+++ b/libc/test/src/math/smoke/roundevenf128_test.cpp
@@ -7,6 +7,11 @@
//===----------------------------------------------------------------------===//
#include "RoundEvenTest.h"
+#include "src/__support/FPUtil/float128.h"
#include "src/math/roundevenf128.h"
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
LIST_ROUNDEVEN_TESTS(float128, LIBC_NAMESPACE::roundevenf128)
>From 0921cc37593a54791bc101d35d270e472cf0e7d4 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 16 Aug 2026 18:34:15 +0530
Subject: [PATCH 2/2] nit
---
libc/test/shared/shared_math_constexpr_test.cpp | 1 +
libc/test/shared/shared_math_test.cpp | 1 +
2 files changed, 2 insertions(+)
diff --git a/libc/test/shared/shared_math_constexpr_test.cpp b/libc/test/shared/shared_math_constexpr_test.cpp
index 5b971d5758a21..b83ba2c44d27b 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -381,6 +381,7 @@ 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::roundevenf128(Float128(0.0)));
//===----------------------------------------------------------------------===//
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 4d32370f0a6f7..215a8ffedfa4b 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::roundevenf128(Float128(0.0)));
}
More information about the libc-commits
mailing list