Skip to content

[libc][math] implement signbit and math macro unit tests #97791

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 14, 2024

Conversation

akielaries
Copy link
Contributor

@akielaries akielaries commented Jul 5, 2024

This PR resolves #96322 and implements the signbit macro under a new header generic-math-macros.h. This also removed the TODO in math-macros.h and moves isfinite, isinf, and isnan to the same generic maths header. Finally, a test file generic-math-macros_test.cpp that adds coverage to the above 4 macros.

Copy link

github-actions bot commented Jul 5, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@akielaries akielaries marked this pull request as ready for review July 6, 2024 00:49
@llvmbot llvmbot added the libc label Jul 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 6, 2024

@llvm/pr-subscribers-libc

Author: Akiel Aries (akielaries)

Changes

This PR addresses #96322 and implements the signbit macro under a new header generic-math-macros.h. This also removed the TODO in math-macros.h and moves isfinite, isinf, and isnan to the same generic maths header. Finally, a test file generic-math-macros_test.cpp that adds coverage to the above 4 macros.


Full diff: https://github.com/llvm/llvm-project/pull/97791.diff

5 Files Affected:

  • (modified) libc/include/llvm-libc-macros/CMakeLists.txt (+6)
  • (added) libc/include/llvm-libc-macros/generic-math-macros.h (+20)
  • (modified) libc/include/llvm-libc-macros/math-macros.h (-5)
  • (modified) libc/test/include/CMakeLists.txt (+10)
  • (added) libc/test/include/generic-math-macros_test.cpp (+87)
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index f6af11abd4dd7..666b6337ddf37 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -277,3 +277,9 @@ add_macro_header(
   HDR
     stdckdint-macros.h
 )
+
+add_macro_header(
+  generic_math_macros
+  HDR
+    generic-math-macros.h
+)
diff --git a/libc/include/llvm-libc-macros/generic-math-macros.h b/libc/include/llvm-libc-macros/generic-math-macros.h
new file mode 100644
index 0000000000000..8fec2cc6c02ea
--- /dev/null
+++ b/libc/include/llvm-libc-macros/generic-math-macros.h
@@ -0,0 +1,20 @@
+//===-- Definition of macros from math.h ----------------------------------===//
+//
+// 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_MACROS_GENERIC_MATH_MACROS_H
+#define LLVM_LIBC_MACROS_GENERIC_MATH_MACROS_H
+
+#define isfinite(x) __builtin_isfinite(x)
+#define isinf(x) __builtin_isinf(x)
+#define isnan(x) __builtin_isnan(x)
+#define signbit(x) \
+    ((sizeof(x) == sizeof(float)) ? __builtin_signbitf(x) \
+    : (sizeof(x) == sizeof(double)) ? __builtin_signbit(x) \
+    : __builtin_signbitl(x))
+
+#endif // LLVM_LIBC_MACROS_GENERIC_MATH_MACROS_H
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 47838969d59ae..bcda32a615b62 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -51,9 +51,4 @@
 #define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
 #endif
 
-// TODO: Move generic functional math macros to a separate header file.
-#define isfinite(x) __builtin_isfinite(x)
-#define isinf(x) __builtin_isinf(x)
-#define isnan(x) __builtin_isnan(x)
-
 #endif // LLVM_LIBC_MACROS_MATH_MACROS_H
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 03c31855e352b..7a805fc3a2e66 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -79,3 +79,13 @@ add_libc_test(
   DEPENDS
     libc.include.llvm-libc-macros.stdckdint_macros
 )
+
+add_libc_test(
+  generic_math_macros_test
+  SUITE
+    libc_include_tests
+  SRCS
+    generic-math-macros_test.cpp
+  DEPENDS
+    libc.include.llvm-libc-macros.generic_math_macros
+)
diff --git a/libc/test/include/generic-math-macros_test.cpp b/libc/test/include/generic-math-macros_test.cpp
new file mode 100644
index 0000000000000..d7b37c7ba4e8b
--- /dev/null
+++ b/libc/test/include/generic-math-macros_test.cpp
@@ -0,0 +1,87 @@
+//===-- Unittests for stdbit ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "test/UnitTest/Test.h"
+
+/*
+ * The intent of this test is validate that the generic math macros operate as
+ * intended
+ */
+#include "include/llvm-libc-macros/generic-math-macros.h"
+
+// INF can be defined as a number with zeroed out mantissa and 1s in the 
+// exponent
+static uint32_t positive_infinity = 0x7F800000;
+static uint32_t negative_infinity = 0xFF800000;
+static const float pos_inf = *(float *) &positive_infinity;
+static const float neg_inf = *(float *) &negative_infinity;
+
+// NaN can be defined as a number with all 1s in the exponent
+static uint32_t positive_nan = 0x7F800001;
+static uint32_t negative_nan = 0xFF800001;
+static const float pos_nan = *(float *) &positive_nan;
+static const float neg_nan = *(float *) &negative_nan;
+
+#define PI 3.14159265358979323846
+#define CASE_DIV_BY_ZERO            PI / 0.0
+#define CASE_DIV_BY_POS_INF         PI / pos_inf
+#define CASE_DIV_BY_NEG_INF         PI / neg_inf
+#define CASE_MULT_ZERO_BY_POS_INF   0 * pos_inf
+#define CASE_MULT_ZERO_BY_NEG_INF   0 * neg_inf
+
+/*
+ * As with IEEE 754-1985, the biased-exponent field is filled with all 1 bits 
+ * to indicate either infinity (trailing significand field = 0) or a NaN 
+ * (trailing significand field ≠ 0)
+ */
+
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsfinite) {
+  EXPECT_EQ(isfinite(pos_inf), 0);
+  EXPECT_EQ(isfinite(neg_inf), 0);
+  EXPECT_EQ(isfinite(pos_nan), 0);
+  EXPECT_EQ(isfinite(neg_nan), 0);
+  EXPECT_EQ(isfinite(CASE_DIV_BY_ZERO), 0);
+  EXPECT_EQ(isfinite(PI), 1);
+}
+
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsinf) {
+  EXPECT_EQ(isinf(PI), 0);
+  EXPECT_EQ(isinf(CASE_DIV_BY_POS_INF), 0);
+  EXPECT_EQ(isinf(CASE_DIV_BY_NEG_INF), 0);
+  EXPECT_EQ(isinf(CASE_MULT_ZERO_BY_POS_INF), 0);
+  EXPECT_EQ(isinf(CASE_MULT_ZERO_BY_NEG_INF), 0);
+  EXPECT_EQ(isinf(pos_inf), 1);
+  EXPECT_EQ(isinf(neg_inf), 1);
+  EXPECT_EQ(isinf(CASE_DIV_BY_ZERO), 1);
+}
+
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathIsnan) {
+  EXPECT_EQ(isnan(PI), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_ZERO), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_POS_INF), 0);
+  EXPECT_EQ(isnan(CASE_DIV_BY_NEG_INF), 0);
+  EXPECT_EQ(isnan(pos_nan), 1);
+  EXPECT_EQ(isnan(neg_nan), 1);
+  EXPECT_EQ(isnan(CASE_MULT_ZERO_BY_POS_INF), 1);
+  EXPECT_EQ(isnan(CASE_MULT_ZERO_BY_NEG_INF), 1);
+  EXPECT_EQ(isnan(pos_inf / neg_inf), 1);
+}
+
+TEST(LlvmLibcGenericMath, TypeGenericMacroMathSignbit) {
+  EXPECT_EQ(signbit(static_cast<float>(PI)), 0);
+  EXPECT_EQ(signbit(static_cast<double>(PI)), 0);
+  EXPECT_EQ(signbit(static_cast<long double>(PI)), 0);
+  EXPECT_EQ(signbit(pos_inf), 0);
+  EXPECT_EQ(signbit(pos_nan), 0);
+
+  EXPECT_EQ(signbit(static_cast<float>(-PI)), 1);
+  EXPECT_EQ(signbit(static_cast<double>(-PI)), 1);
+  EXPECT_EQ(signbit(static_cast<long double>(-PI)), 1);
+  EXPECT_EQ(signbit(neg_inf), 1);
+  EXPECT_EQ(signbit(neg_nan), 1);
+}

@lntue lntue self-requested a review July 6, 2024 03:27
@akielaries
Copy link
Contributor Author

As mentioned in the original thread for #96322 here, I can add the macros + tests for these operations as well either in this PR or an additional one

@akielaries akielaries marked this pull request as draft July 8, 2024 02:19
… for macros signbit, isinf, isfinite, and isnan. curious on replicating this unit test abstraction piece for the C tests and for converting the PI define into a hex representation
@akielaries akielaries requested review from petrhosek and lntue July 13, 2024 04:41
@akielaries akielaries changed the title [libc][math] implement signbit [libc][math] implement signbit and math macro unit tests Jul 13, 2024
@akielaries akielaries requested a review from lntue July 13, 2024 18:26
@lntue lntue merged commit 3604c23 into llvm:main Jul 14, 2024
6 checks passed
Copy link

@akielaries Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 14, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-gcc-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/2049

Here is the relevant piece of the build log for the reference:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[       OK ] LlvmLibcHashTest.SanityCheck (1 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (264 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (332 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (215 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[834/2504] Linking CXX executable projects/libc/test/include/libc.test.include.signbitf_test.__unit__.__build__
[835/2504] Running unit test libc.test.include.signbitf_test.__unit__
FAILED: projects/libc/test/include/CMakeFiles/libc.test.include.signbitf_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include/CMakeFiles/libc.test.include.signbitf_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include/libc.test.include.signbitf_test.__unit__.__build__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcSignbitTest.SpecialNumbers
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/include/SignbitTest.h:26: FAILURE
      Expected: func(-1)
      Which is: -2147483648
To be equal to: 1
      Which is: 1
[  FAILED  ] LlvmLibcSignbitTest.SpecialNumbers
Ran 1 tests.  PASS: 0  FAIL: 1
[836/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isinfl_test.__unit__.__build__.dir/isinfl_test.cpp.o
[837/2504] Linking CXX executable projects/libc/test/src/fenv/libc.test.src.fenv.rounding_mode_test.__build__
[838/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnanf_test.__unit__.__build__.dir/isnanf_test.cpp.o
[839/2504] Linking CXX executable projects/libc/test/src/fenv/libc.test.src.fenv.feenableexcept_test.__build__
[840/2504] Linking CXX executable projects/libc/test/include/libc.test.include.isinff_test.__unit__.__build__
[841/2504] Running unit test libc.test.src.__support.threads.linux.raw_mutex_test.__unit__
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.SmokeTest
[       OK ] LlvmLibcSupportThreadsRawMutexTest.SmokeTest (4 us)
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.Timeout
[       OK ] LlvmLibcSupportThreadsRawMutexTest.Timeout (51 us)
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock
[       OK ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock (10 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[842/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinite_test.__unit__.__build__.dir/isfinite_test.cpp.o
[843/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinitef_test.__unit__.__build__.dir/isfinitef_test.cpp.o
[844/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isinf_test.__unit__.__build__.dir/isinf_test.cpp.o
[845/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.signbitl_test.__unit__.__build__.dir/signbitl_test.cpp.o
[846/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnanl_test.__unit__.__build__.dir/isnanl_test.cpp.o
[847/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.signbit_test.__unit__.__build__.dir/signbit_test.cpp.o
[848/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnan_test.__unit__.__build__.dir/isnan_test.cpp.o
[849/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinitel_test.__unit__.__build__.dir/isfinitel_test.cpp.o
[850/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_long_double_test.cpp.o
[851/2504] Building CXX object projects/libc/src/stdlib/CMakeFiles/libc.src.stdlib.strfromd.__internal__.dir/strfromd.cpp.o
[852/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_float_test.cpp.o
[853/2504] Building CXX object projects/libc/test/src/fenv/CMakeFiles/libc.test.src.fenv.getenv_and_setenv_test.__build__.dir/getenv_and_setenv_test.cpp.o
[854/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_double_test.cpp.o
[855/2504] Building CXX object projects/libc/src/stdlib/CMakeFiles/libc.src.stdlib.strfromf.__internal__.dir/strfromf.cpp.o
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[       OK ] LlvmLibcHashTest.SanityCheck (1 ms)
[ RUN      ] LlvmLibcHashTest.Avalanche
[       OK ] LlvmLibcHashTest.Avalanche (264 ms)
[ RUN      ] LlvmLibcHashTest.UniformLSB
[       OK ] LlvmLibcHashTest.UniformLSB (332 ms)
[ RUN      ] LlvmLibcHashTest.UniformMSB
[       OK ] LlvmLibcHashTest.UniformMSB (215 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[834/2504] Linking CXX executable projects/libc/test/include/libc.test.include.signbitf_test.__unit__.__build__
[835/2504] Running unit test libc.test.include.signbitf_test.__unit__
FAILED: projects/libc/test/include/CMakeFiles/libc.test.include.signbitf_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include/CMakeFiles/libc.test.include.signbitf_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/test/include/libc.test.include.signbitf_test.__unit__.__build__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcSignbitTest.SpecialNumbers
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/test/include/SignbitTest.h:26: FAILURE
      Expected: func(-1)
      Which is: -2147483648
To be equal to: 1
      Which is: 1
[  FAILED  ] LlvmLibcSignbitTest.SpecialNumbers
Ran 1 tests.  PASS: 0  FAIL: 1
[836/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isinfl_test.__unit__.__build__.dir/isinfl_test.cpp.o
[837/2504] Linking CXX executable projects/libc/test/src/fenv/libc.test.src.fenv.rounding_mode_test.__build__
[838/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnanf_test.__unit__.__build__.dir/isnanf_test.cpp.o
[839/2504] Linking CXX executable projects/libc/test/src/fenv/libc.test.src.fenv.feenableexcept_test.__build__
[840/2504] Linking CXX executable projects/libc/test/include/libc.test.include.isinff_test.__unit__.__build__
[841/2504] Running unit test libc.test.src.__support.threads.linux.raw_mutex_test.__unit__
[==========] Running 3 tests from 1 test suite.
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.SmokeTest
[       OK ] LlvmLibcSupportThreadsRawMutexTest.SmokeTest (4 us)
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.Timeout
[       OK ] LlvmLibcSupportThreadsRawMutexTest.Timeout (51 us)
[ RUN      ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock
[       OK ] LlvmLibcSupportThreadsRawMutexTest.PSharedLock (10 ms)
Ran 3 tests.  PASS: 3  FAIL: 0
[842/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinite_test.__unit__.__build__.dir/isfinite_test.cpp.o
[843/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinitef_test.__unit__.__build__.dir/isfinitef_test.cpp.o
[844/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isinf_test.__unit__.__build__.dir/isinf_test.cpp.o
[845/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.signbitl_test.__unit__.__build__.dir/signbitl_test.cpp.o
[846/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnanl_test.__unit__.__build__.dir/isnanl_test.cpp.o
[847/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.signbit_test.__unit__.__build__.dir/signbit_test.cpp.o
[848/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isnan_test.__unit__.__build__.dir/isnan_test.cpp.o
[849/2504] Building CXX object projects/libc/test/include/CMakeFiles/libc.test.include.isfinitel_test.__unit__.__build__.dir/isfinitel_test.cpp.o
[850/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_long_double_test.cpp.o
[851/2504] Building CXX object projects/libc/src/stdlib/CMakeFiles/libc.src.stdlib.strfromd.__internal__.dir/strfromd.cpp.o
[852/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_float_test.cpp.o
[853/2504] Building CXX object projects/libc/test/src/fenv/CMakeFiles/libc.test.src.fenv.getenv_and_setenv_test.__build__.dir/getenv_and_setenv_test.cpp.o
[854/2504] Building CXX object projects/libc/test/src/__support/CMakeFiles/libc.test.src.__support.str_to_float_test.__unit__.__build__.dir/str_to_double_test.cpp.o
[855/2504] Building CXX object projects/libc/src/stdlib/CMakeFiles/libc.src.stdlib.strfromf.__internal__.dir/strfromf.cpp.o

@petrhosek
Copy link
Member

petrhosek commented Jul 14, 2024

I don't think the isnan* tests should live in test/include, they should live in test/src/math to mirror implementation in src/math just like we did for all other math functions. The same also applies isinf* to isfinite*. Right now the tests don't match the implementation because isinfl, isinff, isfinitel and isfinitef don't exist at all.

I think this change should have really just added tests for signbit just like the commit message says and isinf* and isfinite* in should have been covered in separate changes correctly.

@petrhosek
Copy link
Member

FYI I have a PR #98274 for the isnan* tests in test/src/math.

@akielaries
Copy link
Contributor Author

Makes sense. Original issue #96322 had mentioned

It seems that we don't have tests for isfinite, isinf, or isnan macros from our math.h, which is problematic. We should start a new "include" test under libc/test/include (similar to stdbit_test.cpp).

So I figured closing out the issue in one PR was reasonable. I had also planned to remove the TODO that was in math-macros.h for moving isnan, isinf, isfinite to a new file (didn't see another issue(s) directly mentioning these individually) but looks like #96008 was addressing that

@lntue
Copy link
Contributor

lntue commented Jul 14, 2024

So I think there are 2 different things: the test/include/isnan*_test should test that the macro isnan works for floating point types (we might add float16 and float128 later if required), while test/src/math/isnan*_test should test for the entry points LIBC_NAMESPACE::isnan* functions. So both have there own merit.

//===-- Utility class to test the isnan macro [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 nanormation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this file has wrong copyright header.

aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This PR resolves llvm#96322 and implements the `signbit` macro under a new
header `generic-math-macros.h`. This also removed the `TODO` in
`math-macros.h` and moves `isfinite`, `isinf`, and `isnan` to the same
generic maths header. Finally, a test file
`generic-math-macros_test.cpp` that adds coverage to the above 4 macros.

Fixes llvm#96322.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][math] implement signbit
5 participants