[libc-commits] [libc] [libc] Make `lroundf128` and `llroundf128` use the emulated float128 type (PR #216829)

via libc-commits libc-commits at lists.llvm.org
Mon Aug 17 13:48:19 PDT 2026


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

>From a9889325767a3b7e8b16b4e2a9c145cb1b4adc33 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 18 Aug 2026 02:11:40 +0530
Subject: [PATCH 1/2] lroundf128

---
 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/lroundf128.h                   |  6 ------
 libc/src/__support/math/CMakeLists.txt          |  2 +-
 libc/src/__support/math/lroundf128.h            | 11 ++++-------
 libc/src/math/generic/CMakeLists.txt            |  1 +
 libc/src/math/generic/lroundf128.cpp            |  5 ++++-
 libc/src/math/lroundf128.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/lroundf128_test.cpp    |  5 +++++
 23 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 81958d224f70d..ec49625164505 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -509,6 +509,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -774,7 +775,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index ee3ec63132cc2..84c607b9189e5 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -521,6 +521,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -785,7 +786,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index c9f7c042bf4a8..62e685d335115 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -517,6 +517,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -782,7 +783,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 0ca00419a916c..96607c01f2637 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -328,6 +328,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -594,7 +595,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 136d5a458d484..9f3d397461fbd 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -180,6 +180,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.lrintl
     #libc.src.math.lround
     #libc.src.math.lroundf
+    #libc.src.math.lroundf128
     #libc.src.math.lroundl
     #libc.src.math.ldexp
     #libc.src.math.ldexpf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 2223504718444..5de0fd05b78ee 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -238,6 +238,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -532,7 +533,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 12783aa4e5316..82dce6ee91f24 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -452,6 +452,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 5820448e06663..6e69e20203034 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -449,6 +449,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 071a7830b43d3..3750f3d4cd76a 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -662,6 +662,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -921,7 +922,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 1adbb04bb4cbe..e79af4be87f3b 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -483,6 +483,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 66dd9dd790737..091df80a37206 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -735,6 +735,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -1011,7 +1012,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 6045886c2f11c..363bf1d6d6b64 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -740,6 +740,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
@@ -1016,7 +1017,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
-    libc.src.math.lroundf128
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nearbyintf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 142b83e71efe6..0803851d24973 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -271,6 +271,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.lrintl
     libc.src.math.lround
     libc.src.math.lroundf
+    libc.src.math.lroundf128
     libc.src.math.lroundl
     libc.src.math.modf
     libc.src.math.modff
diff --git a/libc/shared/math/lroundf128.h b/libc/shared/math/lroundf128.h
index ec035e4c26919..a5e445fb08a7b 100644
--- a/libc/shared/math/lroundf128.h
+++ b/libc/shared/math/lroundf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_LROUNDF128_H
 #define LLVM_LIBC_SHARED_MATH_LROUNDF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/lroundf128.h"
 
@@ -24,6 +20,4 @@ using math::lroundf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_LROUNDF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index db514db61a9df..afe546c21cccf 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -2062,7 +2062,7 @@ add_header_library(
   HDRS
     lroundf128.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/lroundf128.h b/libc/src/__support/math/lroundf128.h
index cd8fd70c25966..4422a6859a4bf 100644
--- a/libc/src/__support/math/lroundf128.h
+++ b/libc/src/__support/math/lroundf128.h
@@ -9,23 +9,20 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LROUNDF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LROUNDF128_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 long lroundf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr long lroundf128(Float128 x) {
   return fputil::round_to_signed_integer<float128, long>(x);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LROUNDF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 80c2053066f16..1c82c5e961a2e 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -865,6 +865,7 @@ add_entrypoint_object(
   HDRS
     ../lroundf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.lroundf128
 )
 
diff --git a/libc/src/math/generic/lroundf128.cpp b/libc/src/math/generic/lroundf128.cpp
index c6ea549d58253..dde3b78e0f0a6 100644
--- a/libc/src/math/generic/lroundf128.cpp
+++ b/libc/src/math/generic/lroundf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/lroundf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/lroundf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(long, lroundf128, (float128 x)) {
-  return math::lroundf128(x);
+  return math::lroundf128(cpp::bit_cast<Float128>(x));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/lroundf128.h b/libc/src/math/lroundf128.h
index 4191db5792095..cf6c62c4575da 100644
--- a/libc/src/math/lroundf128.h
+++ b/libc/src/math/lroundf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_LROUNDF128_H
 #define LLVM_LIBC_SRC_MATH_LROUNDF128_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
+
 long lroundf128(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..944e219fa38a3 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(0L == LIBC_NAMESPACE::shared::lroundf128(Float128(0.0)));
 
 //===----------------------------------------------------------------------===//
 //                       Native Float128 Tests
@@ -491,7 +492,6 @@ static_assert(0.0f ==
 static_assert(0LL == LIBC_NAMESPACE::shared::llrintf128(float128(0.0)));
 static_assert(0LL == LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
-static_assert(0L == LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::nearbyintf128(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..037798b1bce9d 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_EQ(0L, LIBC_NAMESPACE::shared::lroundf128(Float128(0.0)));
 }
 
 #ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
@@ -744,7 +745,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llrintf128(float128(0.0)));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
-  EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf128(float128(0.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
   EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::rintf128(float128(0.0)));
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 91d76f2c7973c..f2c1a4e78be53 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -993,6 +993,7 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
+    libc.src.__support.FPUtil.float128
     libc.src.errno.errno
     libc.src.math.lroundf128
     libc.src.__support.CPP.algorithm
diff --git a/libc/test/src/math/smoke/lroundf128_test.cpp b/libc/test/src/math/smoke/lroundf128_test.cpp
index ed87c9af04899..3637dad07655c 100644
--- a/libc/test/src/math/smoke/lroundf128_test.cpp
+++ b/libc/test/src/math/smoke/lroundf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "RoundToIntegerTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/lroundf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_ROUND_TO_INTEGER_TESTS(float128, long, LIBC_NAMESPACE::lroundf128)

>From eacd3131f7919d45d0e87be9abd5638783092629 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Tue, 18 Aug 2026 02:17:58 +0530
Subject: [PATCH 2/2] roundf128

---
 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/llroundf128.h                  |  6 ------
 libc/src/__support/math/CMakeLists.txt          |  2 +-
 libc/src/__support/math/llroundf128.h           | 11 ++++-------
 libc/src/math/generic/CMakeLists.txt            |  1 +
 libc/src/math/generic/llroundf128.cpp           |  5 ++++-
 libc/src/math/llroundf128.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/llroundf128_test.cpp   |  5 +++++
 23 files changed, 36 insertions(+), 25 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index ec49625164505..bd15a3cb2517d 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -492,6 +492,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -772,7 +773,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 84c607b9189e5..486420f16eef7 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -504,6 +504,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -783,7 +784,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 62e685d335115..cac0087b6a078 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -500,6 +500,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -780,7 +781,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 96607c01f2637..8c967c93150fa 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -311,6 +311,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -592,7 +593,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 9f3d397461fbd..02e9afdff312d 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -174,6 +174,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.llrintl
     #libc.src.math.llround
     #libc.src.math.llroundf
+    #libc.src.math.llroundf128
     #libc.src.math.llroundl
     #libc.src.math.lrint
     #libc.src.math.lrintf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 5de0fd05b78ee..5f677039cf041 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -221,6 +221,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log10
     libc.src.math.log10f
@@ -530,7 +531,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 82dce6ee91f24..63114aafff2b3 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -435,6 +435,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 6e69e20203034..5c941499a51d5 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -432,6 +432,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 3750f3d4cd76a..11e2200bdf32c 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -645,6 +645,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -919,7 +920,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index e79af4be87f3b..188493b7e5520 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -466,6 +466,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 091df80a37206..03d4cfec33ab5 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -718,6 +718,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -1009,7 +1010,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 363bf1d6d6b64..d59ad87a7302d 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -723,6 +723,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log
     libc.src.math.log10
@@ -1014,7 +1015,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.ldexpf128
     libc.src.math.llogbf128
     libc.src.math.llrintf128
-    libc.src.math.llroundf128
     libc.src.math.logbf128
     libc.src.math.lrintf128
     libc.src.math.modff128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 0803851d24973..5787c98b078f1 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -254,6 +254,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.llrintl
     libc.src.math.llround
     libc.src.math.llroundf
+    libc.src.math.llroundf128
     libc.src.math.llroundl
     libc.src.math.log10
     libc.src.math.log10f
diff --git a/libc/shared/math/llroundf128.h b/libc/shared/math/llroundf128.h
index 4ca4826a5acf8..20af856951e37 100644
--- a/libc/shared/math/llroundf128.h
+++ b/libc/shared/math/llroundf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_LLROUNDF128_H
 #define LLVM_LIBC_SHARED_MATH_LLROUNDF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/llroundf128.h"
 
@@ -24,6 +20,4 @@ using math::llroundf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_LLROUNDF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index afe546c21cccf..7878bb3f88809 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1948,7 +1948,7 @@ add_header_library(
   HDRS
     llroundf128.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/llroundf128.h b/libc/src/__support/math/llroundf128.h
index b5db14ed9bc0e..932692d8141b8 100644
--- a/libc/src/__support/math/llroundf128.h
+++ b/libc/src/__support/math/llroundf128.h
@@ -9,23 +9,20 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LLROUNDF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LLROUNDF128_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 long long llroundf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr long long llroundf128(Float128 x) {
   return fputil::round_to_signed_integer<float128, long long>(x);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_LLROUNDF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 1c82c5e961a2e..d411c0e8f75a6 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -926,6 +926,7 @@ add_entrypoint_object(
   HDRS
     ../llroundf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.llroundf128
 )
 
diff --git a/libc/src/math/generic/llroundf128.cpp b/libc/src/math/generic/llroundf128.cpp
index 4ef2eb0032370..8f0a31b59ae49 100644
--- a/libc/src/math/generic/llroundf128.cpp
+++ b/libc/src/math/generic/llroundf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/llroundf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/llroundf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(long long, llroundf128, (float128 x)) {
-  return math::llroundf128(x);
+  return math::llroundf128(cpp::bit_cast<Float128>(x));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/llroundf128.h b/libc/src/math/llroundf128.h
index 59d4d8da582ed..d81d5bd8ab1a5 100644
--- a/libc/src/math/llroundf128.h
+++ b/libc/src/math/llroundf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_LLROUNDF128_H
 #define LLVM_LIBC_SRC_MATH_LLROUNDF128_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
+
 long long llroundf128(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 944e219fa38a3..abe5ea0135b95 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(0LL == LIBC_NAMESPACE::shared::llroundf128(Float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lroundf128(Float128(0.0)));
 
 //===----------------------------------------------------------------------===//
@@ -490,7 +491,6 @@ static_assert(0.0f ==
               LIBC_NAMESPACE::shared::fsubf128(float128(0.0), float128(0.0)));
 
 static_assert(0LL == LIBC_NAMESPACE::shared::llrintf128(float128(0.0)));
-static_assert(0LL == LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
 static_assert(0L == LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
 static_assert(float128(0.0) ==
               LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 037798b1bce9d..9f8d17f76baac 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_EQ(0LL, LIBC_NAMESPACE::shared::llroundf128(Float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lroundf128(Float128(0.0)));
 }
 
@@ -743,7 +744,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(0x0p+0f,
                LIBC_NAMESPACE::shared::fmulf128(float128(0.0), float128(0.0)));
   EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llrintf128(float128(0.0)));
-  EXPECT_EQ(0LL, LIBC_NAMESPACE::shared::llroundf128(float128(0.0)));
   EXPECT_EQ(0L, LIBC_NAMESPACE::shared::lrintf128(float128(0.0)));
   EXPECT_FP_EQ(float128(0.0),
                LIBC_NAMESPACE::shared::nearbyintf128(float128(0.0)));
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index f2c1a4e78be53..27686f1970cbd 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1091,6 +1091,7 @@ add_fp_unittest(
   HDRS
     RoundToIntegerTest.h
   DEPENDS
+    libc.src.__support.FPUtil.float128
     libc.src.errno.errno
     libc.src.math.llroundf128
     libc.src.__support.CPP.algorithm
diff --git a/libc/test/src/math/smoke/llroundf128_test.cpp b/libc/test/src/math/smoke/llroundf128_test.cpp
index b00055e759f85..1503c4c8c5e43 100644
--- a/libc/test/src/math/smoke/llroundf128_test.cpp
+++ b/libc/test/src/math/smoke/llroundf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "RoundToIntegerTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/llroundf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_ROUND_TO_INTEGER_TESTS(float128, long long, LIBC_NAMESPACE::llroundf128)



More information about the libc-commits mailing list