[libc-commits] [libc] 4a1f565 - [libc][math] Refactor setpayloadsig family to header-only (#183113)

via libc-commits libc-commits at lists.llvm.org
Tue Feb 24 10:47:26 PST 2026


Author: Anonmiraj
Date: 2026-02-24T20:47:20+02:00
New Revision: 4a1f565c85f637f8f07a090ea09169b2acf3c114

URL: https://github.com/llvm/llvm-project/commit/4a1f565c85f637f8f07a090ea09169b2acf3c114
DIFF: https://github.com/llvm/llvm-project/commit/4a1f565c85f637f8f07a090ea09169b2acf3c114.diff

LOG: [libc][math] Refactor setpayloadsig family to header-only (#183113)

closes : #181823

Added: 
    libc/shared/math/setpayloadsig.h
    libc/shared/math/setpayloadsigbf16.h
    libc/shared/math/setpayloadsigf.h
    libc/shared/math/setpayloadsigf128.h
    libc/shared/math/setpayloadsigf16.h
    libc/shared/math/setpayloadsigl.h
    libc/src/__support/math/setpayloadsig.h
    libc/src/__support/math/setpayloadsigbf16.h
    libc/src/__support/math/setpayloadsigf.h
    libc/src/__support/math/setpayloadsigf128.h
    libc/src/__support/math/setpayloadsigf16.h
    libc/src/__support/math/setpayloadsigl.h

Modified: 
    libc/shared/math.h
    libc/src/__support/math/CMakeLists.txt
    libc/src/math/generic/CMakeLists.txt
    libc/src/math/generic/setpayloadsig.cpp
    libc/src/math/generic/setpayloadsigbf16.cpp
    libc/src/math/generic/setpayloadsigf.cpp
    libc/src/math/generic/setpayloadsigf128.cpp
    libc/src/math/generic/setpayloadsigf16.cpp
    libc/src/math/generic/setpayloadsigl.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 bc530cbe81d0d..0a18d809142d3 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -160,6 +160,12 @@
 #include "math/setpayloadf128.h"
 #include "math/setpayloadf16.h"
 #include "math/setpayloadl.h"
+#include "math/setpayloadsig.h"
+#include "math/setpayloadsigbf16.h"
+#include "math/setpayloadsigf.h"
+#include "math/setpayloadsigf128.h"
+#include "math/setpayloadsigf16.h"
+#include "math/setpayloadsigl.h"
 #include "math/sin.h"
 #include "math/sincos.h"
 #include "math/sincosf.h"

diff  --git a/libc/shared/math/setpayloadsig.h b/libc/shared/math/setpayloadsig.h
new file mode 100644
index 0000000000000..076e64d2659ce
--- /dev/null
+++ b/libc/shared/math/setpayloadsig.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadsig 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_SETPAYLOADSIG_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIG_H
+
+#include "src/__support/math/setpayloadsig.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsig;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIG_H

diff  --git a/libc/shared/math/setpayloadsigbf16.h b/libc/shared/math/setpayloadsigbf16.h
new file mode 100644
index 0000000000000..6a0319636ac74
--- /dev/null
+++ b/libc/shared/math/setpayloadsigbf16.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadsigbf16 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_SETPAYLOADSIGBF16_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGBF16_H
+
+#include "src/__support/math/setpayloadsigbf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsigbf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGBF16_H

diff  --git a/libc/shared/math/setpayloadsigf.h b/libc/shared/math/setpayloadsigf.h
new file mode 100644
index 0000000000000..e132325c8f09e
--- /dev/null
+++ b/libc/shared/math/setpayloadsigf.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadsigf 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_SETPAYLOADSIGF_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF_H
+
+#include "src/__support/math/setpayloadsigf.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsigf;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF_H

diff  --git a/libc/shared/math/setpayloadsigf128.h b/libc/shared/math/setpayloadsigf128.h
new file mode 100644
index 0000000000000..057b88b3d8438
--- /dev/null
+++ b/libc/shared/math/setpayloadsigf128.h
@@ -0,0 +1,28 @@
+//===-- Shared setpayloadsigf128 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_SETPAYLOADSIGF128_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/math/setpayloadsigf128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsigf128;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF128_H

diff  --git a/libc/shared/math/setpayloadsigf16.h b/libc/shared/math/setpayloadsigf16.h
new file mode 100644
index 0000000000000..b3a93506cf423
--- /dev/null
+++ b/libc/shared/math/setpayloadsigf16.h
@@ -0,0 +1,28 @@
+//===-- Shared setpayloadsigf16 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_SETPAYLOADSIGF16_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF16_H
+
+#include "include/llvm-libc-macros/float16-macros.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT16
+
+#include "src/__support/math/setpayloadsigf16.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsigf16;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGF16_H

diff  --git a/libc/shared/math/setpayloadsigl.h b/libc/shared/math/setpayloadsigl.h
new file mode 100644
index 0000000000000..a85c70b69f20f
--- /dev/null
+++ b/libc/shared/math/setpayloadsigl.h
@@ -0,0 +1,22 @@
+//===-- Shared setpayloadsigl 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_SETPAYLOADSIGL_H
+#define LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGL_H
+
+#include "src/__support/math/setpayloadsigl.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::setpayloadsigl;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_SETPAYLOADSIGL_H

diff  --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index aa5f40eb0ddf8..d409d97baad1e 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -1756,6 +1756,63 @@ add_header_library(
     libc.src.__support.macros.config
 )
 
+add_header_library(
+  setpayloadsig
+  HDRS
+    setpayloadsig.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  setpayloadsigbf16
+  HDRS
+    setpayloadsigbf16.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.FPUtil.bfloat16
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  setpayloadsigf
+  HDRS
+    setpayloadsigf.h
+  DEPENDS
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  setpayloadsigf128
+  HDRS
+    setpayloadsigf128.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  setpayloadsigf16
+  HDRS
+    setpayloadsigf16.h
+  DEPENDS
+    libc.include.llvm-libc-macros.float16_macros
+    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.macros.config
+)
+
+add_header_library(
+  setpayloadsigl
+  HDRS
+    setpayloadsigl.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/setpayloadsig.h b/libc/src/__support/math/setpayloadsig.h
new file mode 100644
index 0000000000000..2c19ceadfae36
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsig.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayloadsig -----------------*- 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_SETPAYLOADSIG_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIG_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadsig(double *res, double pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIG_H

diff  --git a/libc/src/__support/math/setpayloadsigbf16.h b/libc/src/__support/math/setpayloadsigbf16.h
new file mode 100644
index 0000000000000..58bf078e7e328
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsigbf16.h
@@ -0,0 +1,27 @@
+//===-- Implementation header for setpayloadsigbf16 -------------*- 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_SETPAYLOADSIGBF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGBF16_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 setpayloadsigbf16(bfloat16 *res, bfloat16 pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGBF16_H

diff  --git a/libc/src/__support/math/setpayloadsigf.h b/libc/src/__support/math/setpayloadsigf.h
new file mode 100644
index 0000000000000..95a0540eb4444
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsigf.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayloadsigf ----------------*- 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_SETPAYLOADSIGF_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadsigf(float *res, float pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF_H

diff  --git a/libc/src/__support/math/setpayloadsigf128.h b/libc/src/__support/math/setpayloadsigf128.h
new file mode 100644
index 0000000000000..fa49c1d58653a
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsigf128.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for setpayloadsigf128 -------------*- 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_SETPAYLOADSIGF128_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF128_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 setpayloadsigf128(float128 *res, float128 pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF128_H

diff  --git a/libc/src/__support/math/setpayloadsigf16.h b/libc/src/__support/math/setpayloadsigf16.h
new file mode 100644
index 0000000000000..e3629cfe3d00e
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsigf16.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for setpayloadsigf16 --------------*- 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_SETPAYLOADSIGF16_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF16_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 setpayloadsigf16(float16 *res, float16 pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGF16_H

diff  --git a/libc/src/__support/math/setpayloadsigl.h b/libc/src/__support/math/setpayloadsigl.h
new file mode 100644
index 0000000000000..9b9de4109e06f
--- /dev/null
+++ b/libc/src/__support/math/setpayloadsigl.h
@@ -0,0 +1,26 @@
+//===-- Implementation header for setpayloadsigl ----------------*- 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_SETPAYLOADSIGL_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGL_H
+
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace math {
+
+LIBC_INLINE int setpayloadsigl(long double *res, long double pl) {
+  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace math
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_SETPAYLOADSIGL_H

diff  --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d6cf821aefa3c..3bf5d9d59c847 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4600,7 +4600,6 @@ add_entrypoint_object(
   HDRS
     ../setpayload.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
     libc.src.__support.math.setpayload
 )
 
@@ -4661,7 +4660,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsig.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.setpayloadsig
 )
 
 add_entrypoint_object(
@@ -4671,7 +4670,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigf.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.setpayloadsigf
 )
 
 add_entrypoint_object(
@@ -4681,7 +4680,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigl.h
   DEPENDS
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.setpayloadsigl
 )
 
 add_entrypoint_object(
@@ -4691,8 +4690,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigf16.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.setpayloadsigf16
 )
 
 add_entrypoint_object(
@@ -4702,8 +4700,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigf128.h
   DEPENDS
-    libc.src.__support.macros.properties.types
-    libc.src.__support.FPUtil.basic_operations
+    libc.src.__support.math.setpayloadsigf128
 )
 
 add_entrypoint_object(
@@ -4713,11 +4710,7 @@ add_entrypoint_object(
   HDRS
     ../setpayloadsigbf16.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.setpayloadsigbf16
 )
 
 add_entrypoint_object(

diff  --git a/libc/src/math/generic/setpayloadsig.cpp b/libc/src/math/generic/setpayloadsig.cpp
index fa8b165ca1277..192767bc92e49 100644
--- a/libc/src/math/generic/setpayloadsig.cpp
+++ b/libc/src/math/generic/setpayloadsig.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsig.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadsig.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsig, (double *res, double pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsig(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/setpayloadsigbf16.cpp b/libc/src/math/generic/setpayloadsigbf16.cpp
index 7a2b7c7dc66dd..774dca5334106 100644
--- a/libc/src/math/generic/setpayloadsigbf16.cpp
+++ b/libc/src/math/generic/setpayloadsigbf16.cpp
@@ -7,15 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigbf16.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/setpayloadsigbf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigbf16, (bfloat16 * res, bfloat16 pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsigbf16(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/setpayloadsigf.cpp b/libc/src/math/generic/setpayloadsigf.cpp
index ec9d98f2123a8..7b4b0ed694f7d 100644
--- a/libc/src/math/generic/setpayloadsigf.cpp
+++ b/libc/src/math/generic/setpayloadsigf.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigf.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadsigf.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigf, (float *res, float pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsigf(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index 97f6a36e229ec..a3972286767b5 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigf128.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadsigf128.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 * res, float128 pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsigf128(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/setpayloadsigf16.cpp b/libc/src/math/generic/setpayloadsigf16.cpp
index 5ba9fcdb0fe18..46628bc935db6 100644
--- a/libc/src/math/generic/setpayloadsigf16.cpp
+++ b/libc/src/math/generic/setpayloadsigf16.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigf16.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadsigf16.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigf16, (float16 * res, float16 pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsigf16(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/src/math/generic/setpayloadsigl.cpp b/libc/src/math/generic/setpayloadsigl.cpp
index 446fbf5d86139..8cd15577200ee 100644
--- a/libc/src/math/generic/setpayloadsigl.cpp
+++ b/libc/src/math/generic/setpayloadsigl.cpp
@@ -7,14 +7,12 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/math/setpayloadsigl.h"
-#include "src/__support/FPUtil/BasicOperations.h"
-#include "src/__support/common.h"
-#include "src/__support/macros/config.h"
+#include "src/__support/math/setpayloadsigl.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, setpayloadsigl, (long double *res, long double pl)) {
-  return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+  return math::setpayloadsigl(res, pl);
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 774fd8eb96be4..144c0460711ba 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -157,6 +157,12 @@ add_fp_unittest(
     libc.src.__support.math.setpayloadf128
     libc.src.__support.math.setpayloadf16
     libc.src.__support.math.setpayloadl
+    libc.src.__support.math.setpayloadsig
+    libc.src.__support.math.setpayloadsigbf16
+    libc.src.__support.math.setpayloadsigf
+    libc.src.__support.math.setpayloadsigf128
+    libc.src.__support.math.setpayloadsigf16
+    libc.src.__support.math.setpayloadsigl
     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 733fdbf87d7c8..785694ad4cd0e 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -99,6 +99,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat16) {
   float16 setpayloadf16_res = 0.0f16;
   EXPECT_EQ(0,
             LIBC_NAMESPACE::shared::setpayloadf16(&setpayloadf16_res, 0.0f16));
+
+  float16 setpayloadsigf16_res = 0.0f16;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigf16(&setpayloadsigf16_res,
+                                                        0.0f16));
+  EXPECT_FP_EQ(0x0p+0f16, setpayloadsigf16_res);
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT16
@@ -170,6 +175,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
 
   float setpayloadf_res = 0.0f;
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf(&setpayloadf_res, 0.0f));
+
+  float setpayloadsigf_res = 0.0f;
+  EXPECT_EQ(1,
+            LIBC_NAMESPACE::shared::setpayloadsigf(&setpayloadsigf_res, 0.0f));
+  EXPECT_FP_EQ(0x0p+0f, setpayloadsigf_res);
 }
 
 TEST(LlvmLibcSharedMathTest, AllDouble) {
@@ -217,6 +227,10 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
 
   double setpayload_res = 0.0;
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayload(&setpayload_res, 0.0));
+
+  double setpayloadsig_res = 0.0;
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsig(&setpayloadsig_res, 0.0));
+  EXPECT_FP_EQ(0.0, setpayloadsig_res);
 }
 
 TEST(LlvmLibcSharedMathTest, AllLongDouble) {
@@ -243,6 +257,11 @@ TEST(LlvmLibcSharedMathTest, AllLongDouble) {
 
   long double setpayloadl_res = 0.0L;
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadl(&setpayloadl_res, 0.0L));
+
+  long double setpayloadsigl_res = 0.0L;
+  EXPECT_EQ(1,
+            LIBC_NAMESPACE::shared::setpayloadsigl(&setpayloadsigl_res, 0.0L));
+  EXPECT_FP_EQ(0x0p+0L, setpayloadsigl_res);
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128
@@ -296,6 +315,11 @@ TEST(LlvmLibcSharedMathTest, AllFloat128) {
   float128 setpayloadf128_res = float128(0.0);
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadf128(&setpayloadf128_res,
                                                       float128(0.0)));
+
+  float128 setpayloadsigf128_res = float128(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigf128(&setpayloadsigf128_res,
+                                                         float128(0.0)));
+  EXPECT_FP_EQ(float128(0.0), setpayloadsigf128_res);
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
@@ -328,4 +352,9 @@ TEST(LlvmLibcSharedMathTest, AllBFloat16) {
   bfloat16 setpayloadbf16_res = bfloat16(0.0);
   EXPECT_EQ(0, LIBC_NAMESPACE::shared::setpayloadbf16(&setpayloadbf16_res,
                                                       bfloat16(0.0)));
+
+  bfloat16 setpayloadsigbf16_res = bfloat16(0.0);
+  EXPECT_EQ(1, LIBC_NAMESPACE::shared::setpayloadsigbf16(&setpayloadsigbf16_res,
+                                                         bfloat16(0.0)));
+  EXPECT_FP_EQ(bfloat16(0.0), setpayloadsigbf16_res);
 }

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 4b8a1000f7fe9..83304e6354610 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -2470,6 +2470,63 @@ libc_support_library(
     ],
 )
 
+libc_support_library(
+    name = "__support_math_setpayloadsig",
+    hdrs = ["src/__support/math/setpayloadsig.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_setpayloadsigbf16",
+    hdrs = ["src/__support/math/setpayloadsigbf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_fputil_bfloat16",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_setpayloadsigf",
+    hdrs = ["src/__support/math/setpayloadsigf.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_setpayloadsigf128",
+    hdrs = ["src/__support/math/setpayloadsigf128.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_types_float128",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_setpayloadsigf16",
+    hdrs = ["src/__support/math/setpayloadsigf16.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+        ":llvm_libc_macros_float16_macros",
+    ],
+)
+
+libc_support_library(
+    name = "__support_math_setpayloadsigl",
+    hdrs = ["src/__support/math/setpayloadsigl.h"],
+    deps = [
+        ":__support_fputil_basic_operations",
+        ":__support_macros_config",
+    ],
+)
+
 libc_support_library(
     name = "__support_math_sqrtf16",
     hdrs = ["src/__support/math/sqrtf16.h"],
@@ -6183,15 +6240,40 @@ libc_math_function(
     ],
 )
 
-libc_math_function(name = "setpayloadsig")
+libc_math_function(
+    name = "setpayloadsig",
+    additional_deps = [
+        ":__support_math_setpayloadsig",
+    ],
+)
 
-libc_math_function(name = "setpayloadsigf")
+libc_math_function(
+    name = "setpayloadsigf",
+    additional_deps = [
+        ":__support_math_setpayloadsigf",
+    ],
+)
 
-libc_math_function(name = "setpayloadsigl")
+libc_math_function(
+    name = "setpayloadsigl",
+    additional_deps = [
+        ":__support_math_setpayloadsigl",
+    ],
+)
 
-libc_math_function(name = "setpayloadsigf128")
+libc_math_function(
+    name = "setpayloadsigf128",
+    additional_deps = [
+        ":__support_math_setpayloadsigf128",
+    ],
+)
 
-libc_math_function(name = "setpayloadsigf16")
+libc_math_function(
+    name = "setpayloadsigf16",
+    additional_deps = [
+        ":__support_math_setpayloadsigf16",
+    ],
+)
 
 libc_math_function(
     name = "sin",


        


More information about the libc-commits mailing list