Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][math] Implement issignaling[f|l] as a libc math function #110556

Merged
merged 11 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc/config/linux/aarch64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.issignaling
libc.src.math.issignalingf
libc.src.math.issignalingl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down Expand Up @@ -637,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.ilogbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
Expand Down Expand Up @@ -720,6 +724,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.issignalingf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
libc.src.math.llrintf128
Expand Down
4 changes: 4 additions & 0 deletions libc/config/linux/riscv/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.issignaling
libc.src.math.issignalingf
libc.src.math.issignalingl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down Expand Up @@ -627,6 +630,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.issignalingf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
libc.src.math.llrintf128
Expand Down
5 changes: 5 additions & 0 deletions libc/config/linux/x86_64/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
libc.src.math.issignaling
libc.src.math.issignalingf
libc.src.math.issignalingl
libc.src.math.ldexp
libc.src.math.ldexpf
libc.src.math.ldexpl
Expand Down Expand Up @@ -637,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.ilogbf16
libc.src.math.issignalingf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
Expand Down Expand Up @@ -717,6 +721,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
libc.src.math.issignalingf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
libc.src.math.llrintf128
Expand Down
2 changes: 2 additions & 0 deletions libc/docs/math/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ Basic Operations
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ilogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.8 | F.10.3.8 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| issignaling | |check| | |check| | |check| | |check| | |check| | 7.12.3.8 | N/A |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| ldexp | |check| | |check| | |check| | |check| | |check| | 7.12.6.9 | F.10.3.9 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
| llogb | |check| | |check| | |check| | |check| | |check| | 7.12.6.10 | F.10.3.10 |
Expand Down
6 changes: 6 additions & 0 deletions libc/spec/stdc.td
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,12 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"nanf16", RetValSpec<Float16Type>, [ArgSpec<ConstCharPtr>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"nanf128", RetValSpec<Float128Type>, [ArgSpec<ConstCharPtr>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"issignaling", RetValSpec<IntType>, [ArgSpec<DoubleType>]>,
FunctionSpec<"issignalingf", RetValSpec<IntType>, [ArgSpec<FloatType>]>,
FunctionSpec<"issignalingl", RetValSpec<IntType>, [ArgSpec<LongDoubleType>]>,
GuardedFunctionSpec<"issignalingf16", RetValSpec<IntType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"issignalingf128", RetValSpec<IntType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,

FunctionSpec<"canonicalize", RetValSpec<IntType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"canonicalizef", RetValSpec<IntType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
FunctionSpec<"canonicalizel", RetValSpec<IntType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
Expand Down
6 changes: 6 additions & 0 deletions libc/src/__support/FPUtil/BasicOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ LIBC_INLINE T fdim(T x, T y) {
return (x > y ? x - y : 0);
}

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE int issignaling(const T &x) {
FPBits<T> sx(x);
return sx.is_signaling_nan();
}

template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
LIBC_INLINE int canonicalize(T &cx, const T &x) {
FPBits<T> sx(x);
Expand Down
6 changes: 6 additions & 0 deletions libc/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ add_math_entrypoint_object(isnan)
add_math_entrypoint_object(isnanf)
add_math_entrypoint_object(isnanl)

add_math_entrypoint_object(issignaling)
add_math_entrypoint_object(issignalingf)
add_math_entrypoint_object(issignalingl)
add_math_entrypoint_object(issignalingf16)
add_math_entrypoint_object(issignalingf128)

add_math_entrypoint_object(llogb)
add_math_entrypoint_object(llogbf)
add_math_entrypoint_object(llogbl)
Expand Down
54 changes: 54 additions & 0 deletions libc/src/math/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,60 @@ add_entrypoint_object(
-O3
)

add_entrypoint_object(
issignaling
SRCS
issignaling.cpp
HDRS
../issignaling.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
issignalingf
SRCS
issignalingf.cpp
HDRS
../issignalingf.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
issignalingl
SRCS
issignalingl.cpp
HDRS
../issignalingl.h
COMPILE_OPTIONS
-O3
)

add_entrypoint_object(
issignalingf16
SRCS
issignalingf16.cpp
HDRS
../issignalingf16.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
)

add_entrypoint_object(
issignalingf128
SRCS
issignalingf128.cpp
HDRS
../issignalingf128.h
COMPILE_OPTIONS
-O3
DEPENDS
libc.src.__support.macros.properties.types
)

add_entrypoint_object(
isnan
SRCS
Expand Down
20 changes: 20 additions & 0 deletions libc/src/math/generic/issignaling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of issignaling 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/issignaling.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(int, issignaling, (double x)) {
return fputil::issignaling(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/issignalingf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of issignalingf 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/issignalingf.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(int, issignalingf, (float x)) {
return fputil::issignaling(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/issignalingf128.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of issignalingf128 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/issignalingf128.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(int, issignalingf128, (float128 x)) {
return fputil::issignaling(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/issignalingf16.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of issignalingf16 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/issignalingf16.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(int, issignalingf16, (float16 x)) {
return fputil::issignaling(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/generic/issignalingl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation of issignalingl 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/issignalingl.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(int, issignalingl, (long double x)) {
return fputil::issignaling(x);
}

} // namespace LIBC_NAMESPACE_DECL
20 changes: 20 additions & 0 deletions libc/src/math/issignaling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for issignaling -------------------*- 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_ISSIGNALING_H
#define LLVM_LIBC_SRC_MATH_ISSIGNALING_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int issignaling(double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_ISSIGNALING_H
20 changes: 20 additions & 0 deletions libc/src/math/issignalingf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for issignalingf ------------------*- 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_ISSIGNALINGF_H
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGF_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int issignalingf(float x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGF_H
21 changes: 21 additions & 0 deletions libc/src/math/issignalingf128.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for issignalingf128 ---------------*- 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_ISSIGNALINGF128_H
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGF128_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

int issignalingf128(float128 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGF128_H
21 changes: 21 additions & 0 deletions libc/src/math/issignalingf16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===-- Implementation header for issignalingf16 ----------------*- 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_ISSIGNALINGF16_H
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGF16_H

#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"

namespace LIBC_NAMESPACE_DECL {

int issignalingf16(float16 x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGF16_H
20 changes: 20 additions & 0 deletions libc/src/math/issignalingl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===-- Implementation header for issignalingl ------------------*- 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_ISSIGNALINGL_H
#define LLVM_LIBC_SRC_MATH_ISSIGNALINGL_H

#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

int issignalingl(long double x);

} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_MATH_ISSIGNALINGL_H
Loading