From b1cae49e66caaa8bc085cbf817b138b507a0ff04 Mon Sep 17 00:00:00 2001 From: Krishna Pandey Date: Tue, 22 Jul 2025 23:58:49 +0530 Subject: [PATCH 1/3] feat: implement comparison operations operator overloads for bfloat16 Signed-off-by: Krishna Pandey --- libc/src/__support/FPUtil/bfloat16.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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(bits) << 16U; return cpp::bit_cast(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 From 998d575626905890b27642193677bcd60be3ac7b Mon Sep 17 00:00:00 2001 From: Krishna Pandey Date: Wed, 23 Jul 2025 00:10:16 +0530 Subject: [PATCH 2/3] chore: update CMake deps Signed-off-by: Krishna Pandey --- libc/src/__support/FPUtil/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt index f157d90abb8aa..963f2faa65831 100644 --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -275,6 +275,7 @@ add_header_library( DEPENDS .cast .dyadic_float + .comparison_operations libc.src.__support.CPP.bit libc.src.__support.CPP.type_traits libc.src.__support.macros.config From 32be3cffc0731ac5c507e078138c5bfe46ac8b1f Mon Sep 17 00:00:00 2001 From: Krishna Pandey Date: Wed, 23 Jul 2025 00:34:49 +0530 Subject: [PATCH 3/3] nit: lexicographic order Signed-off-by: Krishna Pandey --- libc/src/__support/FPUtil/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt index 963f2faa65831..372eba374d8eb 100644 --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -274,8 +274,8 @@ add_header_library( bfloat16.h DEPENDS .cast - .dyadic_float .comparison_operations + .dyadic_float libc.src.__support.CPP.bit libc.src.__support.CPP.type_traits libc.src.__support.macros.config