Skip to content

Commit e3778a5

Browse files
author
Job Henandez Lara
authored
[libc][math] Add getpayloadl function. (llvm#102214)
1 parent a4900f0 commit e3778a5

File tree

14 files changed

+112
-4
lines changed

14 files changed

+112
-4
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ set(TARGET_LIBM_ENTRYPOINTS
463463
libc.src.math.fsqrtl
464464
libc.src.math.getpayload
465465
libc.src.math.getpayloadf
466+
libc.src.math.getpayloadl
466467
libc.src.math.hypot
467468
libc.src.math.hypotf
468469
libc.src.math.ilogb

libc/config/linux/arm/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ set(TARGET_LIBM_ENTRYPOINTS
299299
libc.src.math.fromfpxl
300300
libc.src.math.getpayload
301301
libc.src.math.getpayloadf
302+
libc.src.math.getpayloadl
302303
libc.src.math.hypot
303304
libc.src.math.hypotf
304305
libc.src.math.ilogb

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ set(TARGET_LIBM_ENTRYPOINTS
466466
libc.src.math.fsqrtl
467467
libc.src.math.getpayload
468468
libc.src.math.getpayloadf
469+
libc.src.math.getpayloadl
469470
libc.src.math.hypot
470471
libc.src.math.hypotf
471472
libc.src.math.ilogb

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ set(TARGET_LIBM_ENTRYPOINTS
466466
libc.src.math.fsqrtl
467467
libc.src.math.getpayload
468468
libc.src.math.getpayloadf
469+
libc.src.math.getpayloadl
469470
libc.src.math.hypot
470471
libc.src.math.hypotf
471472
libc.src.math.ilogb

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Basic Operations
178178
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
179179
| fsub | N/A | | | N/A | | 7.12.14.2 | F.10.11 |
180180
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
181-
| getpayload | |check| | |check| | | |check| | |check| | F.10.13.1 | N/A |
181+
| getpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.1 | N/A |
182182
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
183183
| ilogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
184184
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/newhdrgen/yaml/math.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,13 +1540,38 @@ functions:
15401540
- type: int
15411541
- type: unsigned int
15421542
guard: LIBC_TYPES_HAS_FLOAT16
1543+
- name: getpayload
1544+
standards:
1545+
- stdc
1546+
return_type: double
1547+
arguments:
1548+
- type: double *
1549+
- name: getpayloadl
1550+
standards:
1551+
- stdc
1552+
return_type: long double
1553+
arguments:
1554+
- type: long double *
1555+
- name: getpayloadf
1556+
standards:
1557+
- stdc
1558+
return_type: float
1559+
arguments:
1560+
- type: float *
15431561
- name: getpayloadf16
15441562
standards:
15451563
- stdc
15461564
return_type: _Float16
15471565
arguments:
15481566
- type: _Float16 *
15491567
guard: LIBC_TYPES_HAS_FLOAT16
1568+
- name: getpayloadf128
1569+
standards:
1570+
- stdc
1571+
return_type: float128
1572+
arguments:
1573+
- type: float128 *
1574+
guard: LIBC_TYPES_HAS_FLOAT128
15501575
- name: ilogbf16
15511576
standards:
15521577
- stdc

libc/spec/stdc.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,8 @@ def StdC : StandardSpec<"stdc"> {
746746
GuardedFunctionSpec<"totalordermagf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
747747

748748
FunctionSpec<"getpayload", RetValSpec<DoubleType>, [ArgSpec<DoublePtr>]>,
749-
FunctionSpec<"getpayloadf", RetValSpec<FloatType>, [ArgSpec<FloatPtr>]>,
749+
FunctionSpec<"getpayloadf", RetValSpec<FloatType>, [ArgSpec<FloatPtr>]>,
750+
FunctionSpec<"getpayloadl", RetValSpec<LongDoubleType>, [ArgSpec<LongDoublePtr>]>,
750751
GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
751752
GuardedFunctionSpec<"getpayloadf128", RetValSpec<Float128Type>, [ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
752753

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ add_math_entrypoint_object(fromfpxf128)
274274

275275
add_math_entrypoint_object(getpayload)
276276
add_math_entrypoint_object(getpayloadf)
277+
add_math_entrypoint_object(getpayloadl)
277278
add_math_entrypoint_object(getpayloadf16)
278279
add_math_entrypoint_object(getpayloadf128)
279280

libc/src/math/generic/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,6 +4336,18 @@ add_entrypoint_object(
43364336
-O3
43374337
)
43384338

4339+
add_entrypoint_object(
4340+
getpayloadl
4341+
SRCS
4342+
getpayloadl.cpp
4343+
HDRS
4344+
../getpayloadl.h
4345+
DEPENDS
4346+
libc.src.__support.FPUtil.basic_operations
4347+
COMPILE_OPTIONS
4348+
-O3
4349+
)
4350+
43394351
add_entrypoint_object(
43404352
getpayloadf16
43414353
SRCS

libc/src/math/generic/getpayloadl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of getpayloadl function ----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/math/getpayloadl.h"
10+
#include "src/__support/FPUtil/BasicOperations.h"
11+
#include "src/__support/common.h"
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
LLVM_LIBC_FUNCTION(long double, getpayloadl, (const long double *x)) {
17+
return fputil::getpayload(*x);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/getpayloadl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for getpayloadl -------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_GETPAYLOADL_H
10+
#define LLVM_LIBC_SRC_MATH_GETPAYLOADL_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
long double getpayloadl(const long double *x);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_GETPAYLOADL_H

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,6 +3861,18 @@ add_fp_unittest(
38613861
libc.src.math.getpayloadf
38623862
)
38633863

3864+
add_fp_unittest(
3865+
getpayloadl_test
3866+
SUITE
3867+
libc-math-smoke-tests
3868+
SRCS
3869+
getpayloadl_test.cpp
3870+
HDRS
3871+
GetPayloadTest.h
3872+
DEPENDS
3873+
libc.src.math.getpayloadl
3874+
)
3875+
38643876
add_fp_unittest(
38653877
getpayloadf16_test
38663878
SUITE

libc/test/src/math/smoke/GetPayloadTest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class GetPayloadTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
3939
EXPECT_FP_EQ(T(0.0), funcWrapper(func, neg_aNaN));
4040

4141
// Essentially this:
42-
// T default_snan_payload = StorageType(1) << (FPBits::SIG_LEN - 2);
42+
// T default_snan_payload = StorageType(1) << (FPBits::FRACTION_LEN - 2);
4343
// but supports StorageType being a BigInt.
4444
FPBits default_snan_payload_bits = FPBits::one();
45-
default_snan_payload_bits.set_biased_exponent(FPBits::SIG_LEN - 2 +
45+
default_snan_payload_bits.set_biased_exponent(FPBits::FRACTION_LEN - 2 +
4646
FPBits::EXP_BIAS);
4747
T default_snan_payload = default_snan_payload_bits.get_val();
4848

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for getpayloadl -----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "GetPayloadTest.h"
10+
11+
#include "src/math/getpayloadl.h"
12+
13+
LIST_GETPAYLOAD_TESTS(long double, LIBC_NAMESPACE::getpayloadl)

0 commit comments

Comments
 (0)