[llvm-branch-commits] [libc] [llvm] [libc] Make next-type functions use the emulated float128 type (PR #217575)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Aug 21 05:28:22 PDT 2026


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

>From 1ec5dab595d383262bf31914273f1ae44a6af623 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 20 Aug 2026 15:35:12 +0530
Subject: [PATCH 1/6] nextafterf128

---
 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/nextafterf128.h                      |  6 ------
 libc/src/__support/math/CMakeLists.txt                |  2 +-
 libc/src/__support/math/nextafterf128.h               | 11 ++++-------
 libc/src/math/generic/CMakeLists.txt                  |  1 +
 libc/src/math/generic/nextafterf128.cpp               |  5 ++++-
 libc/src/math/nextafterf128.h                         |  5 +++++
 libc/test/shared/shared_math_constexpr_test.cpp       |  4 +---
 libc/test/shared/shared_math_test.cpp                 |  3 +--
 libc/test/src/math/CMakeLists.txt                     |  1 +
 libc/test/src/math/nextafterf128_test.cpp             |  5 +++++
 libc/test/src/math/smoke/CMakeLists.txt               |  1 +
 libc/test/src/math/smoke/nextafterf128_test.cpp       |  5 +++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel     |  4 +++-
 .../libc/test/src/math/smoke/BUILD.bazel              |  3 +++
 27 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index f7357b5194420..db37b4d1134f9 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -544,6 +544,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -783,7 +784,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 302324ec9f913..376d326d379c3 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -556,6 +556,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -794,7 +795,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index d5866be41ba09..fc6349ffb8eb0 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -552,6 +552,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -791,7 +792,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index b2b37f7ae6e96..65c2bbd84f027 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -363,6 +363,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -603,7 +604,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 716ab572f8d3c..6222668ad851e 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -225,6 +225,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.nearbyintl
     #libc.src.math.nextafter
     #libc.src.math.nextafterf
+    #libc.src.math.nextafterf128
     #libc.src.math.nextafterl
     #libc.src.math.nexttoward
     #libc.src.math.nexttowardf
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 80e08959bfb0c..03da4d62fb7e2 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -273,6 +273,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -542,7 +543,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 8189076a8f194..e4b6b4ebd7761 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.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index b4b106a306999..881c32c35cc0c 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.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 9310a59323271..2e746369108b3 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -704,6 +704,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -937,7 +938,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index a8614f87f02d3..fae384644e253 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.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ef9fe8e89a155..2f68c4193de46 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -772,6 +772,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -1022,7 +1023,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 8313063f60ca5..78caf8d592f83 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -782,6 +782,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
@@ -1032,7 +1033,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextafterf128
     libc.src.math.nextdownf128
     libc.src.math.nextupf128
     libc.src.math.remainderf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index a21f465bd6d2f..615fac15aac22 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -306,6 +306,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nearbyintl
     libc.src.math.nextafter
     libc.src.math.nextafterf
+    libc.src.math.nextafterf128
     libc.src.math.nextafterl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
diff --git a/libc/shared/math/nextafterf128.h b/libc/shared/math/nextafterf128.h
index 95bece2ba874a..6ff2087983a9f 100644
--- a/libc/shared/math/nextafterf128.h
+++ b/libc/shared/math/nextafterf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
 #define LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/nextafterf128.h"
 
@@ -24,6 +20,4 @@ using math::nextafterf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 71692b26a35dc..be5528c764c6a 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4433,7 +4433,7 @@ add_header_library(
   HDRS
     nextafterf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
     libc.src.__support.macros.config
 )
diff --git a/libc/src/__support/math/nextafterf128.h b/libc/src/__support/math/nextafterf128.h
index d9c07b4d6b68f..ac4f6d0325e49 100644
--- a/libc/src/__support/math/nextafterf128.h
+++ b/libc/src/__support/math/nextafterf128.h
@@ -9,24 +9,21 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr float128 nextafterf128(float128 x, float128 y) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 nextafterf128(Float128 x, Float128 y) {
   return fputil::nextafter(x, y);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d35a8985c533a..d8b634b06f1b4 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3229,6 +3229,7 @@ add_entrypoint_object(
   HDRS
     ../nextafterf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.nextafterf128
 )
 
diff --git a/libc/src/math/generic/nextafterf128.cpp b/libc/src/math/generic/nextafterf128.cpp
index 3363db898fe0b..cdaf8a43e2c0f 100644
--- a/libc/src/math/generic/nextafterf128.cpp
+++ b/libc/src/math/generic/nextafterf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextafterf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/nextafterf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, nextafterf128, (float128 x, float128 y)) {
-  return math::nextafterf128(x, y);
+  return cpp::bit_cast<float128>(math::nextafterf128(cpp::bit_cast<Float128>(x), cpp::bit_cast<Float128>(y)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nextafterf128.h b/libc/src/math/nextafterf128.h
index 99b15d6cf43b9..679ea23225faa 100644
--- a/libc/src/math/nextafterf128.h
+++ b/libc/src/math/nextafterf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_NEXTAFTERF128_H
 #define LLVM_LIBC_SRC_MATH_NEXTAFTERF128_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 nextafterf128(float128 x, float128 y);
 
 } // 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 64b8f6edadf52..cdd247b0d2f39 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::nextafterf128(Float128(0.0), Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::copysignf128(Float128(0.0),
                                                    Float128(0.0)));
@@ -502,9 +503,6 @@ static_assert(0.0f ==
               LIBC_NAMESPACE::shared::fmulf128(float128(0.0), float128(0.0)));
 static_assert(0.0f ==
               LIBC_NAMESPACE::shared::fsubf128(float128(0.0), float128(0.0)));
-static_assert(float128(0.0) ==
-              LIBC_NAMESPACE::shared::nextafterf128(float128(0.0),
-                                                    float128(0.0)));
 static_assert(1 == [] {
   const char arg{};
   return LIBC_NAMESPACE::fputil::FPBits<float128>(
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index b197fd4cecfba..03029eed03705 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -584,6 +584,7 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::atan2f128(Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128( Float128(0.0), 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), LIBC_NAMESPACE::shared::fabsf128(Float128(0.0)));
@@ -700,8 +701,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
   float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
-  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128(
-                                  float128(0.0), float128(0.0)));
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
   EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 90c29922d5a35..dfc203ebef664 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2046,6 +2046,7 @@ add_fp_unittest(
   HDRS
     NextAfterTest.h
   DEPENDS
+    libc.src.__support.FPUtil.float128
     libc.src.math.nextafterf128
     libc.src.__support.FPUtil.basic_operations
     libc.src.__support.FPUtil.fp_bits
diff --git a/libc/test/src/math/nextafterf128_test.cpp b/libc/test/src/math/nextafterf128_test.cpp
index a8d000ff4de38..9ee60ef21cffe 100644
--- a/libc/test/src/math/nextafterf128_test.cpp
+++ b/libc/test/src/math/nextafterf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextAfterTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/nextafterf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_NEXTAFTER_TESTS(float128, LIBC_NAMESPACE::nextafterf128)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 4f54d46991304..ebb79527d7000 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4085,6 +4085,7 @@ add_fp_unittest(
     NextAfterTest.h
   DEPENDS
     libc.hdr.fenv_macros
+    libc.src.__support.FPUtil.float128
     libc.src.math.nextafterf128
     libc.src.__support.CPP.bit
     libc.src.__support.FPUtil.fenv_impl
diff --git a/libc/test/src/math/smoke/nextafterf128_test.cpp b/libc/test/src/math/smoke/nextafterf128_test.cpp
index a8d000ff4de38..9ee60ef21cffe 100644
--- a/libc/test/src/math/smoke/nextafterf128_test.cpp
+++ b/libc/test/src/math/smoke/nextafterf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextAfterTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/nextafterf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_NEXTAFTER_TESTS(float128, LIBC_NAMESPACE::nextafterf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a5819b9a27a84..48f90fc8d585d 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -8413,9 +8413,9 @@ libc_support_library(
     name = "__support_math_nextafterf128",
     hdrs = ["src/__support/math/nextafterf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -13000,6 +13000,8 @@ libc_math_function(
 libc_math_function(
     name = "nextafterf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_nextafterf128",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 1ea19f953e0ad..db2b87b017bc9 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1304,6 +1304,9 @@ math_test(
     name = "nextafterf128",
     hdrs = ["NextAfterTest.h"],
     deps = ["//libc:__support_sign"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 7f8ab92e1b85543f8f8ad3fd7e57d3b736190a7a Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 20 Aug 2026 15:36:00 +0530
Subject: [PATCH 2/6] nextupf128

---
 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/nextupf128.h                         |  6 ------
 libc/src/__support/math/CMakeLists.txt                |  2 +-
 libc/src/__support/math/nextupf128.h                  | 11 ++++-------
 libc/src/math/generic/CMakeLists.txt                  |  1 +
 libc/src/math/generic/nextafterf128.cpp               |  3 ++-
 libc/src/math/generic/nextupf128.cpp                  |  5 ++++-
 libc/src/math/nextupf128.h                            |  5 +++++
 libc/test/shared/shared_math_constexpr_test.cpp       |  4 +++-
 libc/test/shared/shared_math_test.cpp                 |  5 +++--
 libc/test/src/math/smoke/CMakeLists.txt               |  1 +
 libc/test/src/math/smoke/nextupf128_test.cpp          |  5 +++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel     |  4 +++-
 .../libc/test/src/math/smoke/BUILD.bazel              |  3 +++
 26 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index db37b4d1134f9..0f0f2b9d17244 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -554,6 +554,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -785,7 +786,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 376d326d379c3..dc1e8bfbf4c51 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -566,6 +566,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -796,7 +797,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index fc6349ffb8eb0..116431146da1a 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -562,6 +562,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -793,7 +794,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index 65c2bbd84f027..ce63cae62cb61 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -373,6 +373,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -605,7 +606,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 6222668ad851e..4291bee1b210e 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -230,6 +230,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.nexttoward
     #libc.src.math.nexttowardf
     #libc.src.math.nexttowardl
+    #libc.src.math.nextupf128
     #libc.src.math.remainderf
     #libc.src.math.remainder
     #libc.src.math.remainderl
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 03da4d62fb7e2..58dee699390e3 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -278,6 +278,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
     libc.src.math.nexttowardl
+    libc.src.math.nextupf128
     libc.src.math.pow
     libc.src.math.powf
     libc.src.math.remainderf
@@ -544,7 +545,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index e4b6b4ebd7761..0d43e49a92e12 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -497,6 +497,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 881c32c35cc0c..199fa1121bdb7 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -494,6 +494,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 2e746369108b3..50c7dac817369 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -714,6 +714,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -939,7 +940,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index fae384644e253..7c456bdf473d3 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -528,6 +528,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 2f68c4193de46..dd08bf3f04f2d 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -782,6 +782,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -1024,7 +1025,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 78caf8d592f83..64abaaa1de878 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -792,6 +792,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttowardl
     libc.src.math.nextup
     libc.src.math.nextupf
+    libc.src.math.nextupf128
     libc.src.math.nextupl
     libc.src.math.pow
     libc.src.math.powf
@@ -1034,7 +1035,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.modff128
     libc.src.math.nanf128
     libc.src.math.nextdownf128
-    libc.src.math.nextupf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index 615fac15aac22..aa825992ff6ea 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -311,6 +311,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
     libc.src.math.nexttowardl
+    libc.src.math.nextupf128
     libc.src.math.pow
     libc.src.math.powf
     libc.src.math.remainderf
diff --git a/libc/shared/math/nextupf128.h b/libc/shared/math/nextupf128.h
index 4d8312efa9311..6da0606a3cbe6 100644
--- a/libc/shared/math/nextupf128.h
+++ b/libc/shared/math/nextupf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_NEXTUPF128_H
 #define LLVM_LIBC_SHARED_MATH_NEXTUPF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/nextupf128.h"
 
@@ -24,6 +20,4 @@ using math::nextupf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_NEXTUPF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index be5528c764c6a..d2348b1746217 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4537,7 +4537,7 @@ add_header_library(
   HDRS
     nextupf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
     libc.src.__support.macros.config
 )
diff --git a/libc/src/__support/math/nextupf128.h b/libc/src/__support/math/nextupf128.h
index 2b618e4095968..42f0d6444a2c5 100644
--- a/libc/src/__support/math/nextupf128.h
+++ b/libc/src/__support/math/nextupf128.h
@@ -9,24 +9,21 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr float128 nextupf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 nextupf128(Float128 x) {
   return fputil::nextupdown</*IsDown=*/false>(x);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d8b634b06f1b4..22a2b582e5542 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3400,6 +3400,7 @@ add_entrypoint_object(
   HDRS
     ../nextupf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.nextupf128
 )
 
diff --git a/libc/src/math/generic/nextafterf128.cpp b/libc/src/math/generic/nextafterf128.cpp
index cdaf8a43e2c0f..5e0f862fb5c4d 100644
--- a/libc/src/math/generic/nextafterf128.cpp
+++ b/libc/src/math/generic/nextafterf128.cpp
@@ -15,7 +15,8 @@ namespace LIBC_NAMESPACE_DECL {
 using LIBC_NAMESPACE::fputil::Float128;
 
 LLVM_LIBC_FUNCTION(float128, nextafterf128, (float128 x, float128 y)) {
-  return cpp::bit_cast<float128>(math::nextafterf128(cpp::bit_cast<Float128>(x), cpp::bit_cast<Float128>(y)));
+  return cpp::bit_cast<float128>(math::nextafterf128(
+      cpp::bit_cast<Float128>(x), cpp::bit_cast<Float128>(y)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupf128.cpp b/libc/src/math/generic/nextupf128.cpp
index 71a7b20b86741..f5e8e98870a65 100644
--- a/libc/src/math/generic/nextupf128.cpp
+++ b/libc/src/math/generic/nextupf128.cpp
@@ -7,12 +7,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/nextupf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, nextupf128, (float128 x)) {
-  return math::nextupf128(x);
+  return cpp::bit_cast<float128>(math::nextupf128(cpp::bit_cast<Float128>(x)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nextupf128.h b/libc/src/math/nextupf128.h
index 755c08d891d64..8e911b5aa6fad 100644
--- a/libc/src/math/nextupf128.h
+++ b/libc/src/math/nextupf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_NEXTUPF128_H
 #define LLVM_LIBC_SRC_MATH_NEXTUPF128_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 nextupf128(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 cdd247b0d2f39..a4001cdc365d0 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -381,7 +381,9 @@ 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::nextafterf128(Float128(0.0), Float128(0.0)));
+static_assert(float128(0.0) ==
+              LIBC_NAMESPACE::shared::nextafterf128(Float128(0.0),
+                                                    Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::copysignf128(Float128(0.0),
                                                    Float128(0.0)));
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 03029eed03705..e97e1a3c62918 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -584,7 +584,9 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::atan2f128(Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
-  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128( Float128(0.0), Float128(0.0)));
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(Float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128(
+                                  Float128(0.0), 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), LIBC_NAMESPACE::shared::fabsf128(Float128(0.0)));
@@ -700,7 +702,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
   float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
-  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
   EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ebb79527d7000..90355f3755100 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4323,6 +4323,7 @@ add_fp_unittest(
   HDRS
     NextUpTest.h
   DEPENDS
+    libc.src.__support.FPUtil.float128
     libc.src.math.nextupf128
 )
 
diff --git a/libc/test/src/math/smoke/nextupf128_test.cpp b/libc/test/src/math/smoke/nextupf128_test.cpp
index ddd385a7b159b..96cc6932ccea8 100644
--- a/libc/test/src/math/smoke/nextupf128_test.cpp
+++ b/libc/test/src/math/smoke/nextupf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextUpTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/nextupf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_NEXTUP_TESTS(float128, LIBC_NAMESPACE::nextupf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 48f90fc8d585d..351e77778c1b3 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -8575,9 +8575,9 @@ libc_support_library(
     name = "__support_math_nextupf128",
     hdrs = ["src/__support/math/nextupf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -13114,6 +13114,8 @@ libc_math_function(
 libc_math_function(
     name = "nextupf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_nextupf128",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index db2b87b017bc9..abbb48380b528 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1378,6 +1378,9 @@ math_test(
 math_test(
     name = "nextupf128",
     hdrs = ["NextUpTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 419839d301c9d63a90dadc9772804a2a3f3b93d0 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Thu, 20 Aug 2026 15:40:46 +0530
Subject: [PATCH 3/6] nextdownf128

---
 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/nextdownf128.h                     |  6 ------
 libc/src/__support/math/CMakeLists.txt              |  2 +-
 libc/src/__support/math/nextdownf128.h              | 11 ++++-------
 libc/src/math/generic/CMakeLists.txt                |  1 +
 libc/src/math/generic/nextdownf128.cpp              |  6 +++++-
 libc/src/math/nextdownf128.h                        |  5 +++++
 libc/test/shared/shared_math_constexpr_test.cpp     |  6 +++---
 libc/test/shared/shared_math_test.cpp               | 13 ++++++++-----
 libc/test/src/math/smoke/CMakeLists.txt             |  1 +
 libc/test/src/math/smoke/nextdownf128_test.cpp      |  5 +++++
 utils/bazel/llvm-project-overlay/libc/BUILD.bazel   |  4 +++-
 .../libc/test/src/math/smoke/BUILD.bazel            |  3 +++
 25 files changed, 52 insertions(+), 32 deletions(-)

diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index 0f0f2b9d17244..48e172ed070c0 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -548,6 +548,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -785,7 +786,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index dc1e8bfbf4c51..0c53b651f16d0 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -560,6 +560,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -796,7 +797,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 116431146da1a..4c6c65b5b0814 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -556,6 +556,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -793,7 +794,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/darwin/aarch64/entrypoints.txt b/libc/config/darwin/aarch64/entrypoints.txt
index ce63cae62cb61..21c5093629f18 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -367,6 +367,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -605,7 +606,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/darwin/x86_64/entrypoints.txt b/libc/config/darwin/x86_64/entrypoints.txt
index 4291bee1b210e..3e38ac38b3791 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -227,6 +227,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     #libc.src.math.nextafterf
     #libc.src.math.nextafterf128
     #libc.src.math.nextafterl
+    #libc.src.math.nextdownf128
     #libc.src.math.nexttoward
     #libc.src.math.nexttowardf
     #libc.src.math.nexttowardl
diff --git a/libc/config/freebsd/x86_64/entrypoints.txt b/libc/config/freebsd/x86_64/entrypoints.txt
index 58dee699390e3..c073755071baa 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -275,6 +275,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterf
     libc.src.math.nextafterf128
     libc.src.math.nextafterl
+    libc.src.math.nextdownf128
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
     libc.src.math.nexttowardl
@@ -544,7 +545,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/gpu/amdgpu/entrypoints.txt b/libc/config/gpu/amdgpu/entrypoints.txt
index 0d43e49a92e12..c2d0ba31fe7ba 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/entrypoints.txt
@@ -491,6 +491,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
diff --git a/libc/config/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 199fa1121bdb7..66e4333fe0836 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -488,6 +488,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 50c7dac817369..08ca2b49b93c1 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -708,6 +708,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -939,7 +940,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 7c456bdf473d3..7a6cbac1ceaa9 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -522,6 +522,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index dd08bf3f04f2d..a78569c93ac63 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -776,6 +776,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -1024,7 +1025,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 64abaaa1de878..bee8c7ebc8709 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -786,6 +786,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterl
     libc.src.math.nextdown
     libc.src.math.nextdownf
+    libc.src.math.nextdownf128
     libc.src.math.nextdownl
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
@@ -1034,7 +1035,6 @@ if(LIBC_TYPES_HAS_NATIVE_FLOAT128)
     libc.src.math.logbf128
     libc.src.math.modff128
     libc.src.math.nanf128
-    libc.src.math.nextdownf128
     libc.src.math.remainderf128
     libc.src.math.remquof128
     libc.src.math.scalblnf128
diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt
index aa825992ff6ea..7f2081bfb2419 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -308,6 +308,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.nextafterf
     libc.src.math.nextafterf128
     libc.src.math.nextafterl
+    libc.src.math.nextdownf128
     libc.src.math.nexttoward
     libc.src.math.nexttowardf
     libc.src.math.nexttowardl
diff --git a/libc/shared/math/nextdownf128.h b/libc/shared/math/nextdownf128.h
index 958d1f2cc5297..902a101dfb19d 100644
--- a/libc/shared/math/nextdownf128.h
+++ b/libc/shared/math/nextdownf128.h
@@ -9,10 +9,6 @@
 #ifndef LLVM_LIBC_SHARED_MATH_NEXTDOWNF128_H
 #define LLVM_LIBC_SHARED_MATH_NEXTDOWNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "shared/libc_common.h"
 #include "src/__support/math/nextdownf128.h"
 
@@ -24,6 +20,4 @@ using math::nextdownf128;
 } // namespace shared
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SHARED_MATH_NEXTDOWNF128_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index d2348b1746217..6ce4662da7c6d 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -4595,7 +4595,7 @@ add_header_library(
   HDRS
     nextdownf128.h
   DEPENDS
-    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.manipulation_functions
     libc.src.__support.macros.config
 )
diff --git a/libc/src/__support/math/nextdownf128.h b/libc/src/__support/math/nextdownf128.h
index b3a93c3909058..13fb2421935f4 100644
--- a/libc/src/__support/math/nextdownf128.h
+++ b/libc/src/__support/math/nextdownf128.h
@@ -9,24 +9,21 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTDOWNF128_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTDOWNF128_H
 
-#include "include/llvm-libc-types/float128.h"
-
-#ifdef LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/float128.h"
 #include "src/__support/macros/config.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 namespace math {
 
-LIBC_INLINE constexpr float128 nextdownf128(float128 x) {
+using LIBC_NAMESPACE::fputil::Float128;
+
+LIBC_INLINE constexpr Float128 nextdownf128(Float128 x) {
   return fputil::nextupdown</*IsDown=*/true>(x);
 }
 
 } // namespace math
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
-
 #endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTDOWNF128_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 22a2b582e5542..59ab7ee7b27d7 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3340,6 +3340,7 @@ add_entrypoint_object(
   HDRS
     ../nextdownf128.h
   DEPENDS
+    libc.src.__support.CPP.bit
     libc.src.__support.math.nextdownf128
 )
 
diff --git a/libc/src/math/generic/nextdownf128.cpp b/libc/src/math/generic/nextdownf128.cpp
index 3a9a60fe7130a..087bdb984677e 100644
--- a/libc/src/math/generic/nextdownf128.cpp
+++ b/libc/src/math/generic/nextdownf128.cpp
@@ -7,12 +7,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextdownf128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/math/nextdownf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
+using LIBC_NAMESPACE::fputil::Float128;
+
 LLVM_LIBC_FUNCTION(float128, nextdownf128, (float128 x)) {
-  return math::nextdownf128(x);
+  return cpp::bit_cast<float128>(
+      math::nextdownf128(cpp::bit_cast<Float128>(x)));
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/nextdownf128.h b/libc/src/math/nextdownf128.h
index 60ba251f67d55..3f9099f084e34 100644
--- a/libc/src/math/nextdownf128.h
+++ b/libc/src/math/nextdownf128.h
@@ -9,11 +9,16 @@
 #ifndef LLVM_LIBC_SRC_MATH_NEXTDOWNF128_H
 #define LLVM_LIBC_SRC_MATH_NEXTDOWNF128_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 nextdownf128(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 a4001cdc365d0..af5396b5ee19e 100644
--- a/libc/test/shared/shared_math_constexpr_test.cpp
+++ b/libc/test/shared/shared_math_constexpr_test.cpp
@@ -381,9 +381,6 @@ 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::nextafterf128(Float128(0.0),
-                                                    Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::copysignf128(Float128(0.0),
                                                    Float128(0.0)));
@@ -433,6 +430,9 @@ static_assert(Float128(0.0) ==
 static_assert(Float128(0.0) == LIBC_NAMESPACE::shared::rintf128(Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
+static_assert(Float128(0.0) ==
+              LIBC_NAMESPACE::shared::nextafterf128(Float128(0.0),
+                                                    Float128(0.0)));
 static_assert(Float128(0.0) ==
               LIBC_NAMESPACE::shared::roundf128(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 e97e1a3c62918..07802e0e30f60 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -581,12 +581,12 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
 
 // Emulated float128 tests
 TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
+  using FPBits = LIBC_NAMESPACE::fputil::FPBits<Float128>;
+  Float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
+  Float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::atan2f128(Float128(0.0), Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::ceilf128(Float128(0.0)));
-  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(Float128(0.0)));
-  EXPECT_FP_EQ(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128(
-                                  Float128(0.0), 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), LIBC_NAMESPACE::shared::fabsf128(Float128(0.0)));
@@ -622,6 +622,11 @@ TEST(LlvmLibcSharedMathTest, AllEmuFloat128) {
   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::nextafterf128(
+                                  Float128(0.0), Float128(0.0)));
+  EXPECT_FP_EQ(neg_min_denormal,
+               LIBC_NAMESPACE::shared::nextdownf128(Float128(0.0)));
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0), LIBC_NAMESPACE::shared::rintf128(Float128(0.0)));
   EXPECT_FP_EQ(Float128(0.0),
                LIBC_NAMESPACE::shared::roundevenf128(Float128(0.0)));
@@ -699,8 +704,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_FP_EQ(float128(0.0), setpayloadsigf128_res);
 
   float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
-  EXPECT_FP_EQ(neg_min_denormal,
-               LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
   float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 90355f3755100..ea5523c9118e8 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4250,6 +4250,7 @@ add_fp_unittest(
   HDRS
     NextDownTest.h
   DEPENDS
+    libc.src.__support.FPUtil.float128
     libc.src.math.nextdownf128
 )
 
diff --git a/libc/test/src/math/smoke/nextdownf128_test.cpp b/libc/test/src/math/smoke/nextdownf128_test.cpp
index 932a8b36a59e4..603b31a9f05cc 100644
--- a/libc/test/src/math/smoke/nextdownf128_test.cpp
+++ b/libc/test/src/math/smoke/nextdownf128_test.cpp
@@ -7,7 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextDownTest.h"
+#include "src/__support/FPUtil/float128.h"
 
 #include "src/math/nextdownf128.h"
 
+#ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+#endif // LIBC_TYPES_HAS_NATIVE_FLOAT128
+
 LIST_NEXTDOWN_TESTS(float128, LIBC_NAMESPACE::nextdownf128)
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 351e77778c1b3..7863e382e32d0 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -8470,10 +8470,10 @@ libc_support_library(
     name = "__support_math_nextdownf128",
     hdrs = ["src/__support/math/nextdownf128.h"],
     deps = [
+        ":__support_fputil_float128",
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
         ":__support_macros_properties_types",
-        ":llvm_libc_types_float128",
     ],
 )
 
@@ -13044,6 +13044,8 @@ libc_math_function(
 libc_math_function(
     name = "nextdownf128",
     additional_deps = [
+        ":__support_cpp_bit",
+        ":__support_fputil_float128",
         ":__support_math_nextdownf128",
     ],
 )
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index abbb48380b528..8c47fb7858e49 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
@@ -1333,6 +1333,9 @@ math_test(
 math_test(
     name = "nextdownf128",
     hdrs = ["NextDownTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 128e5e7cc6a5ec4908d26abf43fc0af4dc91b0fb Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 21 Aug 2026 16:58:09 +0530
Subject: [PATCH 4/6] cast

---
 libc/test/src/math/NextAfterTest.h | 36 +++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h
index 82d5378ec3533..01c6ce496aadd 100644
--- a/libc/test/src/math/NextAfterTest.h
+++ b/libc/test/src/math/NextAfterTest.h
@@ -40,8 +40,8 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   typedef T (*NextAfterFunc)(T, T);
 
   void testNaN(NextAfterFunc func) {
-    ASSERT_FP_EQ(func(nan, 0), nan);
-    ASSERT_FP_EQ(func(0, nan), nan);
+    ASSERT_FP_EQ(func(nan, zero), nan);
+    ASSERT_FP_EQ(func(zero, nan), nan);
   }
 
   void testBoundaries(NextAfterFunc func) {
@@ -61,57 +61,57 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     ASSERT_FP_EQ(result, expected);
 
     x = neg_zero;
-    result = func(x, 1);
+    result = func(x, T(1));
     expected_bits = 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
-    result = func(x, -1);
+    result = func(x, T(-1));
     expected_bits = FPBits::SIGN_MASK + 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     // 'from' is max subnormal value.
     x = LIBC_NAMESPACE::cpp::bit_cast<T>(max_subnormal);
-    result = func(x, 1);
+    result = func(x, T(1));
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(min_normal);
     ASSERT_FP_EQ(result, expected);
 
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = max_subnormal - 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     x = -x;
 
-    result = func(x, -1);
+    result = func(x, T(-1));
     expected_bits = FPBits::SIGN_MASK + min_normal;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = FPBits::SIGN_MASK + max_subnormal - 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     // 'from' is min subnormal value.
     x = LIBC_NAMESPACE::cpp::bit_cast<T>(min_subnormal);
-    result = func(x, 1);
+    result = func(x, T(1));
     expected_bits = min_subnormal + 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
-    ASSERT_FP_EQ(func(x, 0), zero);
+    ASSERT_FP_EQ(func(x, zero), zero);
 
     x = -x;
-    result = func(x, -1);
+    result = func(x, T(-1));
     expected_bits = FPBits::SIGN_MASK + min_subnormal + 1;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
-    ASSERT_FP_EQ(func(x, 0), T(-0.0));
+    ASSERT_FP_EQ(func(x, zero), T(-0.0));
 
     // 'from' is min normal.
     x = LIBC_NAMESPACE::cpp::bit_cast<T>(min_normal);
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = max_subnormal;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
@@ -122,7 +122,7 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
     ASSERT_FP_EQ(result, expected);
 
     x = -x;
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = FPBits::SIGN_MASK + max_subnormal;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
@@ -142,14 +142,14 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
     // 'from' is infinity.
     x = inf;
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = max_normal;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
     ASSERT_FP_EQ(func(x, inf), inf);
 
     x = neg_inf;
-    result = func(x, 0);
+    result = func(x, zero);
     expected_bits = FPBits::SIGN_MASK + max_normal;
     expected = LIBC_NAMESPACE::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
@@ -157,7 +157,7 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
     // 'from' is a power of 2.
     x = T(32.0);
-    result = func(x, 0);
+    result = func(x, zero);
     FPBits x_bits = FPBits(x);
     FPBits result_bits = FPBits(result);
     ASSERT_EQ(result_bits.get_biased_exponent(),
@@ -172,7 +172,7 @@ class NextAfterTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
     x = -x;
 
-    result = func(x, 0);
+    result = func(x, zero);
     result_bits = FPBits(result);
     ASSERT_EQ(result_bits.get_biased_exponent(),
               uint16_t(x_bits.get_biased_exponent() - 1));

>From 90fd9b80f52ac43bc10dd9f6abd4fac55ad0a2a7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 21 Aug 2026 17:18:36 +0530
Subject: [PATCH 5/6] nit

---
 libc/test/shared/shared_math_test.cpp | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 07802e0e30f60..ae96c6251c9ae 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -703,9 +703,6 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                                                          float128(0.0)));
   EXPECT_FP_EQ(float128(0.0), setpayloadsigf128_res);
 
-  float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
-  float128 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
-
 #ifdef LIBC_TYPES_HAS_FLOAT16
   EXPECT_FP_EQ(10.0f16, LIBC_NAMESPACE::shared::f16fmaf128(
                             float128(2.0), float128(3.0), float128(4.0)));

>From 887b7aa4ae693f9a6e95fc30f8dbbf8440f5aed6 Mon Sep 17 00:00:00 2001
From: Zorojuro <sawantsukumar at gmail.com>
Date: Fri, 21 Aug 2026 17:58:10 +0530
Subject: [PATCH 6/6] Apply suggestions from code review

Co-authored-by: Zorojuro <sawantsukumar at gmail.com>
---
 libc/test/src/math/nextafterf128_test.cpp       | 2 +-
 libc/test/src/math/smoke/CMakeLists.txt         | 2 +-
 libc/test/src/math/smoke/nextafterf128_test.cpp | 2 +-
 libc/test/src/math/smoke/nextdownf128_test.cpp  | 2 +-
 libc/test/src/math/smoke/nextupf128_test.cpp    | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/libc/test/src/math/nextafterf128_test.cpp b/libc/test/src/math/nextafterf128_test.cpp
index 9ee60ef21cffe..482709d80a9c2 100644
--- a/libc/test/src/math/nextafterf128_test.cpp
+++ b/libc/test/src/math/nextafterf128_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextAfterTest.h"
-#include "src/__support/FPUtil/float128.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/nextafterf128.h"
 
 #ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ea5523c9118e8..5ee71f5680581 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4085,10 +4085,10 @@ add_fp_unittest(
     NextAfterTest.h
   DEPENDS
     libc.hdr.fenv_macros
-    libc.src.__support.FPUtil.float128
     libc.src.math.nextafterf128
     libc.src.__support.CPP.bit
     libc.src.__support.FPUtil.fenv_impl
+    libc.src.__support.FPUtil.float128
     libc.src.__support.FPUtil.fp_bits
 )
 
diff --git a/libc/test/src/math/smoke/nextafterf128_test.cpp b/libc/test/src/math/smoke/nextafterf128_test.cpp
index 9ee60ef21cffe..482709d80a9c2 100644
--- a/libc/test/src/math/smoke/nextafterf128_test.cpp
+++ b/libc/test/src/math/smoke/nextafterf128_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextAfterTest.h"
-#include "src/__support/FPUtil/float128.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/nextafterf128.h"
 
 #ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
diff --git a/libc/test/src/math/smoke/nextdownf128_test.cpp b/libc/test/src/math/smoke/nextdownf128_test.cpp
index 603b31a9f05cc..239f35f54e6f8 100644
--- a/libc/test/src/math/smoke/nextdownf128_test.cpp
+++ b/libc/test/src/math/smoke/nextdownf128_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextDownTest.h"
-#include "src/__support/FPUtil/float128.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/nextdownf128.h"
 
 #ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128
diff --git a/libc/test/src/math/smoke/nextupf128_test.cpp b/libc/test/src/math/smoke/nextupf128_test.cpp
index 96cc6932ccea8..0408514e7713d 100644
--- a/libc/test/src/math/smoke/nextupf128_test.cpp
+++ b/libc/test/src/math/smoke/nextupf128_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "NextUpTest.h"
-#include "src/__support/FPUtil/float128.h"
 
+#include "src/__support/FPUtil/float128.h"
 #include "src/math/nextupf128.h"
 
 #ifndef LIBC_TYPES_HAS_NATIVE_FLOAT128



More information about the llvm-branch-commits mailing list