-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[libc][math][c++23] Implement comparison operations operator overloads for BFloat16 #150087
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
Conversation
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
Signed-off-by: Krishna Pandey <[email protected]>
@llvm/pr-subscribers-libc Author: Krishna Pandey (krishna2803) Changescc @overmighty @lntue Full diff: https://github.com/llvm/llvm-project/pull/150087.diff 2 Files Affected:
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index f157d90abb8aa..372eba374d8eb 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -274,6 +274,7 @@ add_header_library(
bfloat16.h
DEPENDS
.cast
+ .comparison_operations
.dyadic_float
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index bc0b8b23896fc..05edbba048cb7 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -12,6 +12,7 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/comparison_operations.h"
#include "src/__support/FPUtil/dyadic_float.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h"
@@ -57,6 +58,30 @@ struct BFloat16 {
uint32_t x_bits = static_cast<uint32_t>(bits) << 16U;
return cpp::bit_cast<float>(x_bits);
}
+
+ LIBC_INLINE constexpr bool operator==(BFloat16 other) const {
+ return fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator!=(BFloat16 other) const {
+ return !fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<(BFloat16 other) const {
+ return fputil::less_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<=(BFloat16 other) const {
+ return fputil::less_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>(BFloat16 other) const {
+ return fputil::greater_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>=(BFloat16 other) const {
+ return fputil::greater_than_or_equals(*this, other);
+ }
}; // struct BFloat16
} // namespace fputil
|
@@ -57,6 +58,30 @@ struct BFloat16 { | |||
uint32_t x_bits = static_cast<uint32_t>(bits) << 16U; | |||
return cpp::bit_cast<float>(x_bits); | |||
} | |||
|
|||
LIBC_INLINE constexpr bool operator==(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.
I was going to suggest const BFloat16 &other
but it doesn't impact codegen since BFloat16
is just a wrapper around uint16_t
.
Renamed the PR from "[libc][c++23][math]" to "[libc][math][c++23]" for consistency unless I missed something. |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/104/builds/27494 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/39077 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/182/builds/12655 Here is the relevant piece of the build log for the reference
|
No description provided.