Skip to content

Commit 546e4a2

Browse files
author
Job Henandez Lara
authored
[libc][math][c23] Add entrypoints and tests for setpayload{,f,f128} (#101122)
1 parent ebdcb76 commit 546e4a2

18 files changed

+251
-2
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ set(TARGET_LIBM_ENTRYPOINTS
508508
libc.src.math.scalbn
509509
libc.src.math.scalbnf
510510
libc.src.math.scalbnl
511+
libc.src.math.setpayload
512+
libc.src.math.setpayloadf
511513
libc.src.math.sin
512514
libc.src.math.sincos
513515
libc.src.math.sincosf
@@ -647,6 +649,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
647649
libc.src.math.roundf128
648650
libc.src.math.roundevenf128
649651
libc.src.math.scalbnf128
652+
libc.src.math.setpayloadf128
650653
libc.src.math.sqrtf128
651654
libc.src.math.totalorderf128
652655
libc.src.math.totalordermagf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ set(TARGET_LIBM_ENTRYPOINTS
363363
libc.src.math.scalbn
364364
libc.src.math.scalbnf
365365
libc.src.math.scalbnl
366+
libc.src.math.setpayload
367+
libc.src.math.setpayloadf
366368
libc.src.math.sin
367369
libc.src.math.sincos
368370
libc.src.math.sincosf

libc/config/linux/riscv/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ set(TARGET_LIBM_ENTRYPOINTS
530530
libc.src.math.scalbn
531531
libc.src.math.scalbnf
532532
libc.src.math.scalbnl
533+
libc.src.math.setpayload
534+
libc.src.math.setpayloadf
533535
libc.src.math.sin
534536
libc.src.math.sincos
535537
libc.src.math.sincosf

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,8 @@ set(TARGET_LIBM_ENTRYPOINTS
530530
libc.src.math.scalbn
531531
libc.src.math.scalbnf
532532
libc.src.math.scalbnl
533+
libc.src.math.setpayload
534+
libc.src.math.setpayloadf
533535
libc.src.math.sin
534536
libc.src.math.sincos
535537
libc.src.math.sincosf
@@ -691,6 +693,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
691693
libc.src.math.roundevenf128
692694
libc.src.math.roundf128
693695
libc.src.math.scalbnf128
696+
libc.src.math.setpayloadf128
694697
libc.src.math.sqrtf128
695698
libc.src.math.totalorderf128
696699
libc.src.math.totalordermagf128

libc/docs/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Basic Operations
224224
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
225225
| scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
226226
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
227-
| setpayload | | | | |check| | | F.10.13.2 | N/A |
227+
| setpayload | |check| | |check| | | |check| | |check| | F.10.13.2 | N/A |
228228
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
229229
| setpayloadsig | | | | |check| | | F.10.13.3 | N/A |
230230
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/spec/stdc.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,11 @@ def StdC : StandardSpec<"stdc"> {
734734
GuardedFunctionSpec<"totalordermagf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Ptr>], "LIBC_TYPES_HAS_FLOAT128">,
735735

736736
GuardedFunctionSpec<"getpayloadf16", RetValSpec<Float16Type>, [ArgSpec<Float16Ptr>], "LIBC_TYPES_HAS_FLOAT16">,
737-
737+
738+
FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>],
739+
FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>],
738740
GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
741+
GuardedFunctionSpec<"setpayloadf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
739742

740743
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
741744

libc/src/math/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ add_math_entrypoint_object(scalbnl)
406406
add_math_entrypoint_object(scalbnf16)
407407
add_math_entrypoint_object(scalbnf128)
408408

409+
add_math_entrypoint_object(setpayload)
410+
add_math_entrypoint_object(setpayloadf)
409411
add_math_entrypoint_object(setpayloadf16)
412+
add_math_entrypoint_object(setpayloadf128)
410413

411414
add_math_entrypoint_object(setpayloadsigf16)
412415

libc/src/math/generic/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4116,6 +4116,30 @@ add_entrypoint_object(
41164116
-O3
41174117
)
41184118

4119+
add_entrypoint_object(
4120+
setpayload
4121+
SRCS
4122+
setpayload.cpp
4123+
HDRS
4124+
../setpayload.h
4125+
DEPENDS
4126+
libc.src.__support.FPUtil.basic_operations
4127+
COMPILE_OPTIONS
4128+
-O3
4129+
)
4130+
4131+
add_entrypoint_object(
4132+
setpayloadf
4133+
SRCS
4134+
setpayloadf.cpp
4135+
HDRS
4136+
../setpayloadf.h
4137+
DEPENDS
4138+
libc.src.__support.FPUtil.basic_operations
4139+
COMPILE_OPTIONS
4140+
-O3
4141+
)
4142+
41194143
add_entrypoint_object(
41204144
setpayloadf16
41214145
SRCS
@@ -4129,6 +4153,19 @@ add_entrypoint_object(
41294153
-O3
41304154
)
41314155

4156+
add_entrypoint_object(
4157+
setpayloadf128
4158+
SRCS
4159+
setpayloadf128.cpp
4160+
HDRS
4161+
../setpayloadf128.h
4162+
DEPENDS
4163+
libc.src.__support.macros.properties.types
4164+
libc.src.__support.FPUtil.basic_operations
4165+
COMPILE_OPTIONS
4166+
-O3
4167+
)
4168+
41324169
add_entrypoint_object(
41334170
setpayloadsigf16
41344171
SRCS

libc/src/math/generic/setpayload.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of setpayload 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/setpayload.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(int, setpayload, (double *res, double pl)) {
17+
return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/generic/setpayloadf.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of setpayloadf 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/setpayloadf.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(int, setpayloadf, (float *res, float pl)) {
17+
return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of setpayloadf128 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/setpayloadf128.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(int, setpayloadf128, (float128 * res, float128 pl)) {
17+
return static_cast<int>(fputil::setpayload</*IsSignaling=*/false>(*res, pl));
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/setpayload.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for setpayload --------------------*- 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_SETPAYLOAD_H
10+
#define LLVM_LIBC_SRC_MATH_SETPAYLOAD_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int setpayload(double *res, double pl);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_SETPAYLOAD_H

libc/src/math/setpayloadf.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for setpayloadf -------------------*- 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_SETPAYLOADF_H
10+
#define LLVM_LIBC_SRC_MATH_SETPAYLOADF_H
11+
12+
#include "src/__support/macros/config.h"
13+
14+
namespace LIBC_NAMESPACE_DECL {
15+
16+
int setpayloadf(float *res, float pl);
17+
18+
} // namespace LIBC_NAMESPACE_DECL
19+
20+
#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADF_H

libc/src/math/setpayloadf128.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for setpayloadf128 ----------------*- 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_SETPAYLOADF128_H
10+
#define LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int setpayloadf128(float128 *res, float128 pl);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_SETPAYLOADF128_H

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,6 +3774,30 @@ add_fp_unittest(
37743774
libc.src.math.getpayloadf16
37753775
)
37763776

3777+
add_fp_unittest(
3778+
setpayload_test
3779+
SUITE
3780+
libc-math-smoke-tests
3781+
SRCS
3782+
setpayload_test.cpp
3783+
HDRS
3784+
SetPayloadTest.h
3785+
DEPENDS
3786+
libc.src.math.setpayload
3787+
)
3788+
3789+
add_fp_unittest(
3790+
setpayloadf_test
3791+
SUITE
3792+
libc-math-smoke-tests
3793+
SRCS
3794+
setpayloadf_test.cpp
3795+
HDRS
3796+
SetPayloadTest.h
3797+
DEPENDS
3798+
libc.src.math.setpayloadf
3799+
)
3800+
37773801
add_fp_unittest(
37783802
setpayloadf16_test
37793803
SUITE
@@ -3786,6 +3810,18 @@ add_fp_unittest(
37863810
libc.src.math.setpayloadf16
37873811
)
37883812

3813+
add_fp_unittest(
3814+
setpayloadf128_test
3815+
SUITE
3816+
libc-math-smoke-tests
3817+
SRCS
3818+
setpayloadf128_test.cpp
3819+
HDRS
3820+
SetPayloadTest.h
3821+
DEPENDS
3822+
libc.src.math.setpayloadf128
3823+
)
3824+
37893825
add_fp_unittest(
37903826
setpayloadsigf16_test
37913827
SUITE
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for setpayload ------------------------------------------===//
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 "SetPayloadTest.h"
10+
11+
#include "src/math/setpayload.h"
12+
13+
LIST_SETPAYLOAD_TESTS(double, LIBC_NAMESPACE::setpayload)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for setpayloadf128 --------------------------------------===//
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 "SetPayloadTest.h"
10+
11+
#include "src/math/setpayloadf128.h"
12+
13+
LIST_SETPAYLOAD_TESTS(float128, LIBC_NAMESPACE::setpayloadf128)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//===-- Unittests for setpayloadf -----------------------------------------===//
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 "SetPayloadTest.h"
10+
11+
#include "src/math/setpayloadf.h"
12+
13+
LIST_SETPAYLOAD_TESTS(float, LIBC_NAMESPACE::setpayloadf)

0 commit comments

Comments
 (0)