[libc-commits] [libc] [libc][math] Implement `issignaling[f|l]` as a libc math function (PR #110556)

Shourya Goel via libc-commits libc-commits at lists.llvm.org
Mon Sep 30 23:11:46 PDT 2024


https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/110556

>From 3665111e2f0aed479f6c43ac4cf55ab9aa21dbbc Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 00:52:00 +0530
Subject: [PATCH 1/8] Implemented Issignaling

---
 libc/config/linux/aarch64/entrypoints.txt     |  3 +
 libc/config/linux/riscv/entrypoints.txt       |  3 +
 libc/config/linux/x86_64/entrypoints.txt      |  3 +
 libc/src/__support/FPUtil/BasicOperations.h   | 10 ++++
 libc/src/math/CMakeLists.txt                  |  4 ++
 libc/src/math/generic/CMakeLists.txt          | 30 ++++++++++
 libc/src/math/generic/issignaling.cpp         | 18 ++++++
 libc/src/math/generic/issignalingf.cpp        | 18 ++++++
 libc/src/math/generic/issignalingl.cpp        | 18 ++++++
 libc/src/math/issignaling.h                   | 20 +++++++
 libc/src/math/issignalingf.h                  | 20 +++++++
 libc/src/math/issignalingl.h                  | 20 +++++++
 libc/test/src/math/smoke/CMakeLists.txt       | 39 +++++++++++++
 libc/test/src/math/smoke/IsSignalingTest.h    | 58 +++++++++++++++++++
 libc/test/src/math/smoke/issignaling_test.cpp | 13 +++++
 .../test/src/math/smoke/issignalingf_test.cpp | 13 +++++
 .../test/src/math/smoke/issignalingl_test.cpp | 13 +++++
 17 files changed, 303 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/issignalingl.cpp
 create mode 100644 libc/src/math/issignaling.h
 create mode 100644 libc/src/math/issignalingf.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/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 64fbe1a250c0ba..21288d894705bc 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
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ff3d821c664c5b..135a46099cb1fc 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
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index dd658af3bfb674..d877e3d696c67a 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
diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 824c9bfb3947f3..5b14feabe441a7 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -247,6 +247,16 @@ 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);
+  if (LIBC_UNLIKELY(sx.is_signaling_nan())) {
+    return 1;
+  } else {
+    return 0;
+  }
+}
+
 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);
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3cba34fc249322..440f343f5c0bc0 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -302,6 +302,10 @@ 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(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 d0676d03420c68..17e014adcae984 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3377,6 +3377,36 @@ 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(
   isnan
   SRCS
diff --git a/libc/src/math/generic/issignaling.cpp b/libc/src/math/generic/issignaling.cpp
new file mode 100644
index 00000000000000..26220b4dec2004
--- /dev/null
+++ b/libc/src/math/generic/issignaling.cpp
@@ -0,0 +1,18 @@
+//===-- 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 00000000000000..d2e3e2633225ab
--- /dev/null
+++ b/libc/src/math/generic/issignalingf.cpp
@@ -0,0 +1,18 @@
+//===-- 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/issignalingl.cpp b/libc/src/math/generic/issignalingl.cpp
new file mode 100644
index 00000000000000..8b111d91e7ccf1
--- /dev/null
+++ b/libc/src/math/generic/issignalingl.cpp
@@ -0,0 +1,18 @@
+//===-- 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 00000000000000..093fd7d48770dd
--- /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 00000000000000..97522600916cce
--- /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/issignalingl.h b/libc/src/math/issignalingl.h
new file mode 100644
index 00000000000000..edc039416d1f4e
--- /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 9f9203c491d044..bb89f75a8fdad0 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1597,6 +1597,45 @@ 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
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  issignalingf_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    issignalingf_test.cpp
+  HDRS
+    IsSignalingTest.h
+  DEPENDS
+    libc.src.math.issignalingf
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  issignalingl_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    issignalingl_test.cpp
+  HDRS
+    IsSignalingTest.h
+  DEPENDS
+    libc.src.math.issignalingl
+    libc.src.__support.FPUtil.fp_bits
+)
+
 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 00000000000000..6beabfcd775144
--- /dev/null
+++ b/libc/test/src/math/smoke/IsSignalingTest.h
@@ -0,0 +1,58 @@
+//===-- Utility class to test issignaling[f|l] ------------------*- 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 <typename T>
+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<T>;                          \
+  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 00000000000000..4292cbbb852b49
--- /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/issignalingf_test.cpp b/libc/test/src/math/smoke/issignalingf_test.cpp
new file mode 100644
index 00000000000000..0ceb9a80c03108
--- /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 00000000000000..049769009ba7c6
--- /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)

>From 54458ba8fadd5b189d6921e609c246d286d429ab Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 00:52:49 +0530
Subject: [PATCH 2/8] ran fmt

---
 libc/src/math/generic/issignaling.cpp      | 4 +++-
 libc/src/math/generic/issignalingf.cpp     | 4 +++-
 libc/src/math/generic/issignalingl.cpp     | 7 +++++--
 libc/test/src/math/smoke/IsSignalingTest.h | 4 +++-
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/libc/src/math/generic/issignaling.cpp b/libc/src/math/generic/issignaling.cpp
index 26220b4dec2004..0687a32817b295 100644
--- a/libc/src/math/generic/issignaling.cpp
+++ b/libc/src/math/generic/issignaling.cpp
@@ -13,6 +13,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, issignaling, (double x)) { return fputil::issignaling(x); }
+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
index d2e3e2633225ab..410bf7b4d42782 100644
--- a/libc/src/math/generic/issignalingf.cpp
+++ b/libc/src/math/generic/issignalingf.cpp
@@ -13,6 +13,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, issignalingf, (float x)) { return fputil::issignaling(x); }
+LLVM_LIBC_FUNCTION(int, issignalingf, (float 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
index 8b111d91e7ccf1..b399bd2d5bc6a7 100644
--- a/libc/src/math/generic/issignalingl.cpp
+++ b/libc/src/math/generic/issignalingl.cpp
@@ -1,4 +1,5 @@
-//===-- Implementation of issignalingl function ----------------------------===//
+//===-- 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.
@@ -13,6 +14,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-LLVM_LIBC_FUNCTION(int, issignalingl, (long double x)) { return fputil::issignaling(x); }
+LLVM_LIBC_FUNCTION(int, issignalingl, (long double x)) {
+  return fputil::issignaling(x);
+}
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/IsSignalingTest.h b/libc/test/src/math/smoke/IsSignalingTest.h
index 6beabfcd775144..60773e2ccc4161 100644
--- a/libc/test/src/math/smoke/IsSignalingTest.h
+++ b/libc/test/src/math/smoke/IsSignalingTest.h
@@ -52,7 +52,9 @@ class IssignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
 #define LIST_ISSIGNALING_TESTS(T, func)                                        \
   using LlvmLibcIsSignalingTest = IssignalingTest<T>;                          \
-  TEST_F(LlvmLibcIsSignalingTest, SpecialNumbers) { testSpecialNumbers(&func); }\
+  TEST_F(LlvmLibcIsSignalingTest, SpecialNumbers) {                            \
+    testSpecialNumbers(&func);                                                 \
+  }                                                                            \
   TEST_F(LlvmLibcIsSignalingTest, RoundedNubmers) { testRoundedNumbers(&func); }
 
 #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H

>From 275756cd5f00727116a75418178d32f394737d1d Mon Sep 17 00:00:00 2001
From: Shourya Goel <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:16:25 +0530
Subject: [PATCH 3/8] Update issignalingl.cpp

---
 libc/src/math/generic/issignalingl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/src/math/generic/issignalingl.cpp b/libc/src/math/generic/issignalingl.cpp
index b399bd2d5bc6a7..a3959bcae23575 100644
--- a/libc/src/math/generic/issignalingl.cpp
+++ b/libc/src/math/generic/issignalingl.cpp
@@ -1,5 +1,4 @@
-//===-- Implementation of issignalingl function
-//----------------------------===//
+//===-- 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.

>From 10976a1c5bb05bdabcf8d9c0d75c0f9d9f405e71 Mon Sep 17 00:00:00 2001
From: Shourya Goel <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:28:13 +0530
Subject: [PATCH 4/8] Update BasicOperations.h

---
 libc/src/__support/FPUtil/BasicOperations.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 5b14feabe441a7..4e6ca52c18b479 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -250,11 +250,8 @@ LIBC_INLINE T fdim(T x, T y) {
 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);
-  if (LIBC_UNLIKELY(sx.is_signaling_nan())) {
-    return 1;
-  } else {
-    return 0;
-  }
+  if (LIBC_UNLIKELY(sx.is_signaling_nan())) return 1;
+  return 0;
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>

>From 9491674459ab2886b1cd8105f2b2bcff8dc52eea Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:39:22 +0530
Subject: [PATCH 5/8] fmt

---
 libc/src/__support/FPUtil/BasicOperations.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index 4e6ca52c18b479..90e977234af056 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -250,7 +250,8 @@ LIBC_INLINE T fdim(T x, T y) {
 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);
-  if (LIBC_UNLIKELY(sx.is_signaling_nan())) return 1;
+  if (LIBC_UNLIKELY(sx.is_signaling_nan()))
+    return 1;
   return 0;
 }
 

>From df276bf3e580b2365d5ffe67348f574fd3395949 Mon Sep 17 00:00:00 2001
From: Shourya Goel <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:46:20 +0530
Subject: [PATCH 6/8] Update IsSignalingTest.h

---
 libc/test/src/math/smoke/IsSignalingTest.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/test/src/math/smoke/IsSignalingTest.h b/libc/test/src/math/smoke/IsSignalingTest.h
index 60773e2ccc4161..1d15df81c50102 100644
--- a/libc/test/src/math/smoke/IsSignalingTest.h
+++ b/libc/test/src/math/smoke/IsSignalingTest.h
@@ -16,7 +16,7 @@
 #include "hdr/math_macros.h"
 
 template <typename T>
-class IssignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+class IsSignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 
   DECLARE_SPECIAL_CONSTANTS(T)
 
@@ -51,7 +51,7 @@ class IssignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
 };
 
 #define LIST_ISSIGNALING_TESTS(T, func)                                        \
-  using LlvmLibcIsSignalingTest = IssignalingTest<T>;                          \
+  using LlvmLibcIsSignalingTest = IsSignalingTest<T>;                          \
   TEST_F(LlvmLibcIsSignalingTest, SpecialNumbers) {                            \
     testSpecialNumbers(&func);                                                 \
   }                                                                            \

>From e5da8cc1a56b7311599214f2f5fb18bac794ac7a Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 11:34:56 +0530
Subject: [PATCH 7/8] add f16 and f128

---
 libc/config/linux/aarch64/entrypoints.txt     |  2 ++
 libc/config/linux/riscv/entrypoints.txt       |  1 +
 libc/config/linux/x86_64/entrypoints.txt      |  2 ++
 libc/src/math/CMakeLists.txt                  |  2 ++
 libc/src/math/generic/CMakeLists.txt          | 24 +++++++++++++++++
 libc/src/math/generic/issignalingf128.cpp     | 20 ++++++++++++++
 libc/src/math/generic/issignalingf16.cpp      | 20 ++++++++++++++
 libc/src/math/issignalingf128.h               | 21 +++++++++++++++
 libc/src/math/issignalingf16.h                | 21 +++++++++++++++
 libc/test/src/math/smoke/CMakeLists.txt       | 26 +++++++++++++++++++
 .../src/math/smoke/issignalingf128_test.cpp   | 13 ++++++++++
 .../src/math/smoke/issignalingf16_test.cpp    | 13 ++++++++++
 12 files changed, 165 insertions(+)
 create mode 100644 libc/src/math/generic/issignalingf128.cpp
 create mode 100644 libc/src/math/generic/issignalingf16.cpp
 create mode 100644 libc/src/math/issignalingf128.h
 create mode 100644 libc/src/math/issignalingf16.h
 create mode 100644 libc/test/src/math/smoke/issignalingf128_test.cpp
 create mode 100644 libc/test/src/math/smoke/issignalingf16_test.cpp

diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 21288d894705bc..8313d2779d8892 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -593,6 +593,7 @@ set(TARGET_LIBM_ENTRYPOINTS
 if(LIBC_TYPES_HAS_FLOAT16)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float16 entrypoints
+    libc.src.math.issignalingf16
     libc.src.math.canonicalizef16
     libc.src.math.ceilf16
     libc.src.math.copysignf16
@@ -689,6 +690,7 @@ endif()
 if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float128 entrypoints
+    libc.src.math.issignalingf128
     libc.src.math.canonicalizef128
     libc.src.math.ceilf128
     libc.src.math.copysignf128
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 135a46099cb1fc..1f73afd95cf8c8 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -596,6 +596,7 @@ set(TARGET_LIBM_ENTRYPOINTS
 if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float128 entrypoints
+    libc.src.math.issignalingf128
     libc.src.math.canonicalizef128
     libc.src.math.ceilf128
     libc.src.math.copysignf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index d877e3d696c67a..58231d2ca52fee 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -596,6 +596,7 @@ set(TARGET_LIBM_ENTRYPOINTS
 if(LIBC_TYPES_HAS_FLOAT16)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float16 entrypoints
+    libc.src.math.issignalingf16
     libc.src.math.canonicalizef16
     libc.src.math.ceilf16
     libc.src.math.copysignf16
@@ -686,6 +687,7 @@ endif()
 if(LIBC_TYPES_HAS_FLOAT128)
   list(APPEND TARGET_LIBM_ENTRYPOINTS
     # math.h C23 _Float128 entrypoints
+    libc.src.math.issignalingf128
     libc.src.math.canonicalizef128
     libc.src.math.ceilf128
     libc.src.math.copysignf128
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 440f343f5c0bc0..dab5bb43ed59ce 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -305,6 +305,8 @@ 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)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 17e014adcae984..1fef02fce324b3 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -3397,6 +3397,30 @@ add_entrypoint_object(
     -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(
   issignalingl
   SRCS
diff --git a/libc/src/math/generic/issignalingf128.cpp b/libc/src/math/generic/issignalingf128.cpp
new file mode 100644
index 00000000000000..29612ccf677f67
--- /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 00000000000000..976b8e2b689b3c
--- /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/issignalingf128.h b/libc/src/math/issignalingf128.h
new file mode 100644
index 00000000000000..7d1bfdec646de8
--- /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 00000000000000..2b38525e1a3e07
--- /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/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index bb89f75a8fdad0..09bf57cd0b8cd4 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1623,6 +1623,32 @@ add_fp_unittest(
     libc.src.__support.FPUtil.fp_bits
 )
 
+add_fp_unittest(
+  issignalingf16_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    issignalingf16_test.cpp
+  HDRS
+    IsSignalingTest.h
+  DEPENDS
+    libc.src.math.issignalingf16
+    libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+  issignalingf128_test
+  SUITE
+    libc-math-smoke-tests
+  SRCS
+    issignalingf128_test.cpp
+  HDRS
+    IsSignalingTest.h
+  DEPENDS
+    libc.src.math.issignalingf128
+    libc.src.__support.FPUtil.fp_bits
+)
+
 add_fp_unittest(
   issignalingl_test
   SUITE
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 00000000000000..929e32a8facdd5
--- /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 00000000000000..fc2a65a3291838
--- /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)

>From 690fa67d6815f07309c5a73edbeadf21b147c8ad Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 11:41:29 +0530
Subject: [PATCH 8/8] nit

---
 libc/test/src/math/smoke/IsSignalingTest.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/test/src/math/smoke/IsSignalingTest.h b/libc/test/src/math/smoke/IsSignalingTest.h
index 1d15df81c50102..f52642ad27bea9 100644
--- a/libc/test/src/math/smoke/IsSignalingTest.h
+++ b/libc/test/src/math/smoke/IsSignalingTest.h
@@ -1,4 +1,4 @@
-//===-- Utility class to test issignaling[f|l] ------------------*- C++ -*-===//
+//===-- 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.



More information about the libc-commits mailing list