[libc-commits] [libc] [libc][math] Implement `iscanonical[f|l]` as a libc math function (PR #110565)
Shourya Goel via libc-commits
libc-commits at lists.llvm.org
Tue Oct 1 10:52:33 PDT 2024
https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/110565
>From 4515515a08fe7663958825e0095b78be357794ed Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:36:21 +0530
Subject: [PATCH 01/10] init
---
libc/config/linux/aarch64/entrypoints.txt | 3 +++
libc/config/linux/riscv/entrypoints.txt | 3 +++
libc/config/linux/x86_64/entrypoints.txt | 3 +++
libc/src/math/CMakeLists.txt | 4 +++
libc/src/math/generic/CMakeLists.txt | 31 +++++++++++++++++++++++
libc/src/math/generic/iscanonical.cpp | 22 ++++++++++++++++
libc/src/math/generic/iscanonicalf.cpp | 22 ++++++++++++++++
libc/src/math/generic/iscanonicall.cpp | 22 ++++++++++++++++
libc/src/math/iscanonical.h | 20 +++++++++++++++
libc/src/math/iscanonicalf.h | 20 +++++++++++++++
libc/src/math/iscanonicall.h | 20 +++++++++++++++
11 files changed, 170 insertions(+)
create mode 100644 libc/src/math/generic/iscanonical.cpp
create mode 100644 libc/src/math/generic/iscanonicalf.cpp
create mode 100644 libc/src/math/generic/iscanonicall.cpp
create mode 100644 libc/src/math/iscanonical.h
create mode 100644 libc/src/math/iscanonicalf.h
create mode 100644 libc/src/math/iscanonicall.h
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 64fbe1a250c0ba..313f429541a574 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -378,6 +378,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index ff3d821c664c5b..7d06774661bd7b 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -377,6 +377,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index dd658af3bfb674..3d2a94fe2b1f0c 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -377,6 +377,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 3cba34fc249322..a2c63b4ea70587 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -66,6 +66,10 @@ add_math_entrypoint_object(canonicalizel)
add_math_entrypoint_object(canonicalizef16)
add_math_entrypoint_object(canonicalizef128)
+add_math_entrypoint_object(iscanonical)
+add_math_entrypoint_object(iscanonicalf)
+add_math_entrypoint_object(iscanonicall)
+
add_math_entrypoint_object(cbrt)
add_math_entrypoint_object(cbrtf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index d0676d03420c68..c1f8856348af28 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -60,6 +60,37 @@ add_entrypoint_object(
libc.src.__support.FPUtil.basic_operations
)
+add_entrypoint_object(
+ iscanonical
+ SRCS
+ iscanonical.cpp
+ HDRS
+ ../iscanonical.h
+ COMPILE_OPTIONS
+ -O3
+)
+
+add_entrypoint_object(
+ iscanonicalf
+ SRCS
+ iscanonicalf.cpp
+ HDRS
+ ../iscanonicalf.h
+ COMPILE_OPTIONS
+ -O3
+)
+
+add_entrypoint_object(
+ iscanonicall
+ SRCS
+ iscanonicall.cpp
+ HDRS
+ ../iscanonicall.h
+ COMPILE_OPTIONS
+ -O3
+)
+
+
add_entrypoint_object(
ceil
SRCS
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
new file mode 100644
index 00000000000000..c815778090a44d
--- /dev/null
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonical 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/iscanonical.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, iscanonical, (double x)) {
+ double temp;
+ if (fputil::canonicalize(temp, x) == 0) return 1;
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
new file mode 100644
index 00000000000000..3e81af2d0ce3e8
--- /dev/null
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonicalf 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/iscanonicalf.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, iscanonicalf, (float x)) {
+ float temp;
+ if (fputil::canonicalize(temp, x) == 0) return 1;
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
new file mode 100644
index 00000000000000..10bd0e101dae8a
--- /dev/null
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -0,0 +1,22 @@
+//===-- Implementation of iscanonicall 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/iscanonicall.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, iscanonicall, (long double x)) {
+ long double temp;
+ if (fputil::canonicalize(temp, x) == 0) return 1;
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/iscanonical.h b/libc/src/math/iscanonical.h
new file mode 100644
index 00000000000000..20f83161d45a89
--- /dev/null
+++ b/libc/src/math/iscanonical.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonical -------------------*- 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_ISCANONICAL_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICAL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonical(double x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
\ No newline at end of file
diff --git a/libc/src/math/iscanonicalf.h b/libc/src/math/iscanonicalf.h
new file mode 100644
index 00000000000000..4f599e12b1d884
--- /dev/null
+++ b/libc/src/math/iscanonicalf.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonicalf ------------------*- 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_ISCANONICALF_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALF_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicalf(float x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
\ No newline at end of file
diff --git a/libc/src/math/iscanonicall.h b/libc/src/math/iscanonicall.h
new file mode 100644
index 00000000000000..cb028f0dcbe428
--- /dev/null
+++ b/libc/src/math/iscanonicall.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for iscanonicall ------------------*- 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_ISCANONICALL_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALL_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicall(long double x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
\ No newline at end of file
>From 6f706d15018a80061184b727cdeec68e899137e5 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:36:30 +0530
Subject: [PATCH 02/10] fmt
---
libc/src/math/generic/iscanonical.cpp | 7 ++++---
libc/src/math/generic/iscanonicalf.cpp | 7 ++++---
libc/src/math/generic/iscanonicall.cpp | 7 ++++---
3 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index c815778090a44d..ce2a84ca8d830c 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -14,9 +14,10 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
- double temp;
- if (fputil::canonicalize(temp, x) == 0) return 1;
- return 0;
+ double temp;
+ if (fputil::canonicalize(temp, x) == 0)
+ return 1;
+ return 0;
}
} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 3e81af2d0ce3e8..3a84cea06ac0a1 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -14,9 +14,10 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
- float temp;
- if (fputil::canonicalize(temp, x) == 0) return 1;
- return 0;
+ float temp;
+ if (fputil::canonicalize(temp, x) == 0)
+ return 1;
+ return 0;
}
} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 10bd0e101dae8a..07e9df45ada5d0 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -14,9 +14,10 @@
namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
- long double temp;
- if (fputil::canonicalize(temp, x) == 0) return 1;
- return 0;
+ long double temp;
+ if (fputil::canonicalize(temp, x) == 0)
+ return 1;
+ return 0;
}
} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
>From aba8c185d7510b7691a42310527e5aef63bbcc14 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:49:03 +0530
Subject: [PATCH 03/10] tests
---
libc/test/src/math/smoke/CMakeLists.txt | 39 ++++++++++++
libc/test/src/math/smoke/IsCanonicalTest.h | 60 +++++++++++++++++++
libc/test/src/math/smoke/iscanonical_test.cpp | 13 ++++
.../test/src/math/smoke/iscanonicalf_test.cpp | 13 ++++
.../test/src/math/smoke/iscanonicall_test.cpp | 13 ++++
5 files changed, 138 insertions(+)
create mode 100644 libc/test/src/math/smoke/IsCanonicalTest.h
create mode 100644 libc/test/src/math/smoke/iscanonical_test.cpp
create mode 100644 libc/test/src/math/smoke/iscanonicalf_test.cpp
create mode 100644 libc/test/src/math/smoke/iscanonicall_test.cpp
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 9f9203c491d044..5385d571d1a7e1 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -327,6 +327,45 @@ add_fp_unittest(
libc.src.__support.integer_literals
)
+add_fp_unittest(
+ iscanonical_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ iscanonical_test.cpp
+ HDRS
+ IsCanonicalTest.h
+ DEPENDS
+ libc.src.math.iscanonical
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ iscanonicalf_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ iscanonicalf_test.cpp
+ HDRS
+ IsCanonicalTest.h
+ DEPENDS
+ libc.src.math.iscanonicalf
+ libc.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ iscanonicall_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ iscanonicall_test.cpp
+ HDRS
+ IsCanonicalTest.h
+ DEPENDS
+ libc.src.math.iscanonicall
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
ceil_test
SUITE
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
new file mode 100644
index 00000000000000..7d5a3ccaa7da23
--- /dev/null
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -0,0 +1,60 @@
+//===-- Utility class to test iscanonical[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_ISCANONICALTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_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 IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+ typedef int (*IsCanonicalFunc)(T);
+
+ void testSpecialNumbers(IsCanonicalFunc func) {
+ EXPECT_EQ(func(aNaN), 0);
+ EXPECT_EQ(func(neg_aNaN), 0);
+ EXPECT_EQ(func(sNaN), 0);
+ EXPECT_EQ(func(neg_sNaN), 0);
+ 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), 1);
+ EXPECT_EQ(func(neg_zero), 1);
+ }
+
+ void testRoundedNumbers(IsCanonicalFunc func) {
+ EXPECT_EQ(func(T(1.0)), 1);
+ EXPECT_EQ(func(T(-1.0)), 1);
+ EXPECT_EQ(func(T(10.0)), 1);
+ EXPECT_EQ(func(T(-10.0)), 1);
+ EXPECT_EQ(func(T(1234.0)), 1);
+ EXPECT_EQ(func(T(-1234.0)), 1);
+ }
+};
+
+#define LIST_ISCANONICAL_TESTS(T, func) \
+ using LlvmLibcIsCanonicalTest = IsCanonicalTest<T>; \
+ TEST_F(LlvmLibcIsCanonicalTest, SpecialNumbers) { \
+ testSpecialNumbers(&func); \
+ } \
+ TEST_F(LlvmLibcIsCanonicalTest, RoundedNubmers) { testRoundedNumbers(&func); }
+
+#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
\ No newline at end of file
diff --git a/libc/test/src/math/smoke/iscanonical_test.cpp b/libc/test/src/math/smoke/iscanonical_test.cpp
new file mode 100644
index 00000000000000..2dd1c2ac6f0451
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonical_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonical -----------------------------------------===//
+//
+// 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 "IsCanonicalTest.h"
+
+#include "src/math/iscanonical.h"
+
+LIST_ISCANONICAL_TESTS(double, LIBC_NAMESPACE::iscanonical)
diff --git a/libc/test/src/math/smoke/iscanonicalf_test.cpp b/libc/test/src/math/smoke/iscanonicalf_test.cpp
new file mode 100644
index 00000000000000..eba8688f61f940
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicalf_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicalf ----------------------------------------===//
+//
+// 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 "IsCanonicalTest.h"
+
+#include "src/math/iscanonicalf.h"
+
+LIST_ISCANONICAL_TESTS(float, LIBC_NAMESPACE::iscanonicalf)
diff --git a/libc/test/src/math/smoke/iscanonicall_test.cpp b/libc/test/src/math/smoke/iscanonicall_test.cpp
new file mode 100644
index 00000000000000..d180bcb7443e54
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicall_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicall ----------------------------------------===//
+//
+// 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 "IsCanonicalTest.h"
+
+#include "src/math/iscanonicall.h"
+
+LIST_ISCANONICAL_TESTS(long double, LIBC_NAMESPACE::iscanonicall)
>From 2a9c560b8cce6d8b65795dc4d25ad230c218ef64 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 01:55:22 +0530
Subject: [PATCH 04/10] Updated tests
---
libc/src/math/generic/iscanonical.cpp | 2 +-
libc/src/math/generic/iscanonicalf.cpp | 2 +-
libc/src/math/generic/iscanonicall.cpp | 2 +-
libc/src/math/iscanonical.h | 2 +-
libc/src/math/iscanonicalf.h | 2 +-
libc/src/math/iscanonicall.h | 2 +-
libc/test/src/math/smoke/IsCanonicalTest.h | 20 ++++++++++----------
7 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index ce2a84ca8d830c..6da76a43a1231c 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
return 0;
}
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 3a84cea06ac0a1..0662758353aac4 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
return 0;
}
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 07e9df45ada5d0..29459c7a9ad972 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -20,4 +20,4 @@ LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
return 0;
}
-} // namespace LIBC_NAMESPACE_DECL
\ No newline at end of file
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/iscanonical.h b/libc/src/math/iscanonical.h
index 20f83161d45a89..14b2d17c8bbe9a 100644
--- a/libc/src/math/iscanonical.h
+++ b/libc/src/math/iscanonical.h
@@ -17,4 +17,4 @@ int iscanonical(double x);
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICAL_H
diff --git a/libc/src/math/iscanonicalf.h b/libc/src/math/iscanonicalf.h
index 4f599e12b1d884..fdb48bc2767be4 100644
--- a/libc/src/math/iscanonicalf.h
+++ b/libc/src/math/iscanonicalf.h
@@ -17,4 +17,4 @@ int iscanonicalf(float x);
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF_H
diff --git a/libc/src/math/iscanonicall.h b/libc/src/math/iscanonicall.h
index cb028f0dcbe428..edda6e334f1ab9 100644
--- a/libc/src/math/iscanonicall.h
+++ b/libc/src/math/iscanonicall.h
@@ -17,4 +17,4 @@ int iscanonicall(long double x);
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
\ No newline at end of file
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALL_H
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
index 7d5a3ccaa7da23..47f21cde335a8f 100644
--- a/libc/test/src/math/smoke/IsCanonicalTest.h
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -24,18 +24,18 @@ class IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
typedef int (*IsCanonicalFunc)(T);
void testSpecialNumbers(IsCanonicalFunc func) {
- EXPECT_EQ(func(aNaN), 0);
- EXPECT_EQ(func(neg_aNaN), 0);
+ EXPECT_EQ(func(aNaN), 1);
+ EXPECT_EQ(func(neg_aNaN), 1);
EXPECT_EQ(func(sNaN), 0);
EXPECT_EQ(func(neg_sNaN), 0);
- 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(inf), 1);
+ EXPECT_EQ(func(neg_inf), 1);
+ EXPECT_EQ(func(min_normal), 1);
+ EXPECT_EQ(func(max_normal), 1);
+ EXPECT_EQ(func(neg_max_normal), 1);
+ EXPECT_EQ(func(min_denormal), 1);
+ EXPECT_EQ(func(neg_min_denormal), 1);
+ EXPECT_EQ(func(max_denormal), 1);
EXPECT_EQ(func(zero), 1);
EXPECT_EQ(func(neg_zero), 1);
}
>From 977c99fbd9bf14b4407215ddbaffa0cb3618dc6f Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 11:09:19 +0530
Subject: [PATCH 05/10] 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 | 26 +++++++++++++++++++
libc/src/math/generic/iscanonicalf128.cpp | 23 ++++++++++++++++
libc/src/math/generic/iscanonicalf16.cpp | 23 ++++++++++++++++
libc/src/math/iscanonicalf128.h | 21 +++++++++++++++
libc/src/math/iscanonicalf16.h | 21 +++++++++++++++
libc/test/src/math/smoke/CMakeLists.txt | 26 +++++++++++++++++++
.../src/math/smoke/iscanonicalf128_test.cpp | 13 ++++++++++
.../src/math/smoke/iscanonicalf16_test.cpp | 13 ++++++++++
12 files changed, 173 insertions(+)
create mode 100644 libc/src/math/generic/iscanonicalf128.cpp
create mode 100644 libc/src/math/generic/iscanonicalf16.cpp
create mode 100644 libc/src/math/iscanonicalf128.h
create mode 100644 libc/src/math/iscanonicalf16.h
create mode 100644 libc/test/src/math/smoke/iscanonicalf128_test.cpp
create mode 100644 libc/test/src/math/smoke/iscanonicalf16_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 313f429541a574..d43c495c3aaf73 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -594,6 +594,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
+ libc.src.math.iscanonicalf16
libc.src.math.ceilf16
libc.src.math.copysignf16
# TODO: aarch64 bug
@@ -690,6 +691,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
+ libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 7d06774661bd7b..8b25a406fd5565 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -597,6 +597,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
+ libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 3d2a94fe2b1f0c..cfbff032d635b5 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -597,6 +597,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
+ libc.src.math.iscanonicalf16
libc.src.math.ceilf16
libc.src.math.copysignf16
libc.src.math.exp10f16
@@ -687,6 +688,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
+ libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index a2c63b4ea70587..5464c6c7674aeb 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -69,6 +69,8 @@ add_math_entrypoint_object(canonicalizef128)
add_math_entrypoint_object(iscanonical)
add_math_entrypoint_object(iscanonicalf)
add_math_entrypoint_object(iscanonicall)
+add_math_entrypoint_object(iscanonicalf16)
+add_math_entrypoint_object(iscanonicalf128)
add_math_entrypoint_object(cbrt)
add_math_entrypoint_object(cbrtf)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index c1f8856348af28..ae2599ee3dd484 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -80,6 +80,32 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ iscanonicalf16
+ SRCS
+ iscanonicalf16.cpp
+ HDRS
+ ../iscanonicalf16.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+)
+
+add_entrypoint_object(
+ iscanonicalf128
+ SRCS
+ iscanonicalf128.cpp
+ HDRS
+ ../iscanonicalf128.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ libc.src.__support.macros.properties.types
+ libc.src.__support.FPUtil.basic_operations
+)
+
add_entrypoint_object(
iscanonicall
SRCS
diff --git a/libc/src/math/generic/iscanonicalf128.cpp b/libc/src/math/generic/iscanonicalf128.cpp
new file mode 100644
index 00000000000000..aef8053a1f519e
--- /dev/null
+++ b/libc/src/math/generic/iscanonicalf128.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of iscanonicalf128 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/iscanonicalf128.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, iscanonicalf128, (float128 x)) {
+ float128 temp;
+ if (fputil::canonicalize(temp, x) == 0)
+ return 1;
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf16.cpp b/libc/src/math/generic/iscanonicalf16.cpp
new file mode 100644
index 00000000000000..a9abb897d28fc7
--- /dev/null
+++ b/libc/src/math/generic/iscanonicalf16.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of iscanonicalf16 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/iscanonicalf16.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, iscanonicalf16, (float16 x)) {
+ float16 temp;
+ if (fputil::canonicalize(temp, x) == 0)
+ return 1;
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/iscanonicalf128.h b/libc/src/math/iscanonicalf128.h
new file mode 100644
index 00000000000000..9ba021c86ec147
--- /dev/null
+++ b/libc/src/math/iscanonicalf128.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for iscanonicalf128 ---------------*- 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_ISCANONICALF128_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALF128_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicalf128(float128 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF128_H
diff --git a/libc/src/math/iscanonicalf16.h b/libc/src/math/iscanonicalf16.h
new file mode 100644
index 00000000000000..565d3eae35c49c
--- /dev/null
+++ b/libc/src/math/iscanonicalf16.h
@@ -0,0 +1,21 @@
+//===-- Implementation header for iscanonicalf16 ----------------*- 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_ISCANONICALF16_H
+#define LLVM_LIBC_SRC_MATH_ISCANONICALF16_H
+
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+int iscanonicalf16(float16 x);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ISCANONICALF16_H
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 5385d571d1a7e1..7911b6c87117df 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -353,6 +353,32 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)
+add_fp_unittest(
+ iscanonicalf16_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ iscanonicalf16_test.cpp
+ HDRS
+ IsCanonicalTest.h
+ DEPENDS
+ libc.src.math.iscanonicalf16
+ lib.src.__support.FPUtil.fp_bits
+)
+
+add_fp_unittest(
+ iscanonicalf128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ iscanonicalf128_test.cpp
+ HDRS
+ IsCanonicalTest.h
+ DEPENDS
+ libc.src.math.iscanonicalf128
+ libc.src.__support.FPUtil.fp_bits
+)
+
add_fp_unittest(
iscanonicall_test
SUITE
diff --git a/libc/test/src/math/smoke/iscanonicalf128_test.cpp b/libc/test/src/math/smoke/iscanonicalf128_test.cpp
new file mode 100644
index 00000000000000..0176ae2f223dad
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicalf128_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicalf128 -------------------------------------===//
+//
+// 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 "IsCanonicalTest.h"
+
+#include "src/math/iscanonicalf128.h"
+
+LIST_ISCANONICAL_TESTS(float128, LIBC_NAMESPACE::iscanonicalf128)
diff --git a/libc/test/src/math/smoke/iscanonicalf16_test.cpp b/libc/test/src/math/smoke/iscanonicalf16_test.cpp
new file mode 100644
index 00000000000000..d17d79f86139e0
--- /dev/null
+++ b/libc/test/src/math/smoke/iscanonicalf16_test.cpp
@@ -0,0 +1,13 @@
+//===-- Unittests for iscanonicalf16 --------------------------------------===//
+//
+// 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 "IsCanonicalTest.h"
+
+#include "src/math/iscanonicalf16.h"
+
+LIST_ISCANONICAL_TESTS(float16, LIBC_NAMESPACE::iscanonicalf16)
>From 2bdfae42d4af26500cd830f4a84cec67e7346f6c Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 11:13:20 +0530
Subject: [PATCH 06/10] nits
---
libc/src/math/generic/CMakeLists.txt | 2 --
libc/test/src/math/smoke/IsCanonicalTest.h | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index ae2599ee3dd484..477f8e4d831147 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -90,7 +90,6 @@ add_entrypoint_object(
-O3
DEPENDS
libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
)
add_entrypoint_object(
@@ -103,7 +102,6 @@ add_entrypoint_object(
-O3
DEPENDS
libc.src.__support.macros.properties.types
- libc.src.__support.FPUtil.basic_operations
)
add_entrypoint_object(
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
index 47f21cde335a8f..70e2c9d1d6b7b7 100644
--- a/libc/test/src/math/smoke/IsCanonicalTest.h
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -57,4 +57,4 @@ class IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
} \
TEST_F(LlvmLibcIsCanonicalTest, RoundedNubmers) { testRoundedNumbers(&func); }
-#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
\ No newline at end of file
+#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISCANONICALTEST_H
>From cc56fb5733a8d574eb070fb49bf030bc7b07fe96 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 11:21:42 +0530
Subject: [PATCH 07/10] nit
---
libc/test/src/math/smoke/IsCanonicalTest.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
index 70e2c9d1d6b7b7..9eaf43217ca4f2 100644
--- a/libc/test/src/math/smoke/IsCanonicalTest.h
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -1,4 +1,4 @@
-//===-- Utility class to test iscanonical[f|l] ------------------*- C++ -*-===//
+//===-- Utility class to test different flavors of iscanonical --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From 151c7e92d2e427f253eb6009a3c8fc8635148d9d Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 12:41:54 +0530
Subject: [PATCH 08/10] nits
---
libc/config/linux/aarch64/entrypoints.txt | 10 +++++-----
libc/config/linux/riscv/entrypoints.txt | 8 ++++----
libc/config/linux/x86_64/entrypoints.txt | 10 +++++-----
libc/src/math/generic/CMakeLists.txt | 21 ++++++++++-----------
libc/src/math/generic/iscanonical.cpp | 4 +---
libc/src/math/generic/iscanonicalf.cpp | 4 +---
libc/src/math/generic/iscanonicalf128.cpp | 4 +---
libc/src/math/generic/iscanonicalf16.cpp | 4 +---
libc/src/math/generic/iscanonicall.cpp | 4 +---
libc/test/src/math/smoke/CMakeLists.txt | 22 +++++++++++-----------
10 files changed, 40 insertions(+), 51 deletions(-)
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index d43c495c3aaf73..34ea3301670121 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -378,9 +378,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
- libc.src.math.iscanonical
- libc.src.math.iscanonicalf
- libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
@@ -479,6 +476,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
@@ -594,7 +594,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
- libc.src.math.iscanonicalf16
libc.src.math.ceilf16
libc.src.math.copysignf16
# TODO: aarch64 bug
@@ -641,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.ilogbf16
+ libc.src.math.iscanonicalf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
@@ -691,7 +691,6 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
- libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
@@ -725,6 +724,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
+ libc.src.math.iscanonicalf128
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 8b25a406fd5565..270fb8debc0d9a 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -377,9 +377,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
- libc.src.math.iscanonical
- libc.src.math.iscanonicalf
- libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
@@ -482,6 +479,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
@@ -597,7 +597,6 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
- libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
@@ -631,6 +630,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
+ libc.src.math.iscanonicalf128
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 cfbff032d635b5..8f93af57bc0c3a 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -377,9 +377,6 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.canonicalize
libc.src.math.canonicalizef
libc.src.math.canonicalizel
- libc.src.math.iscanonical
- libc.src.math.iscanonicalf
- libc.src.math.iscanonicall
libc.src.math.cbrt
libc.src.math.cbrtf
libc.src.math.ceil
@@ -482,6 +479,9 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.ilogb
libc.src.math.ilogbf
libc.src.math.ilogbl
+ libc.src.math.iscanonical
+ libc.src.math.iscanonicalf
+ libc.src.math.iscanonicall
libc.src.math.isnan
libc.src.math.isnanf
libc.src.math.isnanl
@@ -597,7 +597,6 @@ if(LIBC_TYPES_HAS_FLOAT16)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float16 entrypoints
libc.src.math.canonicalizef16
- libc.src.math.iscanonicalf16
libc.src.math.ceilf16
libc.src.math.copysignf16
libc.src.math.exp10f16
@@ -641,6 +640,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
libc.src.math.fromfpxf16
libc.src.math.getpayloadf16
libc.src.math.ilogbf16
+ libc.src.math.iscanonicalf16
libc.src.math.ldexpf16
libc.src.math.llogbf16
libc.src.math.llrintf16
@@ -688,7 +688,6 @@ if(LIBC_TYPES_HAS_FLOAT128)
list(APPEND TARGET_LIBM_ENTRYPOINTS
# math.h C23 _Float128 entrypoints
libc.src.math.canonicalizef128
- libc.src.math.iscanonicalf128
libc.src.math.ceilf128
libc.src.math.copysignf128
libc.src.math.daddf128
@@ -722,6 +721,7 @@ if(LIBC_TYPES_HAS_FLOAT128)
libc.src.math.fsubf128
libc.src.math.getpayloadf128
libc.src.math.ilogbf128
+ libc.src.math.iscanonicalf128
libc.src.math.ldexpf128
libc.src.math.llogbf128
libc.src.math.llrintf128
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 477f8e4d831147..90deec4b964287 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -80,6 +80,16 @@ add_entrypoint_object(
-O3
)
+add_entrypoint_object(
+ iscanonicall
+ SRCS
+ iscanonicall.cpp
+ HDRS
+ ../iscanonicall.h
+ COMPILE_OPTIONS
+ -O3
+)
+
add_entrypoint_object(
iscanonicalf16
SRCS
@@ -104,17 +114,6 @@ add_entrypoint_object(
libc.src.__support.macros.properties.types
)
-add_entrypoint_object(
- iscanonicall
- SRCS
- iscanonicall.cpp
- HDRS
- ../iscanonicall.h
- COMPILE_OPTIONS
- -O3
-)
-
-
add_entrypoint_object(
ceil
SRCS
diff --git a/libc/src/math/generic/iscanonical.cpp b/libc/src/math/generic/iscanonical.cpp
index 6da76a43a1231c..d67a6b87b3e506 100644
--- a/libc/src/math/generic/iscanonical.cpp
+++ b/libc/src/math/generic/iscanonical.cpp
@@ -15,9 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonical, (double x)) {
double temp;
- if (fputil::canonicalize(temp, x) == 0)
- return 1;
- return 0;
+ return static_cast<int>(fputil::canonicalize(temp, x) == 0);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf.cpp b/libc/src/math/generic/iscanonicalf.cpp
index 0662758353aac4..daa0708794d2f4 100644
--- a/libc/src/math/generic/iscanonicalf.cpp
+++ b/libc/src/math/generic/iscanonicalf.cpp
@@ -15,9 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf, (float x)) {
float temp;
- if (fputil::canonicalize(temp, x) == 0)
- return 1;
- return 0;
+ return static_cast<int>(fputil::canonicalize(temp, x) == 0);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf128.cpp b/libc/src/math/generic/iscanonicalf128.cpp
index aef8053a1f519e..9be50050f8234c 100644
--- a/libc/src/math/generic/iscanonicalf128.cpp
+++ b/libc/src/math/generic/iscanonicalf128.cpp
@@ -15,9 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf128, (float128 x)) {
float128 temp;
- if (fputil::canonicalize(temp, x) == 0)
- return 1;
- return 0;
+ return static_cast<int>(fputil::canonicalize(temp, x) == 0);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicalf16.cpp b/libc/src/math/generic/iscanonicalf16.cpp
index a9abb897d28fc7..4f7bb1a0050f51 100644
--- a/libc/src/math/generic/iscanonicalf16.cpp
+++ b/libc/src/math/generic/iscanonicalf16.cpp
@@ -15,9 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicalf16, (float16 x)) {
float16 temp;
- if (fputil::canonicalize(temp, x) == 0)
- return 1;
- return 0;
+ return static_cast<int>(fputil::canonicalize(temp, x) == 0);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/iscanonicall.cpp b/libc/src/math/generic/iscanonicall.cpp
index 29459c7a9ad972..756c1f8fb4abfa 100644
--- a/libc/src/math/generic/iscanonicall.cpp
+++ b/libc/src/math/generic/iscanonicall.cpp
@@ -15,9 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(int, iscanonicall, (long double x)) {
long double temp;
- if (fputil::canonicalize(temp, x) == 0)
- return 1;
- return 0;
+ return static_cast<int>(fputil::canonicalize(temp, x) == 0);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 7911b6c87117df..4306f935982e4b 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -354,41 +354,41 @@ add_fp_unittest(
)
add_fp_unittest(
- iscanonicalf16_test
+ iscanonicall_test
SUITE
libc-math-smoke-tests
SRCS
- iscanonicalf16_test.cpp
+ iscanonicall_test.cpp
HDRS
IsCanonicalTest.h
DEPENDS
- libc.src.math.iscanonicalf16
- lib.src.__support.FPUtil.fp_bits
+ libc.src.math.iscanonicall
+ libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
- iscanonicalf128_test
+ iscanonicalf16_test
SUITE
libc-math-smoke-tests
SRCS
- iscanonicalf128_test.cpp
+ iscanonicalf16_test.cpp
HDRS
IsCanonicalTest.h
DEPENDS
- libc.src.math.iscanonicalf128
- libc.src.__support.FPUtil.fp_bits
+ libc.src.math.iscanonicalf16
+ lib.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
- iscanonicall_test
+ iscanonicalf128_test
SUITE
libc-math-smoke-tests
SRCS
- iscanonicall_test.cpp
+ iscanonicalf128_test.cpp
HDRS
IsCanonicalTest.h
DEPENDS
- libc.src.math.iscanonicall
+ libc.src.math.iscanonicalf128
libc.src.__support.FPUtil.fp_bits
)
>From 2ad11efc5a5e8d19fbf40f3a2b9a750a8878fbb2 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 13:01:01 +0530
Subject: [PATCH 09/10] nit
---
libc/test/src/math/smoke/CMakeLists.txt | 5 -----
libc/test/src/math/smoke/IsCanonicalTest.h | 2 --
2 files changed, 7 deletions(-)
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index 4306f935982e4b..5201c798bb9ecb 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -337,7 +337,6 @@ add_fp_unittest(
IsCanonicalTest.h
DEPENDS
libc.src.math.iscanonical
- libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
@@ -350,7 +349,6 @@ add_fp_unittest(
IsCanonicalTest.h
DEPENDS
libc.src.math.iscanonicalf
- libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
@@ -363,7 +361,6 @@ add_fp_unittest(
IsCanonicalTest.h
DEPENDS
libc.src.math.iscanonicall
- libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
@@ -376,7 +373,6 @@ add_fp_unittest(
IsCanonicalTest.h
DEPENDS
libc.src.math.iscanonicalf16
- lib.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
@@ -389,7 +385,6 @@ add_fp_unittest(
IsCanonicalTest.h
DEPENDS
libc.src.math.iscanonicalf128
- libc.src.__support.FPUtil.fp_bits
)
add_fp_unittest(
diff --git a/libc/test/src/math/smoke/IsCanonicalTest.h b/libc/test/src/math/smoke/IsCanonicalTest.h
index 9eaf43217ca4f2..8b6554b97f0351 100644
--- a/libc/test/src/math/smoke/IsCanonicalTest.h
+++ b/libc/test/src/math/smoke/IsCanonicalTest.h
@@ -13,8 +13,6 @@
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
-#include "hdr/math_macros.h"
-
template <typename T>
class IsCanonicalTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
>From 07f3aee3f4a766f1dc6f5ab77bff112754f8eddb Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Tue, 1 Oct 2024 21:40:49 +0530
Subject: [PATCH 10/10] doc
---
libc/docs/math/index.rst | 2 ++
libc/spec/stdc.td | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/libc/docs/math/index.rst b/libc/docs/math/index.rst
index 185d2d440849a0..66efc66dd84f43 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 |
+------------------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
+| iscanonical | |check| | |check| | |check| | |check| | |check| | 7.12.3.2 | 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 7caf543748151a..a77af5eaa4eb44 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -831,6 +831,12 @@ def StdC : StandardSpec<"stdc"> {
GuardedFunctionSpec<"canonicalizef16", RetValSpec<IntType>, [ArgSpec<Float16Type>, ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
GuardedFunctionSpec<"canonicalizef128", RetValSpec<IntType>, [ArgSpec<Float128Type>, ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+ FunctionSpec<"iscanonical", RetValSpec<IntType>, [ArgSpec<DoubleType>]>,
+ FunctionSpec<"iscanonicalf", RetValSpec<IntType>, [ArgSpec<FloatType>]>,
+ FunctionSpec<"iscanonicall", RetValSpec<IntType>, [ArgSpec<LongDoubleType>]>,
+ GuardedFunctionSpec<"iscanonicalf16", RetValSpec<IntType>, [ArgSpec<Float16Type>], "LIBC_TYPES_HAS_FLOAT16">,
+ GuardedFunctionSpec<"iscanonicalf128", RetValSpec<IntType>, [ArgSpec<Float128Type>], "LIBC_TYPES_HAS_FLOAT128">,
+
FunctionSpec<"dsqrtl", RetValSpec<DoubleType>, [ArgSpec<LongDoubleType>]>,
FunctionSpec<"totalorder", RetValSpec<IntType>, [ArgSpec<ConstDoublePtr>, ArgSpec<ConstDoublePtr>]>,
More information about the libc-commits
mailing list