[libc-commits] [libc] [llvm] [libc][math] Refactor nextup family to header-only (PR #181688)

via libc-commits libc-commits at lists.llvm.org
Tue Feb 24 11:50:33 PST 2026


https://github.com/AnonMiraj updated https://github.com/llvm/llvm-project/pull/181688

>From bb8826205a0b3b5f6ea9870f84ed3fab30ffdc26 Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Mon, 16 Feb 2026 17:33:55 +0200
Subject: [PATCH 1/3] [libc][math] Refactor nextup family to header-only

---
 libc/shared/math.h                            |  6 ++
 libc/shared/math/nextup.h                     | 23 ++++++++
 libc/shared/math/nextupbf16.h                 | 23 ++++++++
 libc/shared/math/nextupf.h                    | 23 ++++++++
 libc/shared/math/nextupf128.h                 | 29 ++++++++++
 libc/shared/math/nextupf16.h                  | 29 ++++++++++
 libc/shared/math/nextupl.h                    | 23 ++++++++
 libc/src/__support/math/CMakeLists.txt        | 57 +++++++++++++++++++
 libc/src/__support/math/nextup.h              | 26 +++++++++
 libc/src/__support/math/nextupbf16.h          | 27 +++++++++
 libc/src/__support/math/nextupf.h             | 26 +++++++++
 libc/src/__support/math/nextupf128.h          | 32 +++++++++++
 libc/src/__support/math/nextupf16.h           | 32 +++++++++++
 libc/src/__support/math/nextupl.h             | 26 +++++++++
 libc/src/math/generic/CMakeLists.txt          | 18 ++----
 libc/src/math/generic/nextup.cpp              |  8 +--
 libc/src/math/generic/nextupbf16.cpp          |  7 +--
 libc/src/math/generic/nextupf.cpp             |  8 +--
 libc/src/math/generic/nextupf128.cpp          |  6 +-
 libc/src/math/generic/nextupf16.cpp           |  6 +-
 libc/src/math/generic/nextupl.cpp             |  6 +-
 libc/test/shared/CMakeLists.txt               |  6 ++
 .../llvm-project-overlay/libc/BUILD.bazel     | 50 ++++++++++++++--
 23 files changed, 451 insertions(+), 46 deletions(-)
 create mode 100644 libc/shared/math/nextup.h
 create mode 100644 libc/shared/math/nextupbf16.h
 create mode 100644 libc/shared/math/nextupf.h
 create mode 100644 libc/shared/math/nextupf128.h
 create mode 100644 libc/shared/math/nextupf16.h
 create mode 100644 libc/shared/math/nextupl.h
 create mode 100644 libc/src/__support/math/nextup.h
 create mode 100644 libc/src/__support/math/nextupbf16.h
 create mode 100644 libc/src/__support/math/nextupf.h
 create mode 100644 libc/src/__support/math/nextupf128.h
 create mode 100644 libc/src/__support/math/nextupf16.h
 create mode 100644 libc/src/__support/math/nextupl.h

diff --git a/libc/shared/math.h b/libc/shared/math.h
index 50223b22fe266..b3cbe9d5dd731 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -156,6 +156,12 @@
 #include "math/nextdownf128.h"
 #include "math/nextdownf16.h"
 #include "math/nextdownl.h"
+#include "math/nextup.h"
+#include "math/nextupbf16.h"
+#include "math/nextupf.h"
+#include "math/nextupf128.h"
+#include "math/nextupf16.h"
+#include "math/nextupl.h"
 #include "math/pow.h"
 #include "math/powf.h"
 #include "math/rsqrtf.h"
diff --git a/libc/shared/math/nextup.h b/libc/shared/math/nextup.h
new file mode 100644
index 0000000000000..f147d73603985
--- /dev/null
+++ b/libc/shared/math/nextup.h
@@ -0,0 +1,23 @@
+//===-- Shared nextup function ----------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEXTUP_H
+#define LLVM_LIBC_SHARED_MATH_NEXTUP_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextup.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextup;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUP_H
diff --git a/libc/shared/math/nextupbf16.h b/libc/shared/math/nextupbf16.h
new file mode 100644
index 0000000000000..aa46777f0364c
--- /dev/null
+++ b/libc/shared/math/nextupbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nextupbf16 function ------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEXTUPBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTUPBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextupbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextupbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUPBF16_H
diff --git a/libc/shared/math/nextupf.h b/libc/shared/math/nextupf.h
new file mode 100644
index 0000000000000..41b2f9d0b5a43
--- /dev/null
+++ b/libc/shared/math/nextupf.h
@@ -0,0 +1,23 @@
+//===-- Shared nextupf function ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEXTUPF_H
+#define LLVM_LIBC_SHARED_MATH_NEXTUPF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextupf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextupf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUPF_H
diff --git a/libc/shared/math/nextupf128.h b/libc/shared/math/nextupf128.h
new file mode 100644
index 0000000000000..68756071c1d17
--- /dev/null
+++ b/libc/shared/math/nextupf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nextupf128 function ------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextupf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextupf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUPF128_H
diff --git a/libc/shared/math/nextupf16.h b/libc/shared/math/nextupf16.h
new file mode 100644
index 0000000000000..68690ff5afc0d
--- /dev/null
+++ b/libc/shared/math/nextupf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nextupf16 function -------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEXTUPF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTUPF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextupf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextupf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUPF16_H
diff --git a/libc/shared/math/nextupl.h b/libc/shared/math/nextupl.h
new file mode 100644
index 0000000000000..8affa04feecad
--- /dev/null
+++ b/libc/shared/math/nextupl.h
@@ -0,0 +1,23 @@
+//===-- Shared nextupl function ---------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_MATH_NEXTUPL_H
+#define LLVM_LIBC_SHARED_MATH_NEXTUPL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextupl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextupl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTUPL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index b15cd7743a123..b45ea068989b6 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1640,6 +1640,63 @@ add_header_library(
     libc.src.__support.common
     libc.src.__support.macros.config
 )
+add_header_library(
+  nextup
+  HDRS
+    nextup.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextupbf16
+  HDRS
+    nextupbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextupf
+  HDRS
+    nextupf.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextupf128
+  HDRS
+    nextupf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextupf16
+  HDRS
+    nextupf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  nextupl
+  HDRS
+    nextupl.h
+  DEPENDS
+    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.macros.config
+)
+
 
 add_header_library(
   nextdown
diff --git a/libc/src/__support/math/nextup.h b/libc/src/__support/math/nextup.h
new file mode 100644
index 0000000000000..039e9315d7673
--- /dev/null
+++ b/libc/src/__support/math/nextup.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextup ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUP_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUP_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr double nextup(double x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUP_H
diff --git a/libc/src/__support/math/nextupbf16.h b/libc/src/__support/math/nextupbf16.h
new file mode 100644
index 0000000000000..6e9fb272ba66e
--- /dev/null
+++ b/libc/src/__support/math/nextupbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for nextupbf16 --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPBF16_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr bfloat16 nextupbf16(bfloat16 x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPBF16_H
diff --git a/libc/src/__support/math/nextupf.h b/libc/src/__support/math/nextupf.h
new file mode 100644
index 0000000000000..37ddd192b94ed
--- /dev/null
+++ b/libc/src/__support/math/nextupf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextupf -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr float nextupf(float x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF_H
diff --git a/libc/src/__support/math/nextupf128.h b/libc/src/__support/math/nextupf128.h
new file mode 100644
index 0000000000000..36c1424518fa6
--- /dev/null
+++ b/libc/src/__support/math/nextupf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextupf128 --------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#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_FLOAT128
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr float128 nextupf128(float128 x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF128_H
diff --git a/libc/src/__support/math/nextupf16.h b/libc/src/__support/math/nextupf16.h
new file mode 100644
index 0000000000000..b0168cfe5274e
--- /dev/null
+++ b/libc/src/__support/math/nextupf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextupf16 ---------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr float16 nextupf16(float16 x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPF16_H
diff --git a/libc/src/__support/math/nextupl.h b/libc/src/__support/math/nextupl.h
new file mode 100644
index 0000000000000..2d0e43a3d9f5a
--- /dev/null
+++ b/libc/src/__support/math/nextupl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextupl -----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE constexpr long double nextupl(long double x) {
+  return fputil::nextupdown</*IsDown=*/false>(x);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTUPL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 354c3cf912d77..de9c9b44e79aa 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3540,7 +3540,7 @@ add_entrypoint_object(
   HDRS
     ../nextup.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextup
 )
 
 add_entrypoint_object(
@@ -3550,7 +3550,7 @@ add_entrypoint_object(
   HDRS
     ../nextupl.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupl
 )
 
 add_entrypoint_object(
@@ -3560,7 +3560,7 @@ add_entrypoint_object(
   HDRS
     ../nextupf.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupf
 )
 
 add_entrypoint_object(
@@ -3570,8 +3570,7 @@ add_entrypoint_object(
   HDRS
     ../nextupf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupf16
 )
 
 add_entrypoint_object(
@@ -3581,8 +3580,7 @@ add_entrypoint_object(
   HDRS
     ../nextupf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupf128
 )
 
 add_entrypoint_object(
@@ -3592,11 +3590,7 @@ add_entrypoint_object(
   HDRS
     ../nextupbf16.h
   DEPENDS
-    libc.src.__support.common
-    libc.src.__support.FPUtil.bfloat16
-    libc.src.__support.FPUtil.manipulation_functions
-    libc.src.__support.macros.config
-    libc.src.__support.macros.properties.types
+    libc.src.__support.math.nextupbf16
 )
 
 add_entrypoint_object(
diff --git a/libc/src/math/generic/nextup.cpp b/libc/src/math/generic/nextup.cpp
index ac068240875d1..6d36a1f443c1a 100644
--- a/libc/src/math/generic/nextup.cpp
+++ b/libc/src/math/generic/nextup.cpp
@@ -7,14 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextup.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextup.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(double, nextup, (double x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
-}
+LLVM_LIBC_FUNCTION(double, nextup, (double x)) { return math::nextup(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupbf16.cpp b/libc/src/math/generic/nextupbf16.cpp
index 147ce37477d9f..279fb0bf41c06 100644
--- a/libc/src/math/generic/nextupbf16.cpp
+++ b/libc/src/math/generic/nextupbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupbf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextupbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(bfloat16, nextupbf16, (bfloat16 x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
+  return math::nextupbf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupf.cpp b/libc/src/math/generic/nextupf.cpp
index 10a4b032b66dd..f57f23d0392f0 100644
--- a/libc/src/math/generic/nextupf.cpp
+++ b/libc/src/math/generic/nextupf.cpp
@@ -7,14 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextupf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(float, nextupf, (float x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
-}
+LLVM_LIBC_FUNCTION(float, nextupf, (float x)) { return math::nextupf(x); }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupf128.cpp b/libc/src/math/generic/nextupf128.cpp
index c380f0d60916f..71a7b20b86741 100644
--- a/libc/src/math/generic/nextupf128.cpp
+++ b/libc/src/math/generic/nextupf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextupf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float128, nextupf128, (float128 x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
+  return math::nextupf128(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupf16.cpp b/libc/src/math/generic/nextupf16.cpp
index 5588480c58d0a..37735b9a823cb 100644
--- a/libc/src/math/generic/nextupf16.cpp
+++ b/libc/src/math/generic/nextupf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextupf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(float16, nextupf16, (float16 x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
+  return math::nextupf16(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextupl.cpp b/libc/src/math/generic/nextupl.cpp
index e4ef195738811..910d6717e3338 100644
--- a/libc/src/math/generic/nextupl.cpp
+++ b/libc/src/math/generic/nextupl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/nextupl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextupl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(long double, nextupl, (long double x)) {
-  return fputil::nextupdown</*IsDown=*/false>(x);
+  return math::nextupl(x);
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index a298ab5cf4e18..eb4bb2705897d 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -154,6 +154,12 @@ add_fp_unittest(
     libc.src.__support.math.nextdownf128
     libc.src.__support.math.nextdownf16
     libc.src.__support.math.nextdownl
+    libc.src.__support.math.nextup
+    libc.src.__support.math.nextupbf16
+    libc.src.__support.math.nextupf
+    libc.src.__support.math.nextupf128
+    libc.src.__support.math.nextupf16
+    libc.src.__support.math.nextupl
     libc.src.__support.math.pow
     libc.src.__support.math.powf
     libc.src.__support.math.rsqrtf
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 20363853b4680..835d50a606424 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3608,6 +3608,8 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdown",
     hdrs = ["src/__support/math/nextdown.h"],
+    name = "__support_math_nextup",
+    hdrs = ["src/__support/math/nextup.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -3617,6 +3619,8 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownbf16",
     hdrs = ["src/__support/math/nextdownbf16.h"],
+    name = "__support_math_nextupbf16",
+    hdrs = ["src/__support/math/nextupbf16.h"],
     deps = [
         ":__support_fputil_bfloat16",
         ":__support_fputil_manipulation_functions",
@@ -3627,6 +3631,8 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownf",
     hdrs = ["src/__support/math/nextdownf.h"],
+    name = "__support_math_nextupf",
+    hdrs = ["src/__support/math/nextupf.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -3639,6 +3645,11 @@ libc_support_library(
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_properties_types",
+    name = "__support_math_nextupf128",
+    hdrs = ["src/__support/math/nextupf128.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
         ":llvm_libc_types_float128",
     ],
 )
@@ -3646,6 +3657,8 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownf16",
     hdrs = ["src/__support/math/nextdownf16.h"],
+    name = "__support_math_nextupf16",
+    hdrs = ["src/__support/math/nextupf16.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -3656,6 +3669,8 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownl",
     hdrs = ["src/__support/math/nextdownl.h"],
+    name = "__support_math_nextupl",
+    hdrs = ["src/__support/math/nextupl.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -6181,15 +6196,40 @@ libc_math_function(name = "nexttowardf16")
 
 libc_math_function(name = "nexttowardl")
 
-libc_math_function(name = "nextup")
+libc_math_function(
+    name = "nextup",
+    additional_deps = [
+        ":__support_math_nextup",
+    ],
+)
 
-libc_math_function(name = "nextupf")
+libc_math_function(
+    name = "nextupf",
+    additional_deps = [
+        ":__support_math_nextupf",
+    ],
+)
 
-libc_math_function(name = "nextupl")
+libc_math_function(
+    name = "nextupl",
+    additional_deps = [
+        ":__support_math_nextupl",
+    ],
+)
 
-libc_math_function(name = "nextupf128")
+libc_math_function(
+    name = "nextupf128",
+    additional_deps = [
+        ":__support_math_nextupf128",
+    ],
+)
 
-libc_math_function(name = "nextupf16")
+libc_math_function(
+    name = "nextupf16",
+    additional_deps = [
+        ":__support_math_nextupf16",
+    ],
+)
 
 libc_math_function(
     name = "pow",

>From 4a0a46fc6139645dea6e9b7cd0b6f571468f6119 Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Tue, 17 Feb 2026 13:01:27 +0200
Subject: [PATCH 2/3] update tests

---
 libc/test/shared/shared_math_test.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 01b30b92e5ebf..aa6152f54573e 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -107,6 +107,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(0x0p+0f16, setpayloadsigf16_res);
   float16 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownf16(0.0f16));
+  EXPECT_FP_EQ(0x1p-24f16, LIBC_NAMESPACE::shared::nextupf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -186,6 +187,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0x0p+0f, setpayloadsigf_res);
   float neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownf(0.0f));
+  EXPECT_FP_EQ(0x1p-149f, LIBC_NAMESPACE::shared::nextupf(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -242,6 +244,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_FP_EQ(0.0, setpayloadsig_res);
   double neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdown(0.0));
+  EXPECT_FP_EQ(0x1p-1074, LIBC_NAMESPACE::shared::nextup(0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -277,6 +280,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
 
   long double neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownl(0.0L));
+  EXPECT_FP_EQ(0x1p-16445L, LIBC_NAMESPACE::shared::nextupl(0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -340,6 +344,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
+  EXPECT_FP_EQ(0x1p-16494Q, LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -381,4 +386,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   bfloat16 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownbf16(bfloat16(0.0)));
+  EXPECT_FP_EQ(bfloat16(0x1p-133),
+               LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)));
 }

>From 277e9d4cfe185354bd943d069e1cfb8544e804f6 Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Tue, 17 Feb 2026 21:09:45 +0200
Subject: [PATCH 3/3] fix tests

---
 libc/test/shared/shared_math_test.cpp         | 19 +++---
 .../llvm-project-overlay/libc/BUILD.bazel     | 62 ++++++++++++++++---
 2 files changed, 64 insertions(+), 17 deletions(-)

diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index aa6152f54573e..aee5a37097c7c 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -107,7 +107,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_FP_EQ(0x0p+0f16, setpayloadsigf16_res);
   float16 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownf16(0.0f16));
-  EXPECT_FP_EQ(0x1p-24f16, LIBC_NAMESPACE::shared::nextupf16(0.0f16));
+  float16 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -187,7 +188,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_FP_EQ(0x0p+0f, setpayloadsigf_res);
   float neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownf(0.0f));
-  EXPECT_FP_EQ(0x1p-149f, LIBC_NAMESPACE::shared::nextupf(0.0f));
+  float min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupf(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -244,7 +246,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_FP_EQ(0.0, setpayloadsig_res);
   double neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdown(0.0));
-  EXPECT_FP_EQ(0x1p-1074, LIBC_NAMESPACE::shared::nextup(0.0));
+  double min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextup(0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -280,7 +283,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
 
   long double neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal, LIBC_NAMESPACE::shared::nextdownl(0.0L));
-  EXPECT_FP_EQ(0x1p-16445L, LIBC_NAMESPACE::shared::nextupl(0.0L));
+  long double min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupl(0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -344,7 +348,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   float128 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownf128(float128(0.0)));
-  EXPECT_FP_EQ(0x1p-16494Q, LIBC_NAMESPACE::shared::nextupf128(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)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -386,6 +391,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   bfloat16 neg_min_denormal = FPBits::min_subnormal(Sign::NEG).get_val();
   EXPECT_FP_EQ(neg_min_denormal,
                LIBC_NAMESPACE::shared::nextdownbf16(bfloat16(0.0)));
-  EXPECT_FP_EQ(bfloat16(0x1p-133),
-               LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)));
+  bfloat16 min_denormal = FPBits::min_subnormal(Sign ::POS).get_val();
+  EXPECT_FP_EQ(min_denormal, LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)));
 }
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 835d50a606424..2af0cf7197c48 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3608,8 +3608,6 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdown",
     hdrs = ["src/__support/math/nextdown.h"],
-    name = "__support_math_nextup",
-    hdrs = ["src/__support/math/nextup.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -3619,8 +3617,6 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownbf16",
     hdrs = ["src/__support/math/nextdownbf16.h"],
-    name = "__support_math_nextupbf16",
-    hdrs = ["src/__support/math/nextupbf16.h"],
     deps = [
         ":__support_fputil_bfloat16",
         ":__support_fputil_manipulation_functions",
@@ -3631,8 +3627,6 @@ libc_support_library(
 libc_support_library(
     name = "__support_math_nextdownf",
     hdrs = ["src/__support/math/nextdownf.h"],
-    name = "__support_math_nextupf",
-    hdrs = ["src/__support/math/nextupf.h"],
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_config",
@@ -3645,6 +3639,58 @@ libc_support_library(
     deps = [
         ":__support_fputil_manipulation_functions",
         ":__support_macros_properties_types",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextdownf16",
+    hdrs = ["src/__support/math/nextdownf16.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextdownl",
+    hdrs = ["src/__support/math/nextdownl.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextup",
+    hdrs = ["src/__support/math/nextup.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextupbf16",
+    hdrs = ["src/__support/math/nextupbf16.h"],
+    deps = [
+        ":__support_fputil_bfloat16",
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextupf",
+    hdrs = ["src/__support/math/nextupf.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
     name = "__support_math_nextupf128",
     hdrs = ["src/__support/math/nextupf128.h"],
     deps = [
@@ -3655,8 +3701,6 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_nextdownf16",
-    hdrs = ["src/__support/math/nextdownf16.h"],
     name = "__support_math_nextupf16",
     hdrs = ["src/__support/math/nextupf16.h"],
     deps = [
@@ -3667,8 +3711,6 @@ libc_support_library(
 )
 
 libc_support_library(
-    name = "__support_math_nextdownl",
-    hdrs = ["src/__support/math/nextdownl.h"],
     name = "__support_math_nextupl",
     hdrs = ["src/__support/math/nextupl.h"],
     deps = [



More information about the libc-commits mailing list