From 40d46458d876858a4338addc0991f942511ad874 Mon Sep 17 00:00:00 2001 From: Shourya Goel Date: Tue, 1 Oct 2024 23:19:28 +0530 Subject: [PATCH] [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 --- libc/config/linux/aarch64/entrypoints.txt | 5 ++ libc/config/linux/riscv/entrypoints.txt | 4 ++ libc/config/linux/x86_64/entrypoints.txt | 5 ++ libc/docs/math/index.rst | 2 + libc/spec/stdc.td | 6 ++ libc/src/__support/FPUtil/BasicOperations.h | 6 ++ libc/src/math/CMakeLists.txt | 6 ++ libc/src/math/generic/CMakeLists.txt | 54 +++++++++++++++++ libc/src/math/generic/issignaling.cpp | 20 +++++++ libc/src/math/generic/issignalingf.cpp | 20 +++++++ libc/src/math/generic/issignalingf128.cpp | 20 +++++++ libc/src/math/generic/issignalingf16.cpp | 20 +++++++ libc/src/math/generic/issignalingl.cpp | 20 +++++++ libc/src/math/issignaling.h | 20 +++++++ libc/src/math/issignalingf.h | 20 +++++++ libc/src/math/issignalingf128.h | 21 +++++++ libc/src/math/issignalingf16.h | 21 +++++++ libc/src/math/issignalingl.h | 20 +++++++ libc/test/src/math/smoke/CMakeLists.txt | 60 +++++++++++++++++++ libc/test/src/math/smoke/IsSignalingTest.h | 60 +++++++++++++++++++ libc/test/src/math/smoke/issignaling_test.cpp | 13 ++++ .../src/math/smoke/issignalingf128_test.cpp | 13 ++++ .../src/math/smoke/issignalingf16_test.cpp | 13 ++++ .../test/src/math/smoke/issignalingf_test.cpp | 13 ++++ .../test/src/math/smoke/issignalingl_test.cpp | 13 ++++ 25 files changed, 475 insertions(+) create mode 100644 libc/src/math/generic/issignaling.cpp create mode 100644 libc/src/math/generic/issignalingf.cpp create mode 100644 libc/src/math/generic/issignalingf128.cpp create mode 100644 libc/src/math/generic/issignalingf16.cpp create mode 100644 libc/src/math/generic/issignalingl.cpp create mode 100644 libc/src/math/issignaling.h create mode 100644 libc/src/math/issignalingf.h create mode 100644 libc/src/math/issignalingf128.h create mode 100644 libc/src/math/issignalingf16.h create mode 100644 libc/src/math/issignalingl.h create mode 100644 libc/test/src/math/smoke/IsSignalingTest.h create mode 100644 libc/test/src/math/smoke/issignaling_test.cpp create mode 100644 libc/test/src/math/smoke/issignalingf128_test.cpp create mode 100644 libc/test/src/math/smoke/issignalingf16_test.cpp create mode 100644 libc/test/src/math/smoke/issignalingf_test.cpp create mode 100644 libc/test/src/math/smoke/issignalingl_test.cpp diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 64fbe1a250c0baf..5398593a51eac41 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -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 @@ -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 @@ -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 diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index ff3d821c664c5b3..3bbfb95166abb99 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -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 @@ -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 diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index dd658af3bfb6749..113c6838d06d3b0 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -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 @@ -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 @@ -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 diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst index 185d2d440849a0d..a98f107e5cb23b5 100644 --- a/libc/docs/math/index.rst +++ b/libc/docs/math/index.rst @@ -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 | diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 7caf543748151aa..834ac786b25196e 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -825,6 +825,12 @@ def StdC : StandardSpec<"stdc"> { GuardedFunctionSpec<"nanf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, GuardedFunctionSpec<"nanf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + FunctionSpec<"issignaling", RetValSpec, [ArgSpec]>, + FunctionSpec<"issignalingf", RetValSpec, [ArgSpec]>, + FunctionSpec<"issignalingl", RetValSpec, [ArgSpec]>, + GuardedFunctionSpec<"issignalingf16", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT16">, + GuardedFunctionSpec<"issignalingf128", RetValSpec, [ArgSpec], "LIBC_TYPES_HAS_FLOAT128">, + FunctionSpec<"canonicalize", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"canonicalizef", RetValSpec, [ArgSpec, ArgSpec]>, FunctionSpec<"canonicalizel", RetValSpec, [ArgSpec, ArgSpec]>, diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h index 824c9bfb3947f3c..a69bca6acc5123f 100644 --- a/libc/src/__support/FPUtil/BasicOperations.h +++ b/libc/src/__support/FPUtil/BasicOperations.h @@ -247,6 +247,12 @@ LIBC_INLINE T fdim(T x, T y) { return (x > y ? x - y : 0); } +template , int> = 0> +LIBC_INLINE int issignaling(const T &x) { + FPBits sx(x); + return sx.is_signaling_nan(); +} + template , int> = 0> LIBC_INLINE int canonicalize(T &cx, const T &x) { FPBits sx(x); diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 3cba34fc2493223..dab5bb43ed59ce2 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -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) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index d0676d03420c68c..5e1b2a54a131a9d 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -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 diff --git a/libc/src/math/generic/issignaling.cpp b/libc/src/math/generic/issignaling.cpp new file mode 100644 index 000000000000000..0687a32817b2955 --- /dev/null +++ b/libc/src/math/generic/issignaling.cpp @@ -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 diff --git a/libc/src/math/generic/issignalingf.cpp b/libc/src/math/generic/issignalingf.cpp new file mode 100644 index 000000000000000..410bf7b4d427821 --- /dev/null +++ b/libc/src/math/generic/issignalingf.cpp @@ -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 diff --git a/libc/src/math/generic/issignalingf128.cpp b/libc/src/math/generic/issignalingf128.cpp new file mode 100644 index 000000000000000..29612ccf677f67c --- /dev/null +++ b/libc/src/math/generic/issignalingf128.cpp @@ -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 diff --git a/libc/src/math/generic/issignalingf16.cpp b/libc/src/math/generic/issignalingf16.cpp new file mode 100644 index 000000000000000..976b8e2b689b3cf --- /dev/null +++ b/libc/src/math/generic/issignalingf16.cpp @@ -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 diff --git a/libc/src/math/generic/issignalingl.cpp b/libc/src/math/generic/issignalingl.cpp new file mode 100644 index 000000000000000..a3959bcae23575e --- /dev/null +++ b/libc/src/math/generic/issignalingl.cpp @@ -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 diff --git a/libc/src/math/issignaling.h b/libc/src/math/issignaling.h new file mode 100644 index 000000000000000..093fd7d48770dd0 --- /dev/null +++ b/libc/src/math/issignaling.h @@ -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 diff --git a/libc/src/math/issignalingf.h b/libc/src/math/issignalingf.h new file mode 100644 index 000000000000000..97522600916cceb --- /dev/null +++ b/libc/src/math/issignalingf.h @@ -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 diff --git a/libc/src/math/issignalingf128.h b/libc/src/math/issignalingf128.h new file mode 100644 index 000000000000000..7d1bfdec646de86 --- /dev/null +++ b/libc/src/math/issignalingf128.h @@ -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 diff --git a/libc/src/math/issignalingf16.h b/libc/src/math/issignalingf16.h new file mode 100644 index 000000000000000..2b38525e1a3e073 --- /dev/null +++ b/libc/src/math/issignalingf16.h @@ -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 diff --git a/libc/src/math/issignalingl.h b/libc/src/math/issignalingl.h new file mode 100644 index 000000000000000..edc039416d1f4eb --- /dev/null +++ b/libc/src/math/issignalingl.h @@ -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 diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 9f9203c491d044e..5c3068eb0de8860 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -1597,6 +1597,66 @@ add_fp_unittest( libc.src.__support.FPUtil.manipulation_functions ) +add_fp_unittest( + issignaling_test + SUITE + libc-math-smoke-tests + SRCS + issignaling_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignaling +) + +add_fp_unittest( + issignalingf_test + SUITE + libc-math-smoke-tests + SRCS + issignalingf_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignalingf +) + +add_fp_unittest( + issignalingl_test + SUITE + libc-math-smoke-tests + SRCS + issignalingl_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignalingl +) + +add_fp_unittest( + issignalingf16_test + SUITE + libc-math-smoke-tests + SRCS + issignalingf16_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignalingf16 +) + +add_fp_unittest( + issignalingf128_test + SUITE + libc-math-smoke-tests + SRCS + issignalingf128_test.cpp + HDRS + IsSignalingTest.h + DEPENDS + libc.src.math.issignalingf128 +) + add_fp_unittest( llogb_test SUITE diff --git a/libc/test/src/math/smoke/IsSignalingTest.h b/libc/test/src/math/smoke/IsSignalingTest.h new file mode 100644 index 000000000000000..f52642ad27bea9f --- /dev/null +++ b/libc/test/src/math/smoke/IsSignalingTest.h @@ -0,0 +1,60 @@ +//===-- Utility class to test different flavors of 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_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H +#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H + +#include "test/UnitTest/FEnvSafeTest.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "hdr/math_macros.h" + +template +class IsSignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef int (*IsSignalingFunc)(T); + + void testSpecialNumbers(IsSignalingFunc func) { + EXPECT_EQ(func(aNaN), 0); + EXPECT_EQ(func(neg_aNaN), 0); + EXPECT_EQ(func(sNaN), 1); + EXPECT_EQ(func(neg_sNaN), 1); + EXPECT_EQ(func(inf), 0); + EXPECT_EQ(func(neg_inf), 0); + EXPECT_EQ(func(min_normal), 0); + EXPECT_EQ(func(max_normal), 0); + EXPECT_EQ(func(neg_max_normal), 0); + EXPECT_EQ(func(min_denormal), 0); + EXPECT_EQ(func(neg_min_denormal), 0); + EXPECT_EQ(func(max_denormal), 0); + EXPECT_EQ(func(zero), 0); + EXPECT_EQ(func(neg_zero), 0); + } + + void testRoundedNumbers(IsSignalingFunc func) { + EXPECT_EQ(func(T(1.0)), 0); + EXPECT_EQ(func(T(-1.0)), 0); + EXPECT_EQ(func(T(10.0)), 0); + EXPECT_EQ(func(T(-10.0)), 0); + EXPECT_EQ(func(T(1234.0)), 0); + EXPECT_EQ(func(T(-1234.0)), 0); + } +}; + +#define LIST_ISSIGNALING_TESTS(T, func) \ + using LlvmLibcIsSignalingTest = IsSignalingTest; \ + TEST_F(LlvmLibcIsSignalingTest, SpecialNumbers) { \ + testSpecialNumbers(&func); \ + } \ + TEST_F(LlvmLibcIsSignalingTest, RoundedNubmers) { testRoundedNumbers(&func); } + +#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H diff --git a/libc/test/src/math/smoke/issignaling_test.cpp b/libc/test/src/math/smoke/issignaling_test.cpp new file mode 100644 index 000000000000000..4292cbbb852b497 --- /dev/null +++ b/libc/test/src/math/smoke/issignaling_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for issignaling -----------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/math/issignaling.h" + +LIST_ISSIGNALING_TESTS(double, LIBC_NAMESPACE::issignaling) diff --git a/libc/test/src/math/smoke/issignalingf128_test.cpp b/libc/test/src/math/smoke/issignalingf128_test.cpp new file mode 100644 index 000000000000000..929e32a8facdd5c --- /dev/null +++ b/libc/test/src/math/smoke/issignalingf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for issignalingf128 -------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/math/issignalingf128.h" + +LIST_ISSIGNALING_TESTS(float128, LIBC_NAMESPACE::issignalingf128) diff --git a/libc/test/src/math/smoke/issignalingf16_test.cpp b/libc/test/src/math/smoke/issignalingf16_test.cpp new file mode 100644 index 000000000000000..fc2a65a32918383 --- /dev/null +++ b/libc/test/src/math/smoke/issignalingf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for issignalingf16 --------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/math/issignalingf16.h" + +LIST_ISSIGNALING_TESTS(float16, LIBC_NAMESPACE::issignalingf16) diff --git a/libc/test/src/math/smoke/issignalingf_test.cpp b/libc/test/src/math/smoke/issignalingf_test.cpp new file mode 100644 index 000000000000000..0ceb9a80c031080 --- /dev/null +++ b/libc/test/src/math/smoke/issignalingf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for issignalingf ----------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/math/issignalingf.h" + +LIST_ISSIGNALING_TESTS(float, LIBC_NAMESPACE::issignalingf) diff --git a/libc/test/src/math/smoke/issignalingl_test.cpp b/libc/test/src/math/smoke/issignalingl_test.cpp new file mode 100644 index 000000000000000..049769009ba7c6a --- /dev/null +++ b/libc/test/src/math/smoke/issignalingl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for issignalingl ----------------------------------------===// +// +// 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 "IsSignalingTest.h" + +#include "src/math/issignalingl.h" + +LIST_ISSIGNALING_TESTS(long double, LIBC_NAMESPACE::issignalingl)