[libc-commits] [libc] [libc][math][c23] Add entrypoints and tests for setpayloadsig{, f, l, f128} (PR #102413)
Job Henandez Lara via libc-commits
libc-commits at lists.llvm.org
Wed Aug 7 20:48:32 PDT 2024
https://github.com/Jobhdez updated https://github.com/llvm/llvm-project/pull/102413
>From 603643e8a9cd1684ab331f299e6a61ab3c88c699 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 19:09:19 -0700
Subject: [PATCH 1/5] [libc][math][c23] Add entrypoints and tests for
setpayloadsig{,f,f128}
---
libc/config/linux/aarch64/entrypoints.txt | 3 ++
libc/config/linux/arm/entrypoints.txt | 2 +
libc/config/linux/riscv/entrypoints.txt | 3 ++
libc/config/linux/x86_64/entrypoints.txt | 3 ++
libc/docs/math/index.rst | 2 +-
libc/newhdrgen/yaml/math.yaml | 22 +++++++++++
libc/spec/stdc.td | 3 ++
libc/src/math/CMakeLists.txt | 3 ++
libc/src/math/generic/CMakeLists.txt | 37 +++++++++++++++++++
libc/src/math/generic/setpayloadsig.cpp | 20 ++++++++++
libc/src/math/generic/setpayloadsigf.cpp | 20 ++++++++++
libc/src/math/generic/setpayloadsigf128.cpp | 20 ++++++++++
libc/src/math/setpayloadsig.h | 20 ++++++++++
libc/src/math/setpayloadsigf.h | 20 ++++++++++
libc/src/math/setpayloadsigf128.h | 21 +++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 37 +++++++++++++++++++
.../src/math/smoke/setpayloadsig_test.cpp | 13 +++++++
.../src/math/smoke/setpayloadsigf128_test.cpp | 13 +++++++
.../src/math/smoke/setpayloadsigf_test.cpp | 13 +++++++
19 files changed, 274 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/generic/setpayloadsig.cpp
create mode 100644 libc/src/math/generic/setpayloadsigf.cpp
create mode 100644 libc/src/math/generic/setpayloadsigf128.cpp
create mode 100644 libc/src/math/setpayloadsig.h
create mode 100644 libc/src/math/setpayloadsigf.h
create mode 100644 libc/src/math/setpayloadsigf128.h
create mode 100644 libc/test/src/math/smoke/setpayloadsig_test.cpp
create mode 100644 libc/test/src/math/smoke/setpayloadsigf128_test.cpp
create mode 100644 libc/test/src/math/smoke/setpayloadsigf_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index cdc93f437bf5fa..fcf2dd766bd2d5 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -546,6 +546,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadsig
+ libc.src.math.setpayloadsigf
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
@@ -726,6 +728,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.roundf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
+ libc.src.math.setpayloadsigf128
libc.src.math.sqrtf128
libc.src.math.totalorderf128
libc.src.math.totalordermagf128
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 5d33faad0cb0bb..9d648b754579e9 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -376,6 +376,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadsig
+ libc.src.math.setpayloadsigf
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 66dd6e261f3d63..d98a7b43ec0ff9 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -549,6 +549,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadsig
+ libc.src.math.setpayloadsigf
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
@@ -633,6 +635,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.roundf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
+ libc.src.math.setpayloadsigf128
libc.src.math.sqrtf128
libc.src.math.totalorderf128
libc.src.math.totalordermagf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index ace1b1b08eb12b..24ffb52ee00d70 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -549,6 +549,8 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadsig
+ libc.src.math.setpayloadsigf
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
@@ -722,6 +724,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.roundf128
libc.src.math.scalbnf128
libc.src.math.setpayloadf128
+ libc.src.math.setpayloadsigf128
libc.src.math.sqrtf128
libc.src.math.totalorderf128
libc.src.math.totalordermagf128
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index c665ce397f9b7d..0df1d5ec4b5fea 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -226,7 +226,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| setpayload | |check| | |check| | | |check| | |check| | F.10.13.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| setpayloadsig | | | | |check| | | F.10.13.3 | N/A |
+| setpayloadsig | |check| | |check| | | |check| | |check| | F.10.13.3 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| totalorder | |check| | |check| | | |check| | |check| | F.10.12.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index 12410c1d41e8cf..ae19811a6a0d36 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -1773,6 +1773,20 @@ functions:
- type: _Float16 *
- type: _Float16
guard: LIBC_TYPES_HAS_FLOAT16
+ - name: setpayloadsig
+ standards:
+ - stdc
+ return_type: double
+ arguments:
+ - type: double *
+ - type: double
+ - name: setpayloadsigf
+ standards:
+ - stdc
+ return_type: int
+ arguments:
+ - type: float *
+ - type: float
- name: setpayloadsigf16
standards:
- stdc
@@ -1781,6 +1795,14 @@ functions:
- type: _Float16 *
- type: _Float16
guard: LIBC_TYPES_HAS_FLOAT16
+ - name: setpayloadsigf128
+ standards:
+ - stdc
+ return_type: int
+ arguments:
+ - type: float128 *
+ - type: float128
+ guard: LIBC_TYPES_HAS_FLOAT128
- name: totalorderf16
standards:
- stdc
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 6f974e4384a535..4d586de02e130a 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -761,7 +761,10 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"setpayloadf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+ FunctionSpec<"setpayloadsig", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
+ FunctionSpec<"setpayloadsigf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
+ GuardedFunctionSpec<"setpayloadsigf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
GuardedFunctionSpec<"f16addf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a0bd5269169fa3..fb36c49216ba81 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -439,7 +439,10 @@ add_math_entrypoint_object(setpayloadf)
add_math_entrypoint_object(setpayloadf16)
add_math_entrypoint_object(setpayloadf128)
+add_math_entrypoint_object(setpayloadsig)
+add_math_entrypoint_object(setpayloadsigf)
add_math_entrypoint_object(setpayloadsigf16)
+add_math_entrypoint_object(setpayloadsigf128)
add_math_entrypoint_object(sincos)
add_math_entrypoint_object(sincosf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index be5cc2e02635af..602417386667f1 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4499,6 +4499,30 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ setpayloadsig
+ SRCS
+ setpayloadsig.cpp
+ HDRS
+ ../setpayloadsig.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
+add_entrypoint_object(
+ setpayloadsigf
+ SRCS
+ setpayloadsigf.cpp
+ HDRS
+ ../setpayloadsigf.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
setpayloadsigf16
SRCS
@@ -4512,6 +4536,19 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ setpayloadsigf128
+ SRCS
+ setpayloadsigf128.cpp
+ HDRS
+ ../setpayloadsigf128.h
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
f16add
SRCS
diff --git a/libc/src/math/generic/setpayloadsig.cpp b/libc/src/math/generic/setpayloadsig.cpp
new file mode 100644
index 00000000000000..fa8b165ca12777
--- /dev/null
+++ b/libc/src/math/generic/setpayloadsig.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadsig function --------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/setpayloadsig.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, setpayloadsig, (double *res, double pl)) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadsigf.cpp b/libc/src/math/generic/setpayloadsigf.cpp
new file mode 100644
index 00000000000000..ec9d98f2123a86
--- /dev/null
+++ b/libc/src/math/generic/setpayloadsigf.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadsigf function -------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/setpayloadsigf.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, setpayloadsigf, (float *res, float pl)) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
new file mode 100644
index 00000000000000..d98e4d1fc8b1cf
--- /dev/null
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadsigf128 function ----------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/setpayloadsigf128.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 *res, float128 pl)) {
+ return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadsig.h b/libc/src/math/setpayloadsig.h
new file mode 100644
index 00000000000000..8059e6f018210c
--- /dev/null
+++ b/libc/src/math/setpayloadsig.h
@@ -0,0 +1,20 @@
+//===-- 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_MATH_SETPAYLOADSIG_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADSIG_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadsig(double *res, double pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADSIG_H
diff --git a/libc/src/math/setpayloadsigf.h b/libc/src/math/setpayloadsigf.h
new file mode 100644
index 00000000000000..e7a0175682ea7c
--- /dev/null
+++ b/libc/src/math/setpayloadsigf.h
@@ -0,0 +1,20 @@
+//===-- 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_MATH_SETPAYLOADSIGF_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadsigf(float *res, float pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF_H
diff --git a/libc/src/math/setpayloadsigf128.h b/libc/src/math/setpayloadsigf128.h
new file mode 100644
index 00000000000000..4e036b9c8ba007
--- /dev/null
+++ b/libc/src/math/setpayloadsigf128.h
@@ -0,0 +1,21 @@
+//===-- 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_MATH_SETPAYLOADSIGF128_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadsigf128(float128 *res, float128 pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF128_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 6becaa569e62af..272295d3841a5a 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3957,6 +3957,30 @@ add_fp_unittest(
libc.src.math.setpayloadf128
)
+add_fp_unittest(
+ setpayloadsig_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ setpayloadsig_test.cpp
+ HDRS
+ SetPayloadSigTest.h
+ DEPENDS
+ libc.src.math.setpayloadsig
+)
+
+add_fp_unittest(
+ setpayloadsigf_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ setpayloadsigf_test.cpp
+ HDRS
+ SetPayloadSigTest.h
+ DEPENDS
+ libc.src.math.setpayloadsigf
+)
+
add_fp_unittest(
setpayloadsigf16_test
SUITE
@@ -3969,6 +3993,19 @@ add_fp_unittest(
libc.src.math.setpayloadsigf16
)
+add_fp_unittest(
+ setpayloadsigf128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ setpayloadsigf128_test.cpp
+ HDRS
+ SetPayloadSigTest.h
+ DEPENDS
+ libc.src.math.setpayloadsigf128
+)
+
+
add_fp_unittest(
f16add_test
SUITE
diff --git a/libc/test/src/math/smoke/setpayloadsig_test.cpp b/libc/test/src/math/smoke/setpayloadsig_test.cpp
new file mode 100644
index 00000000000000..4a7dea73bbc8f6
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadsig_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadsig ---------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "SetPayloadSigTest.h"
+
+#include "src/math/setpayloadsig.h"
+
+LIST_SETPAYLOADSIG_TESTS(double, LIBC_NAMESPACE::setpayloadsig)
diff --git a/libc/test/src/math/smoke/setpayloadsigf128_test.cpp b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
new file mode 100644
index 00000000000000..ea7d0268b3a29e
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadsigf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadsigf128 -----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "SetPayloadSigTest.h"
+
+#include "src/math/setpayloadsigf128.h"
+
+LIST_SETPAYLOADSIG_TESTS(float128, LIBC_NAMESPACE::setpayloadsigf128)
diff --git a/libc/test/src/math/smoke/setpayloadsigf_test.cpp b/libc/test/src/math/smoke/setpayloadsigf_test.cpp
new file mode 100644
index 00000000000000..dd8ca2fe86ece0
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadsigf_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadsigf --------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "SetPayloadSigTest.h"
+
+#include "src/math/setpayloadsigf.h"
+
+LIST_SETPAYLOADSIG_TESTS(float, LIBC_NAMESPACE::setpayloadsigf)
>From f59ad890c76eda15b4d2b8fd11229cf74855c762 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 19:11:01 -0700
Subject: [PATCH 2/5] format code
---
libc/src/math/generic/setpayloadsigf128.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/math/generic/setpayloadsigf128.cpp b/libc/src/math/generic/setpayloadsigf128.cpp
index d98e4d1fc8b1cf..97f6a36e229ecd 100644
--- a/libc/src/math/generic/setpayloadsigf128.cpp
+++ b/libc/src/math/generic/setpayloadsigf128.cpp
@@ -13,7 +13,7 @@
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 *res, float128 pl)) {
+LLVM_LIBC_FUNCTION(int, setpayloadsigf128, (float128 * res, float128 pl)) {
return static_cast<int>(fputil::setpayload</*IsSignaling=*/true>(*res, pl));
}
>From 34cb157b67693c48559807f8f0eecd0d21a26d00 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 20:03:59 -0700
Subject: [PATCH 3/5] add setpayloadsigl
---
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/docs/math/index.rst | 2 +-
libc/newhdrgen/yaml/math.yaml | 7 +++++++
libc/spec/stdc.td | 1 +
libc/src/__support/FPUtil/BasicOperations.h | 2 +-
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 12 +++++++++++
libc/src/math/generic/setpayloadsigl.cpp | 20 +++++++++++++++++++
libc/src/math/setpayloadsigl.h | 20 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 12 +++++++++++
.../src/math/smoke/setpayloadsigl_test.cpp | 13 ++++++++++++
11 files changed, 89 insertions(+), 2 deletions(-)
create mode 100644 libc/src/math/generic/setpayloadsigl.cpp
create mode 100644 libc/src/math/setpayloadsigl.h
create mode 100644 libc/test/src/math/smoke/setpayloadsigl_test.cpp
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 24ffb52ee00d70..39634081e0338d 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -551,6 +551,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.setpayloadf
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
+ libc.src.math.setpayloadsigl
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 0df1d5ec4b5fea..c6c5591ca63d2c 100644
--- a/libc/docs/math/index.rst
+++ b/libc/docs/math/index.rst
@@ -226,7 +226,7 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| setpayload | |check| | |check| | | |check| | |check| | F.10.13.2 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
-| setpayloadsig | |check| | |check| | | |check| | |check| | F.10.13.3 | N/A |
+| setpayloadsig | |check| | |check| | |check| | |check| | |check| | F.10.13.3 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| totalorder | |check| | |check| | | |check| | |check| | F.10.12.1 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index ae19811a6a0d36..b456bc375af65f 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -1787,6 +1787,13 @@ functions:
arguments:
- type: float *
- type: float
+ - name: setpayloadsigl
+ standards:
+ - stdc
+ return_type: int
+ arguments:
+ - type: long double *
+ - type: long double
- name: setpayloadsigf16
standards:
- stdc
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 4d586de02e130a..d0eb166bd854a2 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -763,6 +763,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"setpayloadsig", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
FunctionSpec<"setpayloadsigf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
+ FunctionSpec<"setpayloadsigl", RetValSpec<IntType>, [ArgSpec<LongDoublePtr>, ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"setpayloadsigf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index d68f3ae6a26bbd..8046bf0b508929 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -377,7 +377,7 @@ setpayload(T &res, T pl) {
}
using StorageType = typename FPBits::StorageType;
- StorageType v(pl_bits.get_explicit_mantissa() >> (FPBits::SIG_LEN - pl_exp));
+ StorageType v(pl_bits.get_explicit_mantissa() >> (FPBits::FRACTION_LEN - pl_exp));
if constexpr (IsSignaling)
res = FPBits::signaling_nan(Sign::POS, v).get_val();
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index fb36c49216ba81..e10fc94ddfab35 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -441,6 +441,7 @@ add_math_entrypoint_object(setpayloadf128)
add_math_entrypoint_object(setpayloadsig)
add_math_entrypoint_object(setpayloadsigf)
+add_math_entrypoint_object(setpayloadsigl)
add_math_entrypoint_object(setpayloadsigf16)
add_math_entrypoint_object(setpayloadsigf128)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 602417386667f1..f71ff80eb328d9 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4523,6 +4523,18 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ setpayloadsigl
+ SRCS
+ setpayloadsigl.cpp
+ HDRS
+ ../setpayloadsigl.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
setpayloadsigf16
SRCS
diff --git a/libc/src/math/generic/setpayloadsigl.cpp b/libc/src/math/generic/setpayloadsigl.cpp
new file mode 100644
index 00000000000000..446fbf5d861390
--- /dev/null
+++ b/libc/src/math/generic/setpayloadsigl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadsigl function -------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/setpayloadsigl.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.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));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadsigl.h b/libc/src/math/setpayloadsigl.h
new file mode 100644
index 00000000000000..9bc47eed901975
--- /dev/null
+++ b/libc/src/math/setpayloadsigl.h
@@ -0,0 +1,20 @@
+//===-- 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_MATH_SETPAYLOADSIGL_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADSIGL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadsigl(long double *res, long double pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADSIGF_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 272295d3841a5a..466dce6d948f5a 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3981,6 +3981,18 @@ add_fp_unittest(
libc.src.math.setpayloadsigf
)
+add_fp_unittest(
+ setpayloadsigl_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ setpayloadsigl_test.cpp
+ HDRS
+ SetPayloadSigTest.h
+ DEPENDS
+ libc.src.math.setpayloadsigl
+)
+
add_fp_unittest(
setpayloadsigf16_test
SUITE
diff --git a/libc/test/src/math/smoke/setpayloadsigl_test.cpp b/libc/test/src/math/smoke/setpayloadsigl_test.cpp
new file mode 100644
index 00000000000000..6fc878c3f18a4c
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadsigl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadsigl --------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "SetPayloadSigTest.h"
+
+#include "src/math/setpayloadsigl.h"
+
+LIST_SETPAYLOADSIG_TESTS(long double, LIBC_NAMESPACE::setpayloadsigl)
>From b2bce67965e9a7eb48b5a74ab638aa477b9b2d13 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 20:04:31 -0700
Subject: [PATCH 4/5] format code
---
libc/src/__support/FPUtil/BasicOperations.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 8046bf0b508929..8131c9b663cfe4 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -377,7 +377,8 @@ setpayload(T &res, T pl) {
}
using StorageType = typename FPBits::StorageType;
- StorageType v(pl_bits.get_explicit_mantissa() >> (FPBits::FRACTION_LEN - pl_exp));
+ StorageType v(pl_bits.get_explicit_mantissa() >>
+ (FPBits::FRACTION_LEN - pl_exp));
if constexpr (IsSignaling)
res = FPBits::signaling_nan(Sign::POS, v).get_val();
>From cdc8818f6a25cba17710f13bfb0872a902948e40 Mon Sep 17 00:00:00 2001
From: Job Hernandez <hj93 at protonmail.com>
Date: Wed, 7 Aug 2024 20:47:59 -0700
Subject: [PATCH 5/5] add setpayloadl
---
libc/config/linux/aarch64/entrypoints.txt | 2 ++
libc/config/linux/arm/entrypoints.txt | 2 ++
libc/config/linux/riscv/entrypoints.txt | 2 ++
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/src/math/CMakeLists.txt | 1 +
libc/src/math/generic/CMakeLists.txt | 12 +++++++++++
libc/src/math/generic/setpayloadl.cpp | 20 +++++++++++++++++++
libc/src/math/setpayloadl.h | 20 +++++++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 12 +++++++++++
libc/test/src/math/smoke/SetPayloadTest.h | 2 +-
libc/test/src/math/smoke/setpayloadl_test.cpp | 13 ++++++++++++
11 files changed, 86 insertions(+), 1 deletion(-)
create mode 100644 libc/src/math/generic/setpayloadl.cpp
create mode 100644 libc/src/math/setpayloadl.h
create mode 100644 libc/test/src/math/smoke/setpayloadl_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index fcf2dd766bd2d5..f2ab6c0ba73d74 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -546,8 +546,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadl
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
+ libc.src.math.setpayloadsigl
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt
index 9d648b754579e9..9d3ab0c157aa81 100644
--- a/libc/config/linux/arm/entrypoints.txt
+++ b/libc/config/linux/arm/entrypoints.txt
@@ -376,8 +376,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadl
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
+ libc.src.math.setpayloadsigl
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index d98a7b43ec0ff9..a7deccb9ded988 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -549,8 +549,10 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadl
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
+ libc.src.math.setpayloadsigl
libc.src.math.sin
libc.src.math.sincos
libc.src.math.sincosf
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 39634081e0338d..6b16843e5027d7 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -549,6 +549,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.scalbnl
libc.src.math.setpayload
libc.src.math.setpayloadf
+ libc.src.math.setpayloadl
libc.src.math.setpayloadsig
libc.src.math.setpayloadsigf
libc.src.math.setpayloadsigl
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e10fc94ddfab35..56e9bb60c1e436 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -436,6 +436,7 @@ add_math_entrypoint_object(scalbnf128)
add_math_entrypoint_object(setpayload)
add_math_entrypoint_object(setpayloadf)
+add_math_entrypoint_object(setpayloadl)
add_math_entrypoint_object(setpayloadf16)
add_math_entrypoint_object(setpayloadf128)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index f71ff80eb328d9..e5f40673dd5f02 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4473,6 +4473,18 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ setpayloadl
+ SRCS
+ setpayloadl.cpp
+ HDRS
+ ../setpayloadl.h
+ DEPENDS
+ libc.src.__support.FPUtil.basic_operations
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
setpayloadf16
SRCS
diff --git a/libc/src/math/generic/setpayloadl.cpp b/libc/src/math/generic/setpayloadl.cpp
new file mode 100644
index 00000000000000..486f3f9272d564
--- /dev/null
+++ b/libc/src/math/generic/setpayloadl.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of setpayloadl function ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/math/setpayloadl.h"
+#include "src/__support/FPUtil/BasicOperations.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.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));
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/setpayloadl.h b/libc/src/math/setpayloadl.h
new file mode 100644
index 00000000000000..f0df62f8f22f5a
--- /dev/null
+++ b/libc/src/math/setpayloadl.h
@@ -0,0 +1,20 @@
+//===-- 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_MATH_SETPAYLOADL_H
+#define LLVM_LIBC_SRC_MATH_SETPAYLOADL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int setpayloadl(long double *res, long double pl);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADL_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 466dce6d948f5a..45e1c4c26cc147 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3933,6 +3933,18 @@ add_fp_unittest(
libc.src.math.setpayloadf
)
+add_fp_unittest(
+ setpayloadl_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ setpayloadl_test.cpp
+ HDRS
+ SetPayloadTest.h
+ DEPENDS
+ libc.src.math.setpayloadl
+)
+
add_fp_unittest(
setpayloadf16_test
SUITE
diff --git a/libc/test/src/math/smoke/SetPayloadTest.h b/libc/test/src/math/smoke/SetPayloadTest.h
index 4bea78f4230a9c..128d609f0632ac 100644
--- a/libc/test/src/math/smoke/SetPayloadTest.h
+++ b/libc/test/src/math/smoke/SetPayloadTest.h
@@ -65,7 +65,7 @@ class SetPayloadTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
// The following code is creating a NaN payload manually to prevent a
// conversion from BigInt to float128.
FPBits nan_payload_bits = FPBits::one();
- nan_payload_bits.set_biased_exponent(FPBits::SIG_LEN - 2 +
+ nan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 +
FPBits::EXP_BIAS);
nan_payload_bits.set_mantissa(FPBits::SIG_MASK - 3);
T nan_payload = nan_payload_bits.get_val();
diff --git a/libc/test/src/math/smoke/setpayloadl_test.cpp b/libc/test/src/math/smoke/setpayloadl_test.cpp
new file mode 100644
index 00000000000000..45bc6fd2bb9fdf
--- /dev/null
+++ b/libc/test/src/math/smoke/setpayloadl_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for setpayloadl -----------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "SetPayloadTest.h"
+
+#include "src/math/setpayloadl.h"
+
+LIST_SETPAYLOAD_TESTS(long double, LIBC_NAMESPACE::setpayloadl)
More information about the libc-commits
mailing list