Skip to content

Commit aae7c38

Browse files
author
Job Henandez Lara
authored
[libc][math][c23] Add entrypoints and tests for setpayloadsig{,f,l,f128} and setpayloadl. (#102413)
1 parent 8c7a038 commit aae7c38

27 files changed

+480
-4
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ set(TARGET_LIBM_ENTRYPOINTS
546546
libc.src.math.scalbnl
547547
libc.src.math.setpayload
548548
libc.src.math.setpayloadf
549+
libc.src.math.setpayloadl
550+
libc.src.math.setpayloadsig
551+
libc.src.math.setpayloadsigf
552+
libc.src.math.setpayloadsigl
549553
libc.src.math.sin
550554
libc.src.math.sincos
551555
libc.src.math.sincosf
@@ -726,6 +730,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
726730
libc.src.math.roundf128
727731
libc.src.math.scalbnf128
728732
libc.src.math.setpayloadf128
733+
libc.src.math.setpayloadsigf128
729734
libc.src.math.sqrtf128
730735
libc.src.math.totalorderf128
731736
libc.src.math.totalordermagf128

libc/config/linux/arm/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ set(TARGET_LIBM_ENTRYPOINTS
376376
libc.src.math.scalbnl
377377
libc.src.math.setpayload
378378
libc.src.math.setpayloadf
379+
libc.src.math.setpayloadl
380+
libc.src.math.setpayloadsig
381+
libc.src.math.setpayloadsigf
382+
libc.src.math.setpayloadsigl
379383
libc.src.math.sin
380384
libc.src.math.sincos
381385
libc.src.math.sincosf

libc/config/linux/riscv/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ set(TARGET_LIBM_ENTRYPOINTS
549549
libc.src.math.scalbnl
550550
libc.src.math.setpayload
551551
libc.src.math.setpayloadf
552+
libc.src.math.setpayloadl
553+
libc.src.math.setpayloadsig
554+
libc.src.math.setpayloadsigf
555+
libc.src.math.setpayloadsigl
552556
libc.src.math.sin
553557
libc.src.math.sincos
554558
libc.src.math.sincosf
@@ -633,6 +637,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
633637
libc.src.math.roundf128
634638
libc.src.math.scalbnf128
635639
libc.src.math.setpayloadf128
640+
libc.src.math.setpayloadsigf128
636641
libc.src.math.sqrtf128
637642
libc.src.math.totalorderf128
638643
libc.src.math.totalordermagf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ set(TARGET_LIBM_ENTRYPOINTS
549549
libc.src.math.scalbnl
550550
libc.src.math.setpayload
551551
libc.src.math.setpayloadf
552+
libc.src.math.setpayloadl
553+
libc.src.math.setpayloadsig
554+
libc.src.math.setpayloadsigf
555+
libc.src.math.setpayloadsigl
552556
libc.src.math.sin
553557
libc.src.math.sincos
554558
libc.src.math.sincosf
@@ -722,6 +726,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
722726
libc.src.math.roundf128
723727
libc.src.math.scalbnf128
724728
libc.src.math.setpayloadf128
729+
libc.src.math.setpayloadsigf128
725730
libc.src.math.sqrtf128
726731
libc.src.math.totalorderf128
727732
libc.src.math.totalordermagf128

libc/docs/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ Basic Operations
224224
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
225225
| scalbn | |check| | |check| | |check| | |check| | |check| | 7.12.6.19 | F.10.3.19 |
226226
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
227-
| setpayload | |check| | |check| | | |check| | |check| | F.10.13.2 | N/A |
227+
| setpayload | |check| | |check| | |check| | |check| | |check| | F.10.13.2 | N/A |
228228
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
229-
| setpayloadsig | | | | |check| | | F.10.13.3 | N/A |
229+
| setpayloadsig | |check| | |check| | |check| | |check| | |check| | F.10.13.3 | N/A |
230230
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
231231
| totalorder | |check| | |check| | | |check| | |check| | F.10.12.1 | N/A |
232232
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/newhdrgen/yaml/math.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,27 @@ functions:
17651765
- type: _Float16
17661766
- type: int
17671767
guard: LIBC_TYPES_HAS_FLOAT16
1768+
- name: setpayload
1769+
standards:
1770+
- stdc
1771+
return_type: int
1772+
arguments:
1773+
- type: double *
1774+
- type: double
1775+
- name: setpayloadf
1776+
standards:
1777+
- stdc
1778+
return_type: int
1779+
arguments:
1780+
- type: float *
1781+
- type: float
1782+
- name: setpayloadl
1783+
standards:
1784+
- stdc
1785+
return_type: int
1786+
arguments:
1787+
- type: long double *
1788+
- type: long double
17681789
- name: setpayloadf16
17691790
standards:
17701791
- stdc
@@ -1773,6 +1794,35 @@ functions:
17731794
- type: _Float16 *
17741795
- type: _Float16
17751796
guard: LIBC_TYPES_HAS_FLOAT16
1797+
- name: setpayloadf128
1798+
standards:
1799+
- stdc
1800+
return_type: int
1801+
arguments:
1802+
- type: float128 *
1803+
- type: float128
1804+
guard: LIBC_TYPES_HAS_FLOAT128
1805+
- name: setpayloadsig
1806+
standards:
1807+
- stdc
1808+
return_type: double
1809+
arguments:
1810+
- type: double *
1811+
- type: double
1812+
- name: setpayloadsigf
1813+
standards:
1814+
- stdc
1815+
return_type: int
1816+
arguments:
1817+
- type: float *
1818+
- type: float
1819+
- name: setpayloadsigl
1820+
standards:
1821+
- stdc
1822+
return_type: int
1823+
arguments:
1824+
- type: long double *
1825+
- type: long double
17761826
- name: setpayloadsigf16
17771827
standards:
17781828
- stdc
@@ -1781,6 +1831,14 @@ functions:
17811831
- type: _Float16 *
17821832
- type: _Float16
17831833
guard: LIBC_TYPES_HAS_FLOAT16
1834+
- name: setpayloadsigf128
1835+
standards:
1836+
- stdc
1837+
return_type: int
1838+
arguments:
1839+
- type: float128 *
1840+
- type: float128
1841+
guard: LIBC_TYPES_HAS_FLOAT128
17841842
- name: totalorderf16
17851843
standards:
17861844
- stdc

libc/spec/stdc.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,15 @@ def StdC : StandardSpec<"stdc"> {
758758

759759
FunctionSpec<"setpayload", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
760760
FunctionSpec<"setpayloadf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
761+
FunctionSpec<"setpayloadl", RetValSpec<IntType>, [ArgSpec<LongDoublePtr>, ArgSpec<LongDoubleType>]>,
761762
GuardedFunctionSpec<"setpayloadf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
762763
GuardedFunctionSpec<"setpayloadf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
763764

765+
FunctionSpec<"setpayloadsig", RetValSpec<IntType>, [ArgSpec<DoublePtr>, ArgSpec<DoubleType>]>,
766+
FunctionSpec<"setpayloadsigf", RetValSpec<IntType>, [ArgSpec<FloatPtr>, ArgSpec<FloatType>]>,
767+
FunctionSpec<"setpayloadsigl", RetValSpec<IntType>, [ArgSpec<LongDoublePtr>, ArgSpec<LongDoubleType>]>,
764768
GuardedFunctionSpec<"setpayloadsigf16", RetValSpec<IntType>, [ArgSpec<Float16Ptr>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
769+
GuardedFunctionSpec<"setpayloadsigf128", RetValSpec<IntType>, [ArgSpec<Float128Ptr>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
765770

766771
GuardedFunctionSpec<"f16addf128", RetValSpec<Float16Type>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT16_AND_FLOAT128">,
767772

libc/src/__support/FPUtil/BasicOperations.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ setpayload(T &res, T pl) {
377377
}
378378

379379
using StorageType = typename FPBits::StorageType;
380-
StorageType v(pl_bits.get_explicit_mantissa() >> (FPBits::SIG_LEN - pl_exp));
380+
StorageType v(pl_bits.get_explicit_mantissa() >>
381+
(FPBits::FRACTION_LEN - pl_exp));
381382

382383
if constexpr (IsSignaling)
383384
res = FPBits::signaling_nan(Sign::POS, v).get_val();

libc/src/math/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,15 @@ add_math_entrypoint_object(scalbnf128)
436436

437437
add_math_entrypoint_object(setpayload)
438438
add_math_entrypoint_object(setpayloadf)
439+
add_math_entrypoint_object(setpayloadl)
439440
add_math_entrypoint_object(setpayloadf16)
440441
add_math_entrypoint_object(setpayloadf128)
441442

443+
add_math_entrypoint_object(setpayloadsig)
444+
add_math_entrypoint_object(setpayloadsigf)
445+
add_math_entrypoint_object(setpayloadsigl)
442446
add_math_entrypoint_object(setpayloadsigf16)
447+
add_math_entrypoint_object(setpayloadsigf128)
443448

444449
add_math_entrypoint_object(sincos)
445450
add_math_entrypoint_object(sincosf)

libc/src/math/generic/CMakeLists.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,18 @@ add_entrypoint_object(
44734473
-O3
44744474
)
44754475

4476+
add_entrypoint_object(
4477+
setpayloadl
4478+
SRCS
4479+
setpayloadl.cpp
4480+
HDRS
4481+
../setpayloadl.h
4482+
DEPENDS
4483+
libc.src.__support.FPUtil.basic_operations
4484+
COMPILE_OPTIONS
4485+
-O3
4486+
)
4487+
44764488
add_entrypoint_object(
44774489
setpayloadf16
44784490
SRCS
@@ -4499,6 +4511,42 @@ add_entrypoint_object(
44994511
-O3
45004512
)
45014513

4514+
add_entrypoint_object(
4515+
setpayloadsig
4516+
SRCS
4517+
setpayloadsig.cpp
4518+
HDRS
4519+
../setpayloadsig.h
4520+
DEPENDS
4521+
libc.src.__support.FPUtil.basic_operations
4522+
COMPILE_OPTIONS
4523+
-O3
4524+
)
4525+
4526+
add_entrypoint_object(
4527+
setpayloadsigf
4528+
SRCS
4529+
setpayloadsigf.cpp
4530+
HDRS
4531+
../setpayloadsigf.h
4532+
DEPENDS
4533+
libc.src.__support.FPUtil.basic_operations
4534+
COMPILE_OPTIONS
4535+
-O3
4536+
)
4537+
4538+
add_entrypoint_object(
4539+
setpayloadsigl
4540+
SRCS
4541+
setpayloadsigl.cpp
4542+
HDRS
4543+
../setpayloadsigl.h
4544+
DEPENDS
4545+
libc.src.__support.FPUtil.basic_operations
4546+
COMPILE_OPTIONS
4547+
-O3
4548+
)
4549+
45024550
add_entrypoint_object(
45034551
setpayloadsigf16
45044552
SRCS
@@ -4512,6 +4560,19 @@ add_entrypoint_object(
45124560
-O3
45134561
)
45144562

4563+
add_entrypoint_object(
4564+
setpayloadsigf128
4565+
SRCS
4566+
setpayloadsigf128.cpp
4567+
HDRS
4568+
../setpayloadsigf128.h
4569+
DEPENDS
4570+
libc.src.__support.macros.properties.types
4571+
libc.src.__support.FPUtil.basic_operations
4572+
COMPILE_OPTIONS
4573+
-O3
4574+
)
4575+
45154576
add_entrypoint_object(
45164577
f16add
45174578
SRCS

libc/src/math/generic/setpayloadl.cpp

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

0 commit comments

Comments
 (0)