Skip to content

Commit 47e3d8d

Browse files
authored
[libc][math] Implement issignaling[f|l] as a libc math function (#110556)
This PR implements the issignaling function as part of the libc math library, addressing the TODO items mentioned in #110011 The addition of this function is crucial for completing the implementation of remaining math macros, as referenced in #109201
1 parent e9dbdb2 commit 47e3d8d

25 files changed

+475
-0
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ set(TARGET_LIBM_ENTRYPOINTS
479479
libc.src.math.isnan
480480
libc.src.math.isnanf
481481
libc.src.math.isnanl
482+
libc.src.math.issignaling
483+
libc.src.math.issignalingf
484+
libc.src.math.issignalingl
482485
libc.src.math.ldexp
483486
libc.src.math.ldexpf
484487
libc.src.math.ldexpl
@@ -637,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
637640
libc.src.math.fromfpxf16
638641
libc.src.math.getpayloadf16
639642
libc.src.math.ilogbf16
643+
libc.src.math.issignalingf16
640644
libc.src.math.ldexpf16
641645
libc.src.math.llogbf16
642646
libc.src.math.llrintf16
@@ -720,6 +724,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
720724
libc.src.math.fsubf128
721725
libc.src.math.getpayloadf128
722726
libc.src.math.ilogbf128
727+
libc.src.math.issignalingf128
723728
libc.src.math.ldexpf128
724729
libc.src.math.llogbf128
725730
libc.src.math.llrintf128

libc/config/linux/riscv/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ set(TARGET_LIBM_ENTRYPOINTS
482482
libc.src.math.isnan
483483
libc.src.math.isnanf
484484
libc.src.math.isnanl
485+
libc.src.math.issignaling
486+
libc.src.math.issignalingf
487+
libc.src.math.issignalingl
485488
libc.src.math.ldexp
486489
libc.src.math.ldexpf
487490
libc.src.math.ldexpl
@@ -627,6 +630,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
627630
libc.src.math.fsubf128
628631
libc.src.math.getpayloadf128
629632
libc.src.math.ilogbf128
633+
libc.src.math.issignalingf128
630634
libc.src.math.ldexpf128
631635
libc.src.math.llogbf128
632636
libc.src.math.llrintf128

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ set(TARGET_LIBM_ENTRYPOINTS
482482
libc.src.math.isnan
483483
libc.src.math.isnanf
484484
libc.src.math.isnanl
485+
libc.src.math.issignaling
486+
libc.src.math.issignalingf
487+
libc.src.math.issignalingl
485488
libc.src.math.ldexp
486489
libc.src.math.ldexpf
487490
libc.src.math.ldexpl
@@ -637,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
637640
libc.src.math.fromfpxf16
638641
libc.src.math.getpayloadf16
639642
libc.src.math.ilogbf16
643+
libc.src.math.issignalingf16
640644
libc.src.math.ldexpf16
641645
libc.src.math.llogbf16
642646
libc.src.math.llrintf16
@@ -717,6 +721,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
717721
libc.src.math.fsubf128
718722
libc.src.math.getpayloadf128
719723
libc.src.math.ilogbf128
724+
libc.src.math.issignalingf128
720725
libc.src.math.ldexpf128
721726
libc.src.math.llogbf128
722727
libc.src.math.llrintf128

libc/docs/math/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ Basic Operations
182182
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
183183
| ilogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
184184
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
185+
| issignaling | |check| | |check| | |check| | |check| | |check| | 7.12.3.8 | N/A |
186+
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
185187
| ldexp | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
186188
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
187189
| llogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |

libc/spec/stdc.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,12 @@ def StdC : StandardSpec<"stdc"> {
825825
GuardedFunctionSpec<"nanf16", RetValSpec<Float16Type>, [ArgSpec<ConstCharPtr>], "LIBC_TYPES_HAS_FLOAT16">,
826826
GuardedFunctionSpec<"nanf128", RetValSpec<Float128Type>, [ArgSpec<ConstCharPtr>], "LIBC_TYPES_HAS_FLOAT128">,
827827

828+
FunctionSpec<"issignaling", RetValSpec<IntType>, [ArgSpec<DoubleType>]>,
829+
FunctionSpec<"issignalingf", RetValSpec<IntType>, [ArgSpec<FloatType>]>,
830+
FunctionSpec<"issignalingl", RetValSpec<IntType>, [ArgSpec<LongDoubleType>]>,
831+
GuardedFunctionSpec<"issignalingf16", RetValSpec<IntType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
832+
GuardedFunctionSpec<"issignalingf128", RetValSpec<IntType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
833+
828834
FunctionSpec<"canonicalize", RetValSpec<IntType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
829835
FunctionSpec<"canonicalizef", RetValSpec<IntType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
830836
FunctionSpec<"canonicalizel", RetValSpec<IntType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,

libc/src/__support/FPUtil/BasicOperations.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ LIBC_INLINE T fdim(T x, T y) {
247247
return (x > y ? x - y : 0);
248248
}
249249

250+
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
251+
LIBC_INLINE int issignaling(const T &x) {
252+
FPBits<T> sx(x);
253+
return sx.is_signaling_nan();
254+
}
255+
250256
template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
251257
LIBC_INLINE int canonicalize(T &cx, const T &x) {
252258
FPBits<T> sx(x);

libc/src/math/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ add_math_entrypoint_object(isnan)
302302
add_math_entrypoint_object(isnanf)
303303
add_math_entrypoint_object(isnanl)
304304

305+
add_math_entrypoint_object(issignaling)
306+
add_math_entrypoint_object(issignalingf)
307+
add_math_entrypoint_object(issignalingl)
308+
add_math_entrypoint_object(issignalingf16)
309+
add_math_entrypoint_object(issignalingf128)
310+
305311
add_math_entrypoint_object(llogb)
306312
add_math_entrypoint_object(llogbf)
307313
add_math_entrypoint_object(llogbl)

libc/src/math/generic/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,60 @@ add_entrypoint_object(
33773377
-O3
33783378
)
33793379

3380+
add_entrypoint_object(
3381+
issignaling
3382+
SRCS
3383+
issignaling.cpp
3384+
HDRS
3385+
../issignaling.h
3386+
COMPILE_OPTIONS
3387+
-O3
3388+
)
3389+
3390+
add_entrypoint_object(
3391+
issignalingf
3392+
SRCS
3393+
issignalingf.cpp
3394+
HDRS
3395+
../issignalingf.h
3396+
COMPILE_OPTIONS
3397+
-O3
3398+
)
3399+
3400+
add_entrypoint_object(
3401+
issignalingl
3402+
SRCS
3403+
issignalingl.cpp
3404+
HDRS
3405+
../issignalingl.h
3406+
COMPILE_OPTIONS
3407+
-O3
3408+
)
3409+
3410+
add_entrypoint_object(
3411+
issignalingf16
3412+
SRCS
3413+
issignalingf16.cpp
3414+
HDRS
3415+
../issignalingf16.h
3416+
COMPILE_OPTIONS
3417+
-O3
3418+
DEPENDS
3419+
libc.src.__support.macros.properties.types
3420+
)
3421+
3422+
add_entrypoint_object(
3423+
issignalingf128
3424+
SRCS
3425+
issignalingf128.cpp
3426+
HDRS
3427+
../issignalingf128.h
3428+
COMPILE_OPTIONS
3429+
-O3
3430+
DEPENDS
3431+
libc.src.__support.macros.properties.types
3432+
)
3433+
33803434
add_entrypoint_object(
33813435
isnan
33823436
SRCS

libc/src/math/generic/issignaling.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation of issignaling 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/issignaling.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, issignaling, (double x)) {
17+
return fputil::issignaling(x);
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 issignalingf 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/issignalingf.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, issignalingf, (float x)) {
17+
return fputil::issignaling(x);
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 issignalingf128 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/issignalingf128.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, issignalingf128, (float128 x)) {
17+
return fputil::issignaling(x);
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 issignalingf16 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/issignalingf16.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, issignalingf16, (float16 x)) {
17+
return fputil::issignaling(x);
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 issignalingl 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/issignalingl.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, issignalingl, (long double x)) {
17+
return fputil::issignaling(x);
18+
}
19+
20+
} // namespace LIBC_NAMESPACE_DECL

libc/src/math/issignaling.h

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

libc/src/math/issignalingf.h

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

libc/src/math/issignalingf128.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for issignalingf128 ---------------*- 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_ISSIGNALINGF128_H
10+
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGF128_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 issignalingf128(float128 x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGF128_H

libc/src/math/issignalingf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for issignalingf16 ----------------*- 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_ISSIGNALINGF16_H
10+
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGF16_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 issignalingf16(float16 x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGF16_H

libc/src/math/issignalingl.h

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

0 commit comments

Comments
 (0)