-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc][math][c23] Add {totalorder,totalordermag}f16 C23 math functions #95014
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6b214b5
[libc][math][c23] Add totalorderf16 C23 math function
overmighty 5c725f5
[libc][math][c23] Add totalordermagf16 C23 math function
overmighty e295094
[libc][math][c23] Fix NaN negation in TotalOrderTest.h
overmighty 1ac6c81
[libc][math][c23] Refactor fputil::{totalorder,totalordermag}
overmighty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
//===-- Implementation of totalorderf16 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/totalorderf16.h" | ||
#include "src/__support/FPUtil/BasicOperations.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
LLVM_LIBC_FUNCTION(int, totalorderf16, (const float16 *x, const float16 *y)) { | ||
return static_cast<int>(fputil::totalorder(*x, *y)); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
This file contains hidden or 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,20 @@ | ||
//===-- Implementation of totalordermagf16 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/totalordermagf16.h" | ||
#include "src/__support/FPUtil/BasicOperations.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
LLVM_LIBC_FUNCTION(int, totalordermagf16, | ||
(const float16 *x, const float16 *y)) { | ||
return static_cast<int>(fputil::totalordermag(*x, *y)); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
This file contains hidden or 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,20 @@ | ||
//===-- Implementation header for totalorderf16 -----------------*- 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_TOTALORDERF16_H | ||
#define LLVM_LIBC_SRC_MATH_TOTALORDERF16_H | ||
|
||
#include "src/__support/macros/properties/types.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
int totalorderf16(const float16 *x, const float16 *y); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_MATH_TOTALORDERF16_H |
This file contains hidden or 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,20 @@ | ||
//===-- Implementation header for totalordermagf16 --------------*- 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_TOTALORDERMAGF16_H | ||
#define LLVM_LIBC_SRC_MATH_TOTALORDERMAGF16_H | ||
|
||
#include "src/__support/macros/properties/types.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
int totalordermagf16(const float16 *x, const float16 *y); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_MATH_TOTALORDERMAGF16_H |
This file contains hidden or 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 hidden or 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 hidden or 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,142 @@ | ||
//===-- Utility class to test flavors of totalordermag ----------*- 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 LIBC_TEST_SRC_MATH_SMOKE_TOTALORDERMAGTEST_H | ||
#define LIBC_TEST_SRC_MATH_SMOKE_TOTALORDERMAGTEST_H | ||
|
||
#include "test/UnitTest/FEnvSafeTest.h" | ||
#include "test/UnitTest/FPMatcher.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
template <typename T> | ||
class TotalOrderMagTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { | ||
|
||
DECLARE_SPECIAL_CONSTANTS(T) | ||
|
||
public: | ||
typedef int (*TotalOrderMagFunc)(const T *, const T *); | ||
|
||
bool funcWrapper(TotalOrderMagFunc func, T x, T y) { | ||
return func(&x, &y) != 0; | ||
} | ||
|
||
void testXLesserThanY(TotalOrderMagFunc func) { | ||
EXPECT_TRUE(funcWrapper(func, neg_inf, inf)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(123.38))); | ||
|
||
EXPECT_FALSE(funcWrapper(func, T(-0.1), T(0.0))); | ||
EXPECT_FALSE(funcWrapper(func, T(-123.38), T(0.0))); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(-0.1), T(0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(-123.38), T(123.38))); | ||
} | ||
|
||
void testXGreaterThanY(TotalOrderMagFunc func) { | ||
EXPECT_TRUE(funcWrapper(func, inf, neg_inf)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(-0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(-123.38))); | ||
|
||
EXPECT_FALSE(funcWrapper(func, T(0.1), T(0.0))); | ||
EXPECT_FALSE(funcWrapper(func, T(123.38), T(0.0))); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.1), T(-0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(123.38), T(-123.38))); | ||
} | ||
|
||
void testXEqualToY(TotalOrderMagFunc func) { | ||
EXPECT_TRUE(funcWrapper(func, inf, inf)); | ||
EXPECT_TRUE(funcWrapper(func, neg_inf, neg_inf)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(-0.0), T(0.0))); | ||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(-0.0))); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.0), T(0.0))); | ||
EXPECT_TRUE(funcWrapper(func, T(-0.0), T(-0.0))); | ||
EXPECT_TRUE(funcWrapper(func, T(0.1), T(0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(-0.1), T(-0.1))); | ||
EXPECT_TRUE(funcWrapper(func, T(123.38), T(123.38))); | ||
EXPECT_TRUE(funcWrapper(func, T(-123.38), T(-123.38))); | ||
} | ||
|
||
void testSingleNaN(TotalOrderMagFunc func) { | ||
EXPECT_FALSE(funcWrapper(func, neg_aNaN, T(0.0))); | ||
EXPECT_FALSE(funcWrapper(func, neg_aNaN, T(0.1))); | ||
EXPECT_FALSE(funcWrapper(func, neg_aNaN, T(123.38))); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.0), neg_aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, T(0.1), neg_aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, T(123.38), neg_aNaN)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, T(0.0), aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, T(0.1), aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, T(123.38), aNaN)); | ||
|
||
EXPECT_FALSE(funcWrapper(func, aNaN, T(0.0))); | ||
EXPECT_FALSE(funcWrapper(func, aNaN, T(0.1))); | ||
EXPECT_FALSE(funcWrapper(func, aNaN, T(123.38))); | ||
} | ||
|
||
void testNaNSigns(TotalOrderMagFunc func) { | ||
EXPECT_TRUE(funcWrapper(func, neg_aNaN, aNaN)); | ||
EXPECT_FALSE(funcWrapper(func, neg_aNaN, sNaN)); | ||
EXPECT_TRUE(funcWrapper(func, neg_sNaN, aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, neg_sNaN, sNaN)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, aNaN, neg_aNaN)); | ||
EXPECT_FALSE(funcWrapper(func, aNaN, neg_sNaN)); | ||
EXPECT_TRUE(funcWrapper(func, sNaN, neg_aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, sNaN, neg_sNaN)); | ||
} | ||
|
||
void testQuietVsSignalingNaN(TotalOrderMagFunc func) { | ||
EXPECT_FALSE(funcWrapper(func, neg_aNaN, neg_sNaN)); | ||
EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, sNaN, aNaN)); | ||
EXPECT_FALSE(funcWrapper(func, aNaN, sNaN)); | ||
} | ||
|
||
void testNaNPayloads(TotalOrderMagFunc func) { | ||
T qnan_123 = FPBits::quiet_nan(Sign::POS, 0x123).get_val(); | ||
T neg_qnan_123 = FPBits::quiet_nan(Sign::NEG, 0x123).get_val(); | ||
T snan_123 = FPBits::signaling_nan(Sign::POS, 0x123).get_val(); | ||
T neg_snan_123 = FPBits::signaling_nan(Sign::NEG, 0x123).get_val(); | ||
Comment on lines
+107
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really know if I'm supposed to keep these variable names in Also, why do the tests use |
||
|
||
EXPECT_TRUE(funcWrapper(func, aNaN, aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, sNaN, sNaN)); | ||
EXPECT_TRUE(funcWrapper(func, aNaN, qnan_123)); | ||
EXPECT_TRUE(funcWrapper(func, sNaN, snan_123)); | ||
EXPECT_FALSE(funcWrapper(func, qnan_123, aNaN)); | ||
EXPECT_FALSE(funcWrapper(func, snan_123, sNaN)); | ||
|
||
EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_aNaN)); | ||
EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_sNaN)); | ||
EXPECT_TRUE(funcWrapper(func, neg_aNaN, neg_qnan_123)); | ||
EXPECT_TRUE(funcWrapper(func, neg_sNaN, neg_snan_123)); | ||
EXPECT_FALSE(funcWrapper(func, neg_qnan_123, neg_aNaN)); | ||
EXPECT_FALSE(funcWrapper(func, neg_snan_123, neg_sNaN)); | ||
} | ||
}; | ||
|
||
#define LIST_TOTALORDERMAG_TESTS(T, func) \ | ||
using LlvmLibcTotalOrderMagTest = TotalOrderMagTestTemplate<T>; \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, XLesserThanY) { testXLesserThanY(&func); } \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, XGreaterThanY) { \ | ||
testXGreaterThanY(&func); \ | ||
} \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, XEqualToY) { testXEqualToY(&func); } \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, SingleNaN) { testSingleNaN(&func); } \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, NaNSigns) { testNaNSigns(&func); } \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, QuietVsSignalingNaN) { \ | ||
testQuietVsSignalingNaN(&func); \ | ||
} \ | ||
TEST_F(LlvmLibcTotalOrderMagTest, NaNPayloads) { testNaNPayloads(&func); } | ||
|
||
#endif // LIBC_TEST_SRC_MATH_SMOKE_TOTALORDERMAGTEST_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I omitted the word "different" in "test [different] flavors", unlike usual, so that
-*- C++ -*-
can fit.