[libc-commits] [libc] [libc][math][c23] Add entrypoints and tests for setpayloadsig{, f, f128} (PR #102413)
Job Henandez Lara via libc-commits
libc-commits at lists.llvm.org
Wed Aug 7 20:04:48 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/4] [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 cdc93f437bf5f..fcf2dd766bd2d 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 5d33faad0cb0b..9d648b754579e 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 66dd6e261f3d6..d98a7b43ec0ff 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 ace1b1b08eb12..24ffb52ee00d7 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 c665ce397f9b7..0df1d5ec4b5fe 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 12410c1d41e8c..ae19811a6a0d3 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 6f974e4384a53..4d586de02e130 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 a0bd5269169fa..fb36c49216ba8 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 be5cc2e02635a..602417386667f 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 0000000000000..fa8b165ca1277
--- /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 0000000000000..ec9d98f2123a8
--- /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 0000000000000..d98e4d1fc8b1c
--- /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 0000000000000..8059e6f018210
--- /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 0000000000000..e7a0175682ea7
--- /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 0000000000000..4e036b9c8ba00
--- /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 6becaa569e62a..272295d3841a5 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 0000000000000..4a7dea73bbc8f
--- /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 0000000000000..ea7d0268b3a29
--- /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 0000000000000..dd8ca2fe86ece
--- /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/4] 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 d98e4d1fc8b1c..97f6a36e229ec 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/4] 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 24ffb52ee00d7..39634081e0338 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 0df1d5ec4b5fe..c6c5591ca63d2 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 ae19811a6a0d3..b456bc375af65 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 4d586de02e130..d0eb166bd854a 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 d68f3ae6a26bb..8046bf0b50892 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 fb36c49216ba8..e10fc94ddfab3 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 602417386667f..f71ff80eb328d 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 0000000000000..446fbf5d86139
--- /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 0000000000000..9bc47eed90197
--- /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 272295d3841a5..466dce6d948f5 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 0000000000000..6fc878c3f18a4
--- /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/4] 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 8046bf0b50892..8131c9b663cfe 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();
More information about the libc-commits
mailing list