[libc-commits] [libc] [llvm] [libc][math] Refactor nextafter family to header-only (PR #181673)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 16 06:16:58 PST 2026
https://github.com/AnonMiraj created https://github.com/llvm/llvm-project/pull/181673
closes #181672
>From d1dedf052b2218cf9558f0eea0d3c343e710514b Mon Sep 17 00:00:00 2001
From: Ezzeldin Ibrahim <ezzibrahimx at gmail.com>
Date: Mon, 16 Feb 2026 15:57:48 +0200
Subject: [PATCH] [libc][math] Refactor nextafter family to header-only
---
libc/shared/math.h | 6 ++
libc/shared/math/nextafter.h | 23 +++++
libc/shared/math/nextafterbf16.h | 23 +++++
libc/shared/math/nextafterf.h | 23 +++++
libc/shared/math/nextafterf128.h | 29 ++++++
libc/shared/math/nextafterf16.h | 29 ++++++
libc/shared/math/nextafterl.h | 23 +++++
libc/src/__support/math/CMakeLists.txt | 57 ++++++++++++
libc/src/__support/math/nextafter.h | 26 ++++++
libc/src/__support/math/nextafterbf16.h | 27 ++++++
libc/src/__support/math/nextafterf.h | 26 ++++++
libc/src/__support/math/nextafterf128.h | 32 +++++++
libc/src/__support/math/nextafterf16.h | 32 +++++++
libc/src/__support/math/nextafterl.h | 26 ++++++
libc/src/math/generic/CMakeLists.txt | 18 ++--
libc/src/math/generic/nextafter.cpp | 6 +-
libc/src/math/generic/nextafterbf16.cpp | 7 +-
libc/src/math/generic/nextafterf.cpp | 6 +-
libc/src/math/generic/nextafterf128.cpp | 6 +-
libc/src/math/generic/nextafterf16.cpp | 6 +-
libc/src/math/generic/nextafterl.cpp | 6 +-
libc/test/shared/CMakeLists.txt | 6 ++
libc/test/shared/shared_math_test.cpp | 14 +++
.../llvm-project-overlay/libc/BUILD.bazel | 92 ++++++++++++++++++-
24 files changed, 507 insertions(+), 42 deletions(-)
create mode 100644 libc/shared/math/nextafter.h
create mode 100644 libc/shared/math/nextafterbf16.h
create mode 100644 libc/shared/math/nextafterf.h
create mode 100644 libc/shared/math/nextafterf128.h
create mode 100644 libc/shared/math/nextafterf16.h
create mode 100644 libc/shared/math/nextafterl.h
create mode 100644 libc/src/__support/math/nextafter.h
create mode 100644 libc/src/__support/math/nextafterbf16.h
create mode 100644 libc/src/__support/math/nextafterf.h
create mode 100644 libc/src/__support/math/nextafterf128.h
create mode 100644 libc/src/__support/math/nextafterf16.h
create mode 100644 libc/src/__support/math/nextafterl.h
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 93f7d6a8156cf..cb6e65eb216f6 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/nextafter.h"
+#include "math/nextafterbf16.h"
+#include "math/nextafterf.h"
+#include "math/nextafterf128.h"
+#include "math/nextafterf16.h"
+#include "math/nextafterl.h"
#include "math/pow.h"
#include "math/powf.h"
#include "math/rsqrtf.h"
diff --git a/libc/shared/math/nextafter.h b/libc/shared/math/nextafter.h
new file mode 100644
index 0000000000000..07addbba337e4
--- /dev/null
+++ b/libc/shared/math/nextafter.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafter 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_NEXTAFTER_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTER_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafter.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafter;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTER_H
diff --git a/libc/shared/math/nextafterbf16.h b/libc/shared/math/nextafterbf16.h
new file mode 100644
index 0000000000000..52073b1fde409
--- /dev/null
+++ b/libc/shared/math/nextafterbf16.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterbf16 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_NEXTAFTERBF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERBF16_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERBF16_H
diff --git a/libc/shared/math/nextafterf.h b/libc/shared/math/nextafterf.h
new file mode 100644
index 0000000000000..0933cd30679e6
--- /dev/null
+++ b/libc/shared/math/nextafterf.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterf 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_NEXTAFTERF_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF_H
diff --git a/libc/shared/math/nextafterf128.h b/libc/shared/math/nextafterf128.h
new file mode 100644
index 0000000000000..e25c2ea1fee56
--- /dev/null
+++ b/libc/shared/math/nextafterf128.h
@@ -0,0 +1,29 @@
+//===-- Shared nextafterf128 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_NEXTAFTERF128_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF128_H
diff --git a/libc/shared/math/nextafterf16.h b/libc/shared/math/nextafterf16.h
new file mode 100644
index 0000000000000..c90ac3b9ae69d
--- /dev/null
+++ b/libc/shared/math/nextafterf16.h
@@ -0,0 +1,29 @@
+//===-- Shared nextafterf16 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_NEXTAFTERF16_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERF16_H
diff --git a/libc/shared/math/nextafterl.h b/libc/shared/math/nextafterl.h
new file mode 100644
index 0000000000000..4de0f1c25c02f
--- /dev/null
+++ b/libc/shared/math/nextafterl.h
@@ -0,0 +1,23 @@
+//===-- Shared nextafterl 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_NEXTAFTERL_H
+#define LLVM_LIBC_SHARED_MATH_NEXTAFTERL_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/nextafterl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::nextafterl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_NEXTAFTERL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index aaab78c01a891..5e7be7fa3ffb0 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(
+ nextafter
+ HDRS
+ nextafter.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nextafterbf16
+ HDRS
+ nextafterbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nextafterf
+ HDRS
+ nextafterf.h
+ DEPENDS
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nextafterf128
+ HDRS
+ nextafterf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nextafterf16
+ HDRS
+ nextafterf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ nextafterl
+ HDRS
+ nextafterl.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/nextafter.h b/libc/src/__support/math/nextafter.h
new file mode 100644
index 0000000000000..beb2fc9da057c
--- /dev/null
+++ b/libc/src/__support/math/nextafter.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafter ---------------------*- 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_NEXTAFTER_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTER_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE double nextafter(double x, double y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTER_H
diff --git a/libc/src/__support/math/nextafterbf16.h b/libc/src/__support/math/nextafterbf16.h
new file mode 100644
index 0000000000000..26679e2079045
--- /dev/null
+++ b/libc/src/__support/math/nextafterbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for nextafterbf16 -----------------*- 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_NEXTAFTERBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERBF16_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 bfloat16 nextafterbf16(bfloat16 x, bfloat16 y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERBF16_H
diff --git a/libc/src/__support/math/nextafterf.h b/libc/src/__support/math/nextafterf.h
new file mode 100644
index 0000000000000..7d8a0f203879b
--- /dev/null
+++ b/libc/src/__support/math/nextafterf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafterf --------------------*- 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_NEXTAFTERF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE float nextafterf(float x, float y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF_H
diff --git a/libc/src/__support/math/nextafterf128.h b/libc/src/__support/math/nextafterf128.h
new file mode 100644
index 0000000000000..b13b913c506fe
--- /dev/null
+++ b/libc/src/__support/math/nextafterf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextafterf128 -----------------*- 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_NEXTAFTERF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_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 float128 nextafterf128(float128 x, float128 y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF128_H
diff --git a/libc/src/__support/math/nextafterf16.h b/libc/src/__support/math/nextafterf16.h
new file mode 100644
index 0000000000000..631790b44cb73
--- /dev/null
+++ b/libc/src/__support/math/nextafterf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for nextafterf16 ------------------*- 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_NEXTAFTERF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF16_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 float16 nextafterf16(float16 x, float16 y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERF16_H
diff --git a/libc/src/__support/math/nextafterl.h b/libc/src/__support/math/nextafterl.h
new file mode 100644
index 0000000000000..cf2c2e6da5fb4
--- /dev/null
+++ b/libc/src/__support/math/nextafterl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for nextafterl --------------------*- 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_NEXTAFTERL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERL_H
+
+#include "src/__support/FPUtil/ManipulationFunctions.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE long double nextafterl(long double x, long double y) {
+ return fputil::nextafter(x, y);
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_NEXTAFTERL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 75b51b4587bea..692abcf043e0b 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3413,7 +3413,7 @@ add_entrypoint_object(
HDRS
../nextafter.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nextafter
)
add_entrypoint_object(
@@ -3423,7 +3423,7 @@ add_entrypoint_object(
HDRS
../nextafterf.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nextafterf
)
add_entrypoint_object(
@@ -3433,7 +3433,7 @@ add_entrypoint_object(
HDRS
../nextafterl.h
DEPENDS
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nextafterl
)
add_entrypoint_object(
@@ -3443,8 +3443,7 @@ add_entrypoint_object(
HDRS
../nextafterf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nextafterf16
)
add_entrypoint_object(
@@ -3454,8 +3453,7 @@ add_entrypoint_object(
HDRS
../nextafterf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.manipulation_functions
+ libc.src.__support.math.nextafterf128
)
add_entrypoint_object(
@@ -3465,11 +3463,7 @@ add_entrypoint_object(
HDRS
../nextafterbf16.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.nextafterbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/nextafter.cpp b/libc/src/math/generic/nextafter.cpp
index ff35c86930eab..bbb98576e0b40 100644
--- a/libc/src/math/generic/nextafter.cpp
+++ b/libc/src/math/generic/nextafter.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafter.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafter.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(double, nextafter, (double x, double y)) {
- return fputil::nextafter(x, y);
+ return math::nextafter(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextafterbf16.cpp b/libc/src/math/generic/nextafterbf16.cpp
index e21a2dcb3d664..42887c9eba274 100644
--- a/libc/src/math/generic/nextafterbf16.cpp
+++ b/libc/src/math/generic/nextafterbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafterbf16.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/nextafterbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(bfloat16, nextafterbf16, (bfloat16 x, bfloat16 y)) {
- return fputil::nextafter(x, y);
+ return math::nextafterbf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextafterf.cpp b/libc/src/math/generic/nextafterf.cpp
index fd8ca02895b67..eca649704b759 100644
--- a/libc/src/math/generic/nextafterf.cpp
+++ b/libc/src/math/generic/nextafterf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafterf.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float, nextafterf, (float x, float y)) {
- return fputil::nextafter(x, y);
+ return math::nextafterf(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextafterf128.cpp b/libc/src/math/generic/nextafterf128.cpp
index c774f10b88ccd..3363db898fe0b 100644
--- a/libc/src/math/generic/nextafterf128.cpp
+++ b/libc/src/math/generic/nextafterf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafterf128.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float128, nextafterf128, (float128 x, float128 y)) {
- return fputil::nextafter(x, y);
+ return math::nextafterf128(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextafterf16.cpp b/libc/src/math/generic/nextafterf16.cpp
index 70adc9c0800d3..69fe584eae1af 100644
--- a/libc/src/math/generic/nextafterf16.cpp
+++ b/libc/src/math/generic/nextafterf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafterf16.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(float16, nextafterf16, (float16 x, float16 y)) {
- return fputil::nextafter(x, y);
+ return math::nextafterf16(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/nextafterl.cpp b/libc/src/math/generic/nextafterl.cpp
index 5dafd63b77560..e888f88c36a07 100644
--- a/libc/src/math/generic/nextafterl.cpp
+++ b/libc/src/math/generic/nextafterl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/nextafterl.h"
-#include "src/__support/FPUtil/ManipulationFunctions.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/nextafterl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(long double, nextafterl, (long double x, long double y)) {
- return fputil::nextafter(x, y);
+ return math::nextafterl(x, y);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 9dfbedee66a33..443663d22fa1e 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.nextafter
+ libc.src.__support.math.nextafterbf16
+ libc.src.__support.math.nextafterf
+ libc.src.__support.math.nextafterf128
+ libc.src.__support.math.nextafterf16
+ libc.src.__support.math.nextafterl
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..cd9bad55facdb 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -81,6 +81,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef16(&canonicalizef16_cx,
&canonicalizef16_x));
EXPECT_FP_EQ(0x0p+0f16, canonicalizef16_cx);
+
+ EXPECT_FP_EQ(0x0p+0f16, LIBC_NAMESPACE::shared::nextafterf16(0.0f16, 0.0f16));
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -142,6 +144,8 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizef(&canonicalizef_cx,
&canonicalizef_x));
EXPECT_FP_EQ(0x0p+0f, canonicalizef_cx);
+
+ EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::nextafterf(0.0f, 0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -174,6 +178,8 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalize(&canonicalize_cx,
&canonicalize_x));
EXPECT_FP_EQ(0.0, canonicalize_cx);
+
+ EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::nextafter(0.0, 0.0));
}
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -189,6 +195,8 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_EQ(0, LIBC_NAMESPACE::shared::canonicalizel(&canonicalizel_cx,
&canonicalizel_x));
EXPECT_FP_EQ(0x0p+0L, canonicalizel_cx);
+
+ EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::nextafterl(0.0L, 0.0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -224,6 +232,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(float128(0.0), LIBC_NAMESPACE::shared::nextafterf128(
+ float128(0.0), float128(0.0)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -236,4 +247,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(bfloat16(0.0), LIBC_NAMESPACE::shared::nextafterbf16(
+ bfloat16(0.0), 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..8ea90968426b9 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_nextafter",
+ hdrs = ["src/__support/math/nextafter.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nextafterbf16",
+ hdrs = ["src/__support/math/nextafterbf16.h"],
+ deps = [
+ ":__support_fputil_bfloat16",
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nextafterf",
+ hdrs = ["src/__support/math/nextafterf.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nextafterf128",
+ hdrs = ["src/__support/math/nextafterf128.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nextafterf16",
+ hdrs = ["src/__support/math/nextafterf16.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_nextafterl",
+ hdrs = ["src/__support/math/nextafterl.h"],
+ deps = [
+ ":__support_fputil_manipulation_functions",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_ldexpf128",
hdrs = ["src/__support/math/ldexpf128.h"],
@@ -5324,15 +5381,40 @@ libc_math_function(name = "nearbyintf128")
libc_math_function(name = "nearbyintf16")
-libc_math_function(name = "nextafter")
+libc_math_function(
+ name = "nextafter",
+ additional_deps = [
+ ":__support_math_nextafter",
+ ],
+)
-libc_math_function(name = "nextafterf")
+libc_math_function(
+ name = "nextafterf",
+ additional_deps = [
+ ":__support_math_nextafterf",
+ ],
+)
-libc_math_function(name = "nextafterl")
+libc_math_function(
+ name = "nextafterl",
+ additional_deps = [
+ ":__support_math_nextafterl",
+ ],
+)
-libc_math_function(name = "nextafterf128")
+libc_math_function(
+ name = "nextafterf128",
+ additional_deps = [
+ ":__support_math_nextafterf128",
+ ],
+)
-libc_math_function(name = "nextafterf16")
+libc_math_function(
+ name = "nextafterf16",
+ additional_deps = [
+ ":__support_math_nextafterf16",
+ ],
+)
libc_math_function(name = "nextdown")
More information about the libc-commits
mailing list