[libc-commits] [libc] 594b6f7 - [libc][math][c++23] Implement comparison operations operator overloads for BFloat16 (#150087)
via libc-commits
libc-commits at lists.llvm.org
Wed Jul 23 07:06:28 PDT 2025
Author: Krishna Pandey
Date: 2025-07-23T16:06:24+02:00
New Revision: 594b6f7b3f70b26bf9c7b34d54340797e3e07a1d
URL: https://github.com/llvm/llvm-project/commit/594b6f7b3f70b26bf9c7b34d54340797e3e07a1d
DIFF: https://github.com/llvm/llvm-project/commit/594b6f7b3f70b26bf9c7b34d54340797e3e07a1d.diff
LOG: [libc][math][c++23] Implement comparison operations operator overloads for BFloat16 (#150087)
Signed-off-by: Krishna Pandey <kpandey81930 at gmail.com>
Added:
Modified:
libc/src/__support/FPUtil/CMakeLists.txt
libc/src/__support/FPUtil/bfloat16.h
Removed:
################################################################################
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
More information about the libc-commits
mailing list