Skip to content

Commit

Permalink
[libc][math] Add getpayloadl function. (#102214)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jobhdez authored Aug 7, 2024
1 parent a4900f0 commit e3778a5
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 4 deletions.
1 change: 1 addition & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
Expand Down
25 changes: 25 additions & 0 deletions libc/newhdrgen/yaml/math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1540,13 +1540,38 @@ 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
return_type: _Float16
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
Expand Down
3 changes: 2 additions & 1 deletion libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"totalordermagf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"getpayload", RetValSpec<DoubleType>, [ArgSpec<DoublePtr>]>,
FunctionSpec<"getpayloadf", RetValSpec<FloatType>, [ArgSpec<FloatPtr>]>,
FunctionSpec<"getpayloadf", RetValSpec<FloatType>, [ArgSpec<FloatPtr>]>,
FunctionSpec<"getpayloadl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoublePtr>]>,
GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,

Expand Down
1 change: 1 addition & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/getpayloadl.cpp
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions libc/src/math/getpayloadl.h
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/math/smoke/GetPayloadTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/getpayloadl_test.cpp
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e3778a5

Please sign in to comment.