forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc][math] implement
signbit
and math macro unit tests (llvm#97791)
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.
- Loading branch information
1 parent
8e66967
commit 65d7bc1
Showing
22 changed files
with
570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- Utility class to test the isfinite 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 information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> | ||
class IsFiniteTest : public LIBC_NAMESPACE::testing::Test { | ||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsFiniteFunc)(T); | ||
|
||
void testSpecialNumbers(IsFiniteFunc func) { | ||
EXPECT_EQ(func(inf), 0); | ||
EXPECT_EQ(func(neg_inf), 0); | ||
EXPECT_EQ(func(zero), 1); | ||
EXPECT_EQ(func(neg_zero), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISFINITE_TESTS(T, func) \ | ||
using LlvmLibcIsFiniteTest = IsFiniteTest<T>; \ | ||
TEST_F(LlvmLibcIsFiniteTest, SpecialNumbers) { \ | ||
auto isfinite_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isfinite_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- Utility class to test the isinf 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 information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class IsInfTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsInfFunc)(T); | ||
|
||
void testSpecialNumbers(IsInfFunc func) { | ||
EXPECT_EQ(func(zero), 0); | ||
EXPECT_EQ(func(neg_zero), 0); | ||
EXPECT_EQ(func(inf), 1); | ||
EXPECT_EQ(func(neg_inf), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISINF_TESTS(T, func) \ | ||
using LlvmLibcIsInfTest = IsInfTest<T>; \ | ||
TEST_F(LlvmLibcIsInfTest, SpecialNumbers) { \ | ||
auto isinf_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isinf_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===-- 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. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class IsNanTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*IsNanFunc)(T); | ||
|
||
void testSpecialNumbers(IsNanFunc func) { | ||
EXPECT_EQ(func(zero), 0); | ||
EXPECT_EQ(func(neg_zero), 0); | ||
EXPECT_EQ(func(aNaN), 1); | ||
EXPECT_EQ(func(sNaN), 1); | ||
} | ||
}; | ||
|
||
#define LIST_ISNAN_TESTS(T, func) \ | ||
using LlvmLibcIsNanTest = IsNanTest<T>; \ | ||
TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { \ | ||
auto isnan_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(isnan_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===-- Utility class to test the signbit 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 information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H | ||
#define LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H | ||
|
||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
template <typename T> class SignbitTest : public LIBC_NAMESPACE::testing::Test { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*SignbitFunc)(T); | ||
|
||
void testSpecialNumbers(SignbitFunc func) { | ||
EXPECT_EQ(func(1), 0); | ||
EXPECT_EQ(func(-1), 1); | ||
} | ||
}; | ||
|
||
#define LIST_SIGNBIT_TESTS(T, func) \ | ||
using LlvmLibcSignbitTest = SignbitTest<T>; \ | ||
TEST_F(LlvmLibcSignbitTest, SpecialNumbers) { \ | ||
auto signbit_func = [](T x) { return func(x); }; \ | ||
testSpecialNumbers(signbit_func); \ | ||
} | ||
|
||
#endif // LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Unittests for isfinite macro --------------------------------------===// | ||
// | ||
// 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 "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
#include <assert.h> | ||
|
||
// check if macro is defined | ||
#ifndef isfinite | ||
#error "isfinite macro is not defined" | ||
#else | ||
int main(void) { | ||
assert(isfinite(1.0f)); | ||
assert(isfinite(1.0)); | ||
assert(isfinite(1.0L)); | ||
return 0; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//===-- Unittest for isfinite[d] macro ------------------------------------===// | ||
// | ||
// 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 "IsFiniteTest.h" | ||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
LIST_ISFINITE_TESTS(double, isfinite) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//===-- Unittest for isfinite[f] macro ------------------------------------===// | ||
// | ||
// 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 "IsFiniteTest.h" | ||
#include "include/llvm-libc-macros/math-function-macros.h" | ||
|
||
LIST_ISFINITE_TESTS(float, isfinite) |
Oops, something went wrong.