[libc-commits] [libc] 03388af - [libc][math] Refactor setpayload family to header-only (#182922)
via libc-commits
libc-commits at lists.llvm.org
Tue Feb 24 09:50:12 PST 2026
Author: Anonmiraj
Date: 2026-02-24T19:50:07+02:00
New Revision: 03388af3197b85bb3047ea4aa7791633662bb821
URL: https://github.com/llvm/llvm-project/commit/03388af3197b85bb3047ea4aa7791633662bb821
DIFF: https://github.com/llvm/llvm-project/commit/03388af3197b85bb3047ea4aa7791633662bb821.diff
LOG: [libc][math] Refactor setpayload family to header-only (#182922)
part of #181823
Added:
libc/shared/math/setpayload.h
libc/shared/math/setpayloadbf16.h
libc/shared/math/setpayloadf.h
libc/shared/math/setpayloadf128.h
libc/shared/math/setpayloadf16.h
libc/shared/math/setpayloadl.h
libc/src/__support/math/setpayload.h
libc/src/__support/math/setpayloadbf16.h
libc/src/__support/math/setpayloadf.h
libc/src/__support/math/setpayloadf128.h
libc/src/__support/math/setpayloadf16.h
libc/src/__support/math/setpayloadl.h
Modified:
libc/shared/math.h
libc/src/__support/math/CMakeLists.txt
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/setpayload.cpp
libc/src/math/generic/setpayloadbf16.cpp
libc/src/math/generic/setpayloadf.cpp
libc/src/math/generic/setpayloadf128.cpp
libc/src/math/generic/setpayloadf16.cpp
libc/src/math/generic/setpayloadl.cpp
libc/test/shared/CMakeLists.txt
libc/test/shared/shared_math_test.cpp
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 034674735a422..7f739d7173799 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -153,6 +153,12 @@
#include "math/powf.h"
#include "math/rsqrtf.h"
#include "math/rsqrtf16.h"
+#include "math/setpayload.h"
+#include "math/setpayloadbf16.h"
+#include "math/setpayloadf.h"
+#include "math/setpayloadf128.h"
+#include "math/setpayloadf16.h"
+#include "math/setpayloadl.h"
#include "math/sin.h"
#include "math/sincos.h"
#include "math/sincosf.h"
diff --git a/libc/shared/math/setpayload.h b/libc/shared/math/setpayload.h
new file mode 100644
index 0000000000000..c3f2d74b18b32
--- /dev/null
+++ b/libc/shared/math/setpayload.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayload 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_SETPAYLOAD_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOAD_H
+
+#include "src/__support/math/setpayload.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayload;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOAD_H
diff --git a/libc/shared/math/setpayloadbf16.h b/libc/shared/math/setpayloadbf16.h
new file mode 100644
index 0000000000000..8b4aa19e085ae
--- /dev/null
+++ b/libc/shared/math/setpayloadbf16.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadbf16 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_SETPAYLOADBF16_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADBF16_H
+
+#include "src/__support/math/setpayloadbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADBF16_H
diff --git a/libc/shared/math/setpayloadf.h b/libc/shared/math/setpayloadf.h
new file mode 100644
index 0000000000000..2c69bf0c14717
--- /dev/null
+++ b/libc/shared/math/setpayloadf.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadf 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_SETPAYLOADF_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADF_H
+
+#include "src/__support/math/setpayloadf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADF_H
diff --git a/libc/shared/math/setpayloadf128.h b/libc/shared/math/setpayloadf128.h
new file mode 100644
index 0000000000000..e50a563964f57
--- /dev/null
+++ b/libc/shared/math/setpayloadf128.h
@@ -0,0 +1,28 @@
+//===-- Shared setpayloadf128 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_SETPAYLOADF128_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/setpayloadf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADF128_H
diff --git a/libc/shared/math/setpayloadf16.h b/libc/shared/math/setpayloadf16.h
new file mode 100644
index 0000000000000..09592952effab
--- /dev/null
+++ b/libc/shared/math/setpayloadf16.h
@@ -0,0 +1,28 @@
+//===-- Shared setpayloadf16 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_SETPAYLOADF16_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/setpayloadf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADF16_H
diff --git a/libc/shared/math/setpayloadl.h b/libc/shared/math/setpayloadl.h
new file mode 100644
index 0000000000000..0fd3f58fb5446
--- /dev/null
+++ b/libc/shared/math/setpayloadl.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadl 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_SETPAYLOADL_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADL_H
+
+#include "src/__support/math/setpayloadl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADL_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index e577e9410c6c2..e18865a2479ac 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1683,6 +1683,63 @@ add_header_library(
libc.src.__support.macros.optimization
)
+add_header_library(
+ setpayload
+ HDRS
+ setpayload.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ setpayloadbf16
+ HDRS
+ setpayloadbf16.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.FPUtil.bfloat16
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ setpayloadf
+ HDRS
+ setpayloadf.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ setpayloadf128
+ HDRS
+ setpayloadf128.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ setpayloadf16
+ HDRS
+ setpayloadf16.h
+ DEPENDS
+ libc.include.llvm-libc-macros.float16_macros
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ setpayloadl
+ HDRS
+ setpayloadl.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.macros.config
+)
+
add_header_library(
sqrtf16
HDRS
diff --git a/libc/src/__support/math/setpayload.h b/libc/src/__support/math/setpayload.h
new file mode 100644
index 0000000000000..f9fa79ce76e1d
--- /dev/null
+++ b/libc/src/__support/math/setpayload.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayload --------------------*- 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_SETPAYLOAD_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOAD_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayload(double *res, double pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOAD_H
diff --git a/libc/src/__support/math/setpayloadbf16.h b/libc/src/__support/math/setpayloadbf16.h
new file mode 100644
index 0000000000000..31e02eb4f7ccb
--- /dev/null
+++ b/libc/src/__support/math/setpayloadbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for setpayloadbf16 ----------------*- 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_SETPAYLOADBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADBF16_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/FPUtil/bfloat16.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadbf16(bfloat16 *res, bfloat16 pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADBF16_H
diff --git a/libc/src/__support/math/setpayloadf.h b/libc/src/__support/math/setpayloadf.h
new file mode 100644
index 0000000000000..2431f253956a1
--- /dev/null
+++ b/libc/src/__support/math/setpayloadf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayloadf -------------------*- 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_SETPAYLOADF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadf(float *res, float pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF_H
diff --git a/libc/src/__support/math/setpayloadf128.h b/libc/src/__support/math/setpayloadf128.h
new file mode 100644
index 0000000000000..cf301e92c69b3
--- /dev/null
+++ b/libc/src/__support/math/setpayloadf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for setpayloadf128 ----------------*- 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_SETPAYLOADF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadf128(float128 *res, float128 pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF128_H
diff --git a/libc/src/__support/math/setpayloadf16.h b/libc/src/__support/math/setpayloadf16.h
new file mode 100644
index 0000000000000..4a417f0c525eb
--- /dev/null
+++ b/libc/src/__support/math/setpayloadf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for setpayloadf16 -----------------*- 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_SETPAYLOADF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadf16(float16 *res, float16 pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADF16_H
diff --git a/libc/src/__support/math/setpayloadl.h b/libc/src/__support/math/setpayloadl.h
new file mode 100644
index 0000000000000..d5ed051766827
--- /dev/null
+++ b/libc/src/__support/math/setpayloadl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayloadl -------------------*- 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_SETPAYLOADL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadl(long double *res, long double pl) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADL_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 70843ce3c0aef..990a04701714c 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4609,6 +4609,7 @@ add_entrypoint_object(
../setpayload.h
DEPENDS
libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.setpayload
)
add_entrypoint_object(
@@ -4618,7 +4619,7 @@ add_entrypoint_object(
HDRS
../setpayloadf.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.setpayloadf
)
add_entrypoint_object(
@@ -4628,7 +4629,7 @@ add_entrypoint_object(
HDRS
../setpayloadl.h
DEPENDS
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.setpayloadl
)
add_entrypoint_object(
@@ -4638,8 +4639,7 @@ add_entrypoint_object(
HDRS
../setpayloadf16.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.setpayloadf16
)
add_entrypoint_object(
@@ -4649,8 +4649,7 @@ add_entrypoint_object(
HDRS
../setpayloadf128.h
DEPENDS
- libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
+ libc.src.__support.math.setpayloadf128
)
add_entrypoint_object(
@@ -4660,11 +4659,7 @@ add_entrypoint_object(
HDRS
../setpayloadbf16.h
DEPENDS
- libc.src.__support.common
- libc.src.__support.FPUtil.basic_operations
- libc.src.__support.FPUtil.bfloat16
- libc.src.__support.macros.config
- libc.src.__support.macros.properties.types
+ libc.src.__support.math.setpayloadbf16
)
add_entrypoint_object(
diff --git a/libc/src/math/generic/setpayload.cpp b/libc/src/math/generic/setpayload.cpp
index 7e7078c95bdce..66ec416cd2c95 100644
--- a/libc/src/math/generic/setpayload.cpp
+++ b/libc/src/math/generic/setpayload.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayload.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayload.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayload, (double *res, double pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayload(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadbf16.cpp b/libc/src/math/generic/setpayloadbf16.cpp
index 49f9b9cabd6a2..ae18b019dbc93 100644
--- a/libc/src/math/generic/setpayloadbf16.cpp
+++ b/libc/src/math/generic/setpayloadbf16.cpp
@@ -7,15 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayloadbf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/FPUtil/bfloat16.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadbf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayloadbf16, (bfloat16 * res, bfloat16 pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayloadbf16(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadf.cpp b/libc/src/math/generic/setpayloadf.cpp
index 50d2ffd22fb77..f25599caf8390 100644
--- a/libc/src/math/generic/setpayloadf.cpp
+++ b/libc/src/math/generic/setpayloadf.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayloadf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadf.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayloadf, (float *res, float pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayloadf(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp
index a50e5efd82ceb..83a3218688a99 100644
--- a/libc/src/math/generic/setpayloadf128.cpp
+++ b/libc/src/math/generic/setpayloadf128.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayloadf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadf128.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayloadf128, (float128 * res, float128 pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayloadf128(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadf16.cpp b/libc/src/math/generic/setpayloadf16.cpp
index 1d1445eb22432..1b89c5c404b91 100644
--- a/libc/src/math/generic/setpayloadf16.cpp
+++ b/libc/src/math/generic/setpayloadf16.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayloadf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadf16.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayloadf16, (float16 * res, float16 pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayloadf16(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadl.cpp b/libc/src/math/generic/setpayloadl.cpp
index 486f3f9272d56..922071507843a 100644
--- a/libc/src/math/generic/setpayloadl.cpp
+++ b/libc/src/math/generic/setpayloadl.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "src/math/setpayloadl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadl.h"
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, setpayloadl, (long double *res, long double pl)) {
- return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
+ return math::setpayloadl(res, pl);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 0cdaed2e10b49..5e1a06c7abe87 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -150,6 +150,12 @@ add_fp_unittest(
libc.src.__support.math.powf
libc.src.__support.math.rsqrtf
libc.src.__support.math.rsqrtf16
+ libc.src.__support.math.setpayload
+ libc.src.__support.math.setpayloadbf16
+ libc.src.__support.math.setpayloadf
+ libc.src.__support.math.setpayloadf128
+ libc.src.__support.math.setpayloadf16
+ libc.src.__support.math.setpayloadl
libc.src.__support.math.sqrtf16
libc.src.__support.math.sin
libc.src.__support.math.sincos
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index 312a6ac7a8d47..b7d0f239a1a2f 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -94,6 +94,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
float16 getpayloadf16_x = 0.0f16;
EXPECT_FP_EQ(-0x1p+0f16,
LIBC_NAMESPACE::shared::getpayloadf16(&getpayloadf16_x));
+
+ float16 setpayloadf16_res = 0.0f16;
+ EXPECT_EQ(0,
+ LIBC_NAMESPACE::shared::setpayloadf16(&setpayloadf16_res, 0.0f16));
}
#endif // LIBC_TYPES_HAS_FLOAT16
@@ -162,6 +166,9 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::fmaxf(0.0f, 0.0f));
float getpayloadf_x = 0.0f;
EXPECT_FP_EQ(-0x1p+0f, LIBC_NAMESPACE::shared::getpayloadf(&getpayloadf_x));
+
+ float setpayloadf_res = 0.0f;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf(&setpayloadf_res, 0.0f));
}
TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -206,6 +213,9 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::fmax(0.0, 0.0));
double getpayload_x = 0.0;
EXPECT_FP_EQ(-1.0, LIBC_NAMESPACE::shared::getpayload(&getpayload_x));
+
+ double setpayload_res = 0.0;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayload(&setpayload_res, 0.0));
}
TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -229,6 +239,9 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
EXPECT_FP_EQ(0x0p+0L, LIBC_NAMESPACE::shared::fmaxl(0.0L, 0.0L));
long double getpayloadl_x = 0.0L;
EXPECT_FP_EQ(-0x1p+0L, LIBC_NAMESPACE::shared::getpayloadl(&getpayloadl_x));
+
+ long double setpayloadl_res = 0.0L;
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadl(&setpayloadl_res, 0.0L));
}
#ifdef LIBC_TYPES_HAS_FLOAT128
@@ -278,6 +291,10 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
float128 getpayloadf128_x = float128(0.0);
EXPECT_FP_EQ(float128(-1.0),
LIBC_NAMESPACE::shared::getpayloadf128(&getpayloadf128_x));
+
+ float128 setpayloadf128_res = float128(0.0);
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf128(&setpayloadf128_res,
+ float128(0.0)));
}
#endif // LIBC_TYPES_HAS_FLOAT128
@@ -306,4 +323,8 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
bfloat16 getpayloadbf16_x = bfloat16(0.0);
EXPECT_FP_EQ(bfloat16(-1.0),
LIBC_NAMESPACE::shared::getpayloadbf16(&getpayloadbf16_x));
+
+ bfloat16 setpayloadbf16_res = bfloat16(0.0);
+ EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadbf16(&setpayloadbf16_res,
+ bfloat16(0.0)));
}
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index de443652ccf0b..2affa0334ee0b 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2413,6 +2413,63 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "__support_math_setpayload",
+ hdrs = ["src/__support/math/setpayload.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_setpayloadbf16",
+ hdrs = ["src/__support/math/setpayloadbf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_fputil_bfloat16",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_setpayloadf",
+ hdrs = ["src/__support/math/setpayloadf.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_setpayloadf128",
+ hdrs = ["src/__support/math/setpayloadf128.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_types_float128",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_setpayloadf16",
+ hdrs = ["src/__support/math/setpayloadf16.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ":llvm_libc_macros_float16_macros",
+ ],
+)
+
+libc_support_library(
+ name = "__support_math_setpayloadl",
+ hdrs = ["src/__support/math/setpayloadl.h"],
+ deps = [
+ ":__support_fputil_basic_operations",
+ ":__support_macros_config",
+ ],
+)
+
libc_support_library(
name = "__support_math_sqrtf16",
hdrs = ["src/__support/math/sqrtf16.h"],
@@ -6074,15 +6131,40 @@ libc_math_function(name = "scalbnf128")
libc_math_function(name = "scalbnf16")
-libc_math_function(name = "setpayload")
+libc_math_function(
+ name = "setpayload",
+ additional_deps = [
+ ":__support_math_setpayload",
+ ],
+)
-libc_math_function(name = "setpayloadf")
+libc_math_function(
+ name = "setpayloadf",
+ additional_deps = [
+ ":__support_math_setpayloadf",
+ ],
+)
-libc_math_function(name = "setpayloadl")
+libc_math_function(
+ name = "setpayloadl",
+ additional_deps = [
+ ":__support_math_setpayloadl",
+ ],
+)
-libc_math_function(name = "setpayloadf128")
+libc_math_function(
+ name = "setpayloadf128",
+ additional_deps = [
+ ":__support_math_setpayloadf128",
+ ],
+)
-libc_math_function(name = "setpayloadf16")
+libc_math_function(
+ name = "setpayloadf16",
+ additional_deps = [
+ ":__support_math_setpayloadf16",
+ ],
+)
libc_math_function(name = "setpayloadsig")
More information about the libc-commits
mailing list