[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 03:49:38 PDT 2026


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

>From 61a57e6f2b3ce321b0531cf3117b127f39a632a3 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/3] 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 be6f4e02513a4..ffe55d5755871 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -541,6 +541,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 d38861a4638e0..bd95ae6fe9e7b 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -553,6 +553,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 3a198301223cc..a2cf331aaa03c 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -549,6 +549,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 69165c68e3d4e..eea14d94290f8 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -360,6 +360,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 4cd5d8221cbb1..923552c10b9a2 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -222,6 +222,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 c5967f0c29b15..478d71b3d4148 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -270,6 +270,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
@@ -541,7 +542,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 67977851b6dee..750aef6b49c90 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/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/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 379c2b7b4e255..653723331b19f 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -481,6 +481,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 fd45246bc9879..88ef13be299da 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -701,6 +701,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 4c8344f0f32ab..c97ed8a1fd211 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -515,6 +515,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 465a7bf48f6af..b289c060ed3a8 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -769,6 +769,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 38a8e18883b1c..ac25175be7e9f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -779,6 +779,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 01700822f34b3..74a70068af3f0 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -303,6 +303,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 7ba5352e3545f..b15137063a649 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 24b9d31a8660c..10ec4cd20cfeb 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3226,6 +3226,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 923d2ee9f0275..bf3ba6d4ccfcf 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)));
@@ -499,9 +500,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 == LIBC_NAMESPACE::shared::iscanonicalf128(float128(0.0)));
 static_assert(0 == LIBC_NAMESPACE::shared::isnanf128(float128(0.0)));
 static_assert(0.0 == LIBC_NAMESPACE::shared::issignalingf128(float128(0.0)));
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index cc62c21752da2..15fca8cd59e49 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)));
@@ -697,8 +698,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 7be266c72deca..7a505e0f71bb2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4082,6 +4082,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 53d4caf7506ef..e2226856247d5 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",
     ],
 )
 
@@ -12994,6 +12994,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 53faf591a19e6..228748cc74802 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
@@ -1293,6 +1293,9 @@ math_test(
     name = "nextafterf128",
     hdrs = ["NextAfterTest.h"],
     deps = ["//libc:__support_sign"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 72529533841c72160f7e8af12e0fc12918cf2767 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/3] 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 ffe55d5755871..6eab72cf06f74 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -551,6 +551,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 bd95ae6fe9e7b..c9f9a63d318c1 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -563,6 +563,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 a2cf331aaa03c..3411b94df2db8 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -559,6 +559,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 eea14d94290f8..2c8f1822f32d6 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -370,6 +370,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 923552c10b9a2..1790cc352cfdf 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.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 478d71b3d4148..de494573d01c4 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.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
@@ -543,7 +544,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 750aef6b49c90..d39b475656dfc 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/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/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index 653723331b19f..b7f7c66081401 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -491,6 +491,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 88ef13be299da..fd44c8fe54a81 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -711,6 +711,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 c97ed8a1fd211..697765d7e409b 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -525,6 +525,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 b289c060ed3a8..156ce1b90dfd9 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -779,6 +779,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 ac25175be7e9f..fb0566b7e5174 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -789,6 +789,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 74a70068af3f0..6b1ca4647ad9f 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -308,6 +308,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 b15137063a649..c558f47590d25 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 10ec4cd20cfeb..a3bf75f064fbd 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3397,6 +3397,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 bf3ba6d4ccfcf..a3982fd3007ce 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 15fca8cd59e49..ab9c10e3322e6 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)));
@@ -697,7 +699,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 7a505e0f71bb2..64d98754d09ba 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4320,6 +4320,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 e2226856247d5..be0438810618c 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",
     ],
 )
 
@@ -13108,6 +13108,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 228748cc74802..f073bfff303c1 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
@@ -1367,6 +1367,9 @@ math_test(
 math_test(
     name = "nextupf128",
     hdrs = ["NextUpTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(

>From 6ed22cf44efcc756e9ccc460bebff1945ee845e7 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/3] 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 6eab72cf06f74..e070c040d85df 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -545,6 +545,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.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 c9f9a63d318c1..68e39c534c16b 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -557,6 +557,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.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 3411b94df2db8..99d35e8342273 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -553,6 +553,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.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 2c8f1822f32d6..6b4d66fefbc9a 100644
--- a/libc/config/darwin/aarch64/entrypoints.txt
+++ b/libc/config/darwin/aarch64/entrypoints.txt
@@ -364,6 +364,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.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 1790cc352cfdf..5db07ccec5202 100644
--- a/libc/config/darwin/x86_64/entrypoints.txt
+++ b/libc/config/darwin/x86_64/entrypoints.txt
@@ -224,6 +224,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 de494573d01c4..e5f71d80c1c87 100644
--- a/libc/config/freebsd/x86_64/entrypoints.txt
+++ b/libc/config/freebsd/x86_64/entrypoints.txt
@@ -272,6 +272,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
@@ -543,7 +544,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 d39b475656dfc..ea238f7565b3b 100644
--- a/libc/config/gpu/amdgpu/entrypoints.txt
+++ b/libc/config/gpu/amdgpu/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/gpu/nvptx/entrypoints.txt b/libc/config/gpu/nvptx/entrypoints.txt
index b7f7c66081401..4a18baf208402 100644
--- a/libc/config/gpu/nvptx/entrypoints.txt
+++ b/libc/config/gpu/nvptx/entrypoints.txt
@@ -485,6 +485,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 fd44c8fe54a81..07e5b4f6b1a9d 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -705,6 +705,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 697765d7e409b..0a0f38f983b94 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -519,6 +519,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 156ce1b90dfd9..05a8b0d8a2cb1 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -773,6 +773,7 @@ set(TARGET_LIBM_ENTRYPOINTS
     libc.src.math.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 fb0566b7e5174..3eaf9936132aa 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -783,6 +783,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 6b1ca4647ad9f..bfc517b272fc6 100644
--- a/libc/config/windows/entrypoints.txt
+++ b/libc/config/windows/entrypoints.txt
@@ -305,6 +305,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 c558f47590d25..e644c917de5ee 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 a3bf75f064fbd..ca86078012fe1 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3337,6 +3337,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 a3982fd3007ce..6f3b433a30938 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)));
@@ -430,6 +427,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 ab9c10e3322e6..919ac4a509420 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)));
@@ -619,6 +619,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)));
@@ -696,8 +701,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 64d98754d09ba..66a4f3ac65710 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -4247,6 +4247,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 be0438810618c..fa5bb354a999f 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",
     ],
 )
 
@@ -13038,6 +13038,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 f073bfff303c1..53b0077a9acad 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
@@ -1322,6 +1322,9 @@ math_test(
 math_test(
     name = "nextdownf128",
     hdrs = ["NextDownTest.h"],
+    deps = [
+        "//libc:__support_fputil_float128",
+    ],
 )
 
 math_test(



More information about the llvm-branch-commits mailing list