-
Notifications
You must be signed in to change notification settings - Fork 14k
[libc][math][c++23] Add bfloat16 support in LLVM libc #144463
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
…_type Signed-off-by: krishna2803 <kpandey81930@gmail.com>
…n type Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
…d headers Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
…lization for MPFRNumber Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- libc/cmake/modules/compiler_features/check_bfloat16.cpp libc/src/__support/FPUtil/bfloat16.h libc/test/src/__support/FPUtil/bfloat16_test.cpp libc/src/__support/CPP/type_traits/is_floating_point.h libc/src/__support/FPUtil/FPBits.h libc/src/__support/FPUtil/cast.h libc/src/__support/FPUtil/dyadic_float.h libc/src/__support/macros/properties/types.h libc/utils/MPFRWrapper/MPCommon.cpp libc/utils/MPFRWrapper/MPCommon.h View the diff from clang-format here.diff --git a/libc/test/src/__support/FPUtil/bfloat16_test.cpp b/libc/test/src/__support/FPUtil/bfloat16_test.cpp
index 3bfabf3fd..14f06c305 100644
--- a/libc/test/src/__support/FPUtil/bfloat16_test.cpp
+++ b/libc/test/src/__support/FPUtil/bfloat16_test.cpp
@@ -24,7 +24,6 @@ static constexpr uint16_t POS_STOP = 0x7f80U;
static constexpr uint16_t NEG_START = 0x8000U;
static constexpr uint16_t NEG_STOP = 0xff80;
-
using MPFRNumber = LIBC_NAMESPACE::testing::mpfr::MPFRNumber;
// TODO: better naming?
@@ -32,7 +31,7 @@ TEST_F(LlvmLibcBfloat16ExhaustiveTest, PositiveRange) {
for (uint16_t bits = POS_START; bits <= POS_STOP; bits++) {
bfloat16 bf16_num{bits};
MPFRNumber mpfr_num{bf16_num};
-
+
// bfloat16 to float
float mpfr_float = mpfr_num.as<float>();
ASSERT_FP_EQ(mpfr_float, bf16_num.as_float());
@@ -49,7 +48,7 @@ TEST_F(LlvmLibcBfloat16ExhaustiveTest, NegativeRange) {
for (uint16_t bits = NEG_START; bits <= NEG_STOP; bits++) {
bfloat16 bf16_num{bits};
MPFRNumber mpfr_num{bf16_num};
-
+
// bfloat16 to float
float mpfr_float = mpfr_num.as<float>();
ASSERT_FP_EQ(mpfr_float, bf16_num.as_float());
|
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
@@ -15,6 +15,7 @@ set( | |||
"fixed_point" | |||
"cfloat16" | |||
"cfloat128" | |||
"bfloat16" |
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.
You can leave the cmake detection changes to other PR:
CheckCompilerFeatures.cmake
check_bfloat16.cpp
entrypoints.txt
} | ||
} | ||
|
||
constexpr bool operator==(const BFloat16 other) const { |
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.
we should implement floating point equality of the same type in FPBits
, and it should follow IEEE 754 rules for equality (aka not bit identical in some cases).
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.
Add unit tests to make sure the class and the MPFR utility work.
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
Signed-off-by: krishna2803 <kpandey81930@gmail.com>
This PR enables support for BFloat16 type in LLVM libc along with support for testing BFloat16 functions via MPFR.
cc @overmighty @lntue