From d04e1dcccab4bd99c2e4ea8b619040066c45b8d5 Mon Sep 17 00:00:00 2001 From: Job Hernandez Date: Mon, 29 Jul 2024 21:19:00 -0700 Subject: [PATCH 1/3] add setpayload{f, f128} --- libc/config/linux/aarch64/entrypoints.txt | 3 ++ libc/config/linux/x86_64/entrypoints.txt | 3 ++ libc/spec/stdc.td | 5 ++- libc/src/math/CMakeLists.txt | 3 ++ libc/src/math/generic/CMakeLists.txt | 37 +++++++++++++++++++ libc/src/math/generic/setpayload.cpp | 20 ++++++++++ libc/src/math/generic/setpayloadf.cpp | 20 ++++++++++ libc/src/math/generic/setpayloadf128.cpp | 20 ++++++++++ libc/src/math/setpayload.h | 20 ++++++++++ libc/src/math/setpayloadf.h | 20 ++++++++++ libc/src/math/setpayloadf128.h | 21 +++++++++++ libc/test/src/math/smoke/CMakeLists.txt | 36 ++++++++++++++++++ libc/test/src/math/smoke/setpayload_test.cpp | 13 +++++++ .../src/math/smoke/setpayloadf128_test.cpp | 13 +++++++ libc/test/src/math/smoke/setpayloadf_test.cpp | 13 +++++++ 15 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 libc/src/math/generic/setpayload.cpp create mode 100644 libc/src/math/generic/setpayloadf.cpp create mode 100644 libc/src/math/generic/setpayloadf128.cpp create mode 100644 libc/src/math/setpayload.h create mode 100644 libc/src/math/setpayloadf.h create mode 100644 libc/src/math/setpayloadf128.h create mode 100644 libc/test/src/math/smoke/setpayload_test.cpp create mode 100644 libc/test/src/math/smoke/setpayloadf128_test.cpp create mode 100644 libc/test/src/math/smoke/setpayloadf_test.cpp diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index cfc280da27f4b..cd7138d0652d8 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -508,6 +508,8 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbn libc.src.math.scalbnf libc.src.math.scalbnl + libc.src.math.setpayload + libc.src.math.setpayloadf libc.src.math.sin libc.src.math.sincos libc.src.math.sincosf @@ -645,6 +647,7 @@ if(LIBC_TYPES_HAS_FLOAT128) libc.src.math.roundf128 libc.src.math.roundevenf128 libc.src.math.scalbnf128 + libc.src.math.setpayloadf128 libc.src.math.sqrtf128 libc.src.math.totalordermagf128 libc.src.math.truncf128 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index fa656d946eceb..a4a2b1878a1b8 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -530,6 +530,8 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbn libc.src.math.scalbnf libc.src.math.scalbnl + libc.src.math.setpayload + libc.src.math.setpayloadf libc.src.math.sin libc.src.math.sincos libc.src.math.sincosf @@ -688,6 +690,7 @@ if(LIBC_TYPES_HAS_FLOAT128) libc.src.math.roundevenf128 libc.src.math.roundf128 libc.src.math.scalbnf128 + libc.src.math.setpayloadf128 libc.src.math.sqrtf128 libc.src.math.totalordermagf128 libc.src.math.truncf128 diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 9c84accd72cff..1e4c5880f83d5 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -730,8 +730,11 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"totalordermagf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, GuardedFunctionSpec<"getpayloadf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, - + + GuardedFunctionSpec<"setpayload", RetValSpec, [ArgSpec, ArgSpec], + GuardedFunctionSpec<"setpayloadf", RetValSpec, [ArgSpec, ArgSpec], GuardedFunctionSpec<"setpayloadf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"setpayloadf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, GuardedFunctionSpec<"setpayloadsigf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index d70af33522d2b..a724cd23e237b 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -405,7 +405,10 @@ add_math_entrypoint_object(scalbnl) add_math_entrypoint_object(scalbnf16) add_math_entrypoint_object(scalbnf128) +add_math_entrypoint_object(setpayload) +add_math_entrypoint_object(setpayloadf) add_math_entrypoint_object(setpayloadf16) +add_math_entrypoint_object(setpayloadf128) add_math_entrypoint_object(setpayloadsigf16) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 27b5b945e278c..f2ae586133e94 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -4059,6 +4059,30 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + setpayload + SRCS + setpayload.cpp + HDRS + ../setpayload.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + +add_entrypoint_object( + setpayloadf + SRCS + setpayloadf.cpp + HDRS + ../setpayloadf.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( setpayloadf16 SRCS @@ -4072,6 +4096,19 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + setpayloadf128 + SRCS + setpayloadf128.cpp + HDRS + ../setpayloadf128.h + DEPENDS + libc.src.__support.macros.properties.types + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( setpayloadsigf16 SRCS diff --git a/libc/src/math/generic/setpayload.cpp b/libc/src/math/generic/setpayload.cpp new file mode 100644 index 0000000000000..bef786aeab075 --- /dev/null +++ b/libc/src/math/generic/setpayload.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of setpayload 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/setpayload.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, setpayload, (double *res, double pl)) { + return static_cast(fputil::setpayload(*res, pl)); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/setpayloadf.cpp b/libc/src/math/generic/setpayloadf.cpp new file mode 100644 index 0000000000000..50d2ffd22fb77 --- /dev/null +++ b/libc/src/math/generic/setpayloadf.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of setpayloadf 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/setpayloadf.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, setpayloadf, (float *res, float pl)) { + return static_cast(fputil::setpayload(*res, pl)); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp new file mode 100644 index 0000000000000..a262c8e21bb1b --- /dev/null +++ b/libc/src/math/generic/setpayloadf128.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of setpayloadf128 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/setpayloadf128.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, setpayloadf128, (float128 *res, float128 pl)) { + return static_cast(fputil::setpayload(*res, pl)); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/setpayload.h b/libc/src/math/setpayload.h new file mode 100644 index 0000000000000..3f30673e6c564 --- /dev/null +++ b/libc/src/math/setpayload.h @@ -0,0 +1,20 @@ +//===-- Implementation header for setpayload --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_SETPAYLOAD_H +#define LLVM_LIBC_SRC_MATH_SETPAYLOAD_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +int setpayload(double *res, double pl); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_SETPAYLOAD_H diff --git a/libc/src/math/setpayloadf.h b/libc/src/math/setpayloadf.h new file mode 100644 index 0000000000000..95544c8df83b8 --- /dev/null +++ b/libc/src/math/setpayloadf.h @@ -0,0 +1,20 @@ +//===-- Implementation header for setpayloadf -------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADF_H +#define LLVM_LIBC_SRC_MATH_SETPAYLOADF_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +int setpayloadf(float *res, float pl); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADF_H diff --git a/libc/src/math/setpayloadf128.h b/libc/src/math/setpayloadf128.h new file mode 100644 index 0000000000000..e46aef38256db --- /dev/null +++ b/libc/src/math/setpayloadf128.h @@ -0,0 +1,21 @@ +//===-- Implementation header for setpayloadf128 ----------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H +#define LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H + +#include "src/__support/macros/config.h" +#include "src/__support/macros/properties/types.h" + +namespace LIBC_NAMESPACE_DECL { + +int setpayloadf128(float128 *res, float128 pl); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 8b2942343409d..7e631d9499b5a 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3725,6 +3725,30 @@ add_fp_unittest( libc.src.math.getpayloadf16 ) +add_fp_unittest( + setpayload_test + SUITE + libc-math-smoke-tests + SRCS + setpayload_test.cpp + HDRS + SetPayloadTest.h + DEPENDS + libc.src.math.setpayload +) + +add_fp_unittest( + setpayloadf_test + SUITE + libc-math-smoke-tests + SRCS + setpayloadf_test.cpp + HDRS + SetPayloadTest.h + DEPENDS + libc.src.math.setpayloadf +) + add_fp_unittest( setpayloadf16_test SUITE @@ -3737,6 +3761,18 @@ add_fp_unittest( libc.src.math.setpayloadf16 ) +add_fp_unittest( + setpayloadf128_test + SUITE + libc-math-smoke-tests + SRCS + setpayloadf128_test.cpp + HDRS + SetPayloadTest.h + DEPENDS + libc.src.math.setpayloadf128 +) + add_fp_unittest( setpayloadsigf16_test SUITE diff --git a/libc/test/src/math/smoke/setpayload_test.cpp b/libc/test/src/math/smoke/setpayload_test.cpp new file mode 100644 index 0000000000000..e41b3f86c5f17 --- /dev/null +++ b/libc/test/src/math/smoke/setpayload_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for setpayload ------------------------------------------===// +// +// 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/setpayload.h" + +LIST_SETPAYLOAD_TESTS(double, LIBC_NAMESPACE::setpayload) diff --git a/libc/test/src/math/smoke/setpayloadf128_test.cpp b/libc/test/src/math/smoke/setpayloadf128_test.cpp new file mode 100644 index 0000000000000..4b17bfee093c0 --- /dev/null +++ b/libc/test/src/math/smoke/setpayloadf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for setpayloadf128 --------------------------------------===// +// +// 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/setpayloadf128.h" + +LIST_SETPAYLOAD_TESTS(float128, LIBC_NAMESPACE::setpayloadf128) diff --git a/libc/test/src/math/smoke/setpayloadf_test.cpp b/libc/test/src/math/smoke/setpayloadf_test.cpp new file mode 100644 index 0000000000000..51e285f171843 --- /dev/null +++ b/libc/test/src/math/smoke/setpayloadf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for setpayloadf -----------------------------------------===// +// +// 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/setpayloadf.h" + +LIST_SETPAYLOAD_TESTS(float, LIBC_NAMESPACE::setpayloadf) From bd7221007423cb57fedfab35729ef2061cd2c31b Mon Sep 17 00:00:00 2001 From: Job Hernandez Date: Mon, 29 Jul 2024 21:19:23 -0700 Subject: [PATCH 2/3] format code --- libc/src/math/generic/setpayload.cpp | 2 +- libc/src/math/generic/setpayloadf128.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/src/math/generic/setpayload.cpp b/libc/src/math/generic/setpayload.cpp index bef786aeab075..7e7078c95bdce 100644 --- a/libc/src/math/generic/setpayload.cpp +++ b/libc/src/math/generic/setpayload.cpp @@ -14,7 +14,7 @@ namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(int, setpayload, (double *res, double pl)) { - return static_cast(fputil::setpayload(*res, pl)); + return static_cast(fputil::setpayload(*res, pl)); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/generic/setpayloadf128.cpp b/libc/src/math/generic/setpayloadf128.cpp index a262c8e21bb1b..a50e5efd82ceb 100644 --- a/libc/src/math/generic/setpayloadf128.cpp +++ b/libc/src/math/generic/setpayloadf128.cpp @@ -13,7 +13,7 @@ namespace LIBC_NAMESPACE_DECL { -LLVM_LIBC_FUNCTION(int, setpayloadf128, (float128 *res, float128 pl)) { +LLVM_LIBC_FUNCTION(int, setpayloadf128, (float128 * res, float128 pl)) { return static_cast(fputil::setpayload(*res, pl)); } From 89036ec7504e9871525eefefff33bd7de0264764 Mon Sep 17 00:00:00 2001 From: Job Hernandez Date: Tue, 30 Jul 2024 10:06:51 -0700 Subject: [PATCH 3/3] address review --- libc/config/linux/arm/entrypoints.txt | 2 ++ libc/config/linux/riscv/entrypoints.txt | 2 ++ libc/docs/math/index.rst | 2 +- libc/spec/stdc.td | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 8e77105fdb13e..9e42f4a2f858f 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -363,6 +363,8 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbn libc.src.math.scalbnf libc.src.math.scalbnl + libc.src.math.setpayload + libc.src.math.setpayloadf 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 04b8b3bc4ce39..8347884878a01 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -530,6 +530,8 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.scalbn libc.src.math.scalbnf libc.src.math.scalbnl + libc.src.math.setpayload + libc.src.math.setpayloadf 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 9f88b4d9a44b3..46f13b20b353e 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -224,7 +224,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| setpayload | | | | |check| | | F.10.13.2 | N/A | +| setpayload | |check| | |check| | | |check| | |check| | F.10.13.2 | N/A | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | setpayloadsig | | | | |check| | | F.10.13.3 | N/A | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 1e4c5880f83d5..590cf2d0fb2dc 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -731,8 +731,8 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"getpayloadf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, - GuardedFunctionSpec<"setpayload", RetValSpec, [ArgSpec, ArgSpec], - GuardedFunctionSpec<"setpayloadf", RetValSpec, [ArgSpec, ArgSpec], + FunctionSpec<"setpayload", RetValSpec, [ArgSpec, ArgSpec], + FunctionSpec<"setpayloadf", RetValSpec, [ArgSpec, ArgSpec], GuardedFunctionSpec<"setpayloadf16", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"setpayloadf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">,