[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 17 03:01:42 PST 2026


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

>From e99636d3c92c7427a2b6be8834859193105d3a82 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/2] [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 ++
 libc/test/shared/shared_math_test.cpp         | 18 ++++
 .../llvm-project-overlay/libc/BUILD.bazel     | 92 ++++++++++++++++++-
 24 files changed, 511 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 93f7d6a8156cf..dd43a80e640b7 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -111,6 +111,12 @@
 #include "math/logbf16.h"
 #include "math/logf.h"
 #include "math/logf16.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 aaab78c01a891..cfe34664882b9 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1255,6 +1255,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(
   range_reduction_double
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 75b51b4587bea..5026cd4af94f8 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3600,7 +3600,7 @@ add_entrypoint_object(
   HDRS
     ../nextup.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextup
 )
 
 add_entrypoint_object(
@@ -3610,7 +3610,7 @@ add_entrypoint_object(
   HDRS
     ../nextupl.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupl
 )
 
 add_entrypoint_object(
@@ -3620,7 +3620,7 @@ add_entrypoint_object(
   HDRS
     ../nextupf.h
   DEPENDS
-    libc.src.__support.FPUtil.manipulation_functions
+    libc.src.__support.math.nextupf
 )
 
 add_entrypoint_object(
@@ -3630,8 +3630,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(
@@ -3641,8 +3640,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(
@@ -3652,11 +3650,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 9dfbedee66a33..5df0c299fc377 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -108,6 +108,12 @@ add_fp_unittest(
     libc.src.__support.math.llogbf16
     libc.src.__support.math.logf16    
     libc.src.__support.math.llogbl
+    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/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 2d7ee388f754d..aef2f77c47127 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -81,6 +81,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
                                                        &canonicalizef16_x));
   EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf16(0.0f16),
+               LIBC_NAMESPACE::shared::nextupf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -142,6 +145,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
                                                      &canonicalizef_x));
   EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf(0.0f),
+               LIBC_NAMESPACE::shared::nextupf(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -174,6 +180,9 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalize(&canonicalize_cx,
                                                     &canonicalize_x));
   EXPECT_FP_EQ(0.0, canonicalize_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextup(0.0),
+               LIBC_NAMESPACE::shared::nextup(0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -189,6 +198,9 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
                                                      &canonicalizel_x));
   EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupl(0.0L),
+               LIBC_NAMESPACE::shared::nextupl(0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -224,6 +236,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef128(&canonicalizef128_cx,
                                                         &canonicalizef128_x));
   EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf128(float128(0.0)),
+               LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -236,4 +251,7 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizebf16(&canonicalizebf16_cx,
                                                         &canonicalizebf16_x));
   EXPECT_FP_EQ(bfloat16(0.0), canonicalizebf16_cx);
+
+  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)),
+               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 608180b90e87b..91e8e4a385285 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -3138,6 +3138,63 @@ libc_support_library(
     ],
 )
 
+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 = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextupf16",
+    hdrs = ["src/__support/math/nextupf16.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_nextupl",
+    hdrs = ["src/__support/math/nextupl.h"],
+    deps = [
+        ":__support_fputil_manipulation_functions",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_ldexpf128",
     hdrs = ["src/__support/math/ldexpf128.h"],
@@ -5352,15 +5409,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 5ca334bb2f461af76efbad689927038f0ce48056 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/2] update tests

---
 libc/test/shared/shared_math_test.cpp | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index aef2f77c47127..4be2291ca833b 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -82,8 +82,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
                                                        &canonicalizef16_x));
   EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf16(0.0f16),
-               LIBC_NAMESPACE::shared::nextupf16(0.0f16));
+  EXPECT_FP_EQ(0x1p-24f16, LIBC_NAMESPACE::shared::nextupf16(0.0f16));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -146,8 +145,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
                                                      &canonicalizef_x));
   EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf(0.0f),
-               LIBC_NAMESPACE::shared::nextupf(0.0f));
+  EXPECT_FP_EQ(0x1p-149f, LIBC_NAMESPACE::shared::nextupf(0.0f));
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -181,8 +179,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
                                                     &canonicalize_x));
   EXPECT_FP_EQ(0.0, canonicalize_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextup(0.0),
-               LIBC_NAMESPACE::shared::nextup(0.0));
+  EXPECT_FP_EQ(0x1p-1074, LIBC_NAMESPACE::shared::nextup(0.0));
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -199,8 +196,7 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
                                                      &canonicalizel_x));
   EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupl(0.0L),
-               LIBC_NAMESPACE::shared::nextupl(0.0L));
+  EXPECT_FP_EQ(0x1p-16445L, LIBC_NAMESPACE::shared::nextupl(0.0L));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -237,8 +233,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
                                                         &canonicalizef128_x));
   EXPECT_FP_EQ(float128(0.0), canonicalizef128_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupf128(float128(0.0)),
-               LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
+  EXPECT_FP_EQ(0x1p-16494Q, LIBC_NAMESPACE::shared::nextupf128(float128(0.0)));
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -252,6 +247,6 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
                                                         &canonicalizebf16_x));
   EXPECT_FP_EQ(bfloat16(0.0), canonicalizebf16_cx);
 
-  EXPECT_FP_EQ(LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)),
+  EXPECT_FP_EQ(bfloat16(0x1p-133),
                LIBC_NAMESPACE::shared::nextupbf16(bfloat16(0.0)));
 }



More information about the libc-commits mailing list