diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 7677770c495739..b705b82c70f399 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -463,6 +463,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.fsqrtl libc.src.math.getpayload libc.src.math.getpayloadf + libc.src.math.getpayloadl libc.src.math.hypot libc.src.math.hypotf libc.src.math.ilogb diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt index 8a214109f4abcd..36e940af4fb6ba 100644 --- a/libc/config/linux/arm/entrypoints.txt +++ b/libc/config/linux/arm/entrypoints.txt @@ -299,6 +299,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.fromfpxl libc.src.math.getpayload libc.src.math.getpayloadf + libc.src.math.getpayloadl libc.src.math.hypot libc.src.math.hypotf libc.src.math.ilogb diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index 8e2eb36f1b89a9..f117c5fc608fae 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -466,6 +466,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.fsqrtl libc.src.math.getpayload libc.src.math.getpayloadf + libc.src.math.getpayloadl libc.src.math.hypot libc.src.math.hypotf libc.src.math.ilogb diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 2b76487218b13c..c2bde60c0285dd 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -466,6 +466,7 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.fsqrtl libc.src.math.getpayload libc.src.math.getpayloadf + libc.src.math.getpayloadl libc.src.math.hypot libc.src.math.hypotf libc.src.math.ilogb diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 92e5fb700d536f..315192027d914d 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -178,7 +178,7 @@ Basic Operations +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | fsub | N/A | | | N/A | | 7.12.14.2 | F.10.11 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ -| getpayload | |check| | |check| | | |check| | |check| | F.10.13.1 | N/A | +| getpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ | ilogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 | +------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+ diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml index 79d0e9863e9ae8..62cde78fcc1588 100644 --- a/libc/newhdrgen/yaml/math.yaml +++ b/libc/newhdrgen/yaml/math.yaml @@ -1540,6 +1540,24 @@ functions: - type: int - type: unsigned int guard: LIBC_TYPES_HAS_FLOAT16 + - name: getpayload + standards: + - stdc + return_type: double + arguments: + - type: double * + - name: getpayloadl + standards: + - stdc + return_type: long double + arguments: + - type: long double * + - name: getpayloadf + standards: + - stdc + return_type: float + arguments: + - type: float * - name: getpayloadf16 standards: - stdc @@ -1547,6 +1565,13 @@ functions: arguments: - type: _Float16 * guard: LIBC_TYPES_HAS_FLOAT16 + - name: getpayloadf128 + standards: + - stdc + return_type: float128 + arguments: + - type: float128 * + guard: LIBC_TYPES_HAS_FLOAT128 - name: ilogbf16 standards: - stdc diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index ca7bc5c9b57448..e11f0db507b163 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -746,7 +746,8 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"totalordermagf128", RetValSpec, [ArgSpec, ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, FunctionSpec<"getpayload", RetValSpec, [ArgSpec]>, - FunctionSpec<"getpayloadf", RetValSpec, [ArgSpec]>, + FunctionSpec<"getpayloadf", RetValSpec, [ArgSpec]>, + FunctionSpec<"getpayloadl", RetValSpec, [ArgSpec]>, GuardedFunctionSpec<"getpayloadf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"getpayloadf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 6accddb7e5e84f..a1afed59a7b134 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -274,6 +274,7 @@ add_math_entrypoint_object(fromfpxf128) add_math_entrypoint_object(getpayload) add_math_entrypoint_object(getpayloadf) +add_math_entrypoint_object(getpayloadl) add_math_entrypoint_object(getpayloadf16) add_math_entrypoint_object(getpayloadf128) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 445c0702439998..fecbcf41678e88 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -4336,6 +4336,18 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + getpayloadl + SRCS + getpayloadl.cpp + HDRS + ../getpayloadl.h + DEPENDS + libc.src.__support.FPUtil.basic_operations + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( getpayloadf16 SRCS diff --git a/libc/src/math/generic/getpayloadl.cpp b/libc/src/math/generic/getpayloadl.cpp new file mode 100644 index 00000000000000..028dc1e2611c08 --- /dev/null +++ b/libc/src/math/generic/getpayloadl.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of getpayloadl 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/getpayloadl.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(long double, getpayloadl, (const long double *x)) { + return fputil::getpayload(*x); +} + +} // namespace LIBC_NAMESPACE_DECL diff --git a/libc/src/math/getpayloadl.h b/libc/src/math/getpayloadl.h new file mode 100644 index 00000000000000..1ae9f86c19e005 --- /dev/null +++ b/libc/src/math/getpayloadl.h @@ -0,0 +1,20 @@ +//===-- Implementation header for getpayloadl -------------------*- 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_GETPAYLOADL_H +#define LLVM_LIBC_SRC_MATH_GETPAYLOADL_H + +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { + +long double getpayloadl(const long double *x); + +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC_MATH_GETPAYLOADL_H diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index e1c95b6196a8d6..007c3346e0568c 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3861,6 +3861,18 @@ add_fp_unittest( libc.src.math.getpayloadf ) +add_fp_unittest( + getpayloadl_test + SUITE + libc-math-smoke-tests + SRCS + getpayloadl_test.cpp + HDRS + GetPayloadTest.h + DEPENDS + libc.src.math.getpayloadl +) + add_fp_unittest( getpayloadf16_test SUITE diff --git a/libc/test/src/math/smoke/GetPayloadTest.h b/libc/test/src/math/smoke/GetPayloadTest.h index 922a2f04f6fb3c..d904571269e137 100644 --- a/libc/test/src/math/smoke/GetPayloadTest.h +++ b/libc/test/src/math/smoke/GetPayloadTest.h @@ -39,10 +39,10 @@ class GetPayloadTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { EXPECT_FP_EQ(T(0.0), funcWrapper(func, neg_aNaN)); // Essentially this: - // T default_snan_payload = StorageType(1) << (FPBits::SIG_LEN - 2); + // T default_snan_payload = StorageType(1) << (FPBits::FRACTION_LEN - 2); // but supports StorageType being a BigInt. FPBits default_snan_payload_bits = FPBits::one(); - default_snan_payload_bits.set_biased_exponent(FPBits::SIG_LEN - 2 + + default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 + FPBits::EXP_BIAS); T default_snan_payload = default_snan_payload_bits.get_val(); diff --git a/libc/test/src/math/smoke/getpayloadl_test.cpp b/libc/test/src/math/smoke/getpayloadl_test.cpp new file mode 100644 index 00000000000000..d783548c670326 --- /dev/null +++ b/libc/test/src/math/smoke/getpayloadl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for getpayloadl -----------------------------------------===// +// +// 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 "GetPayloadTest.h" + +#include "src/math/getpayloadl.h" + +LIST_GETPAYLOAD_TESTS(long double, LIBC_NAMESPACE::getpayloadl)