[libc-commits] [libc] Bfloat16 `*= (Multiply assign)` operator support (PR #182882)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 23 08:28:24 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Zorojuro (Sukumarsawant)
<details>
<summary>Changes</summary>
This PR intends to add *= operator support for Bfloat16 and tests for it .
---
Full diff: https://github.com/llvm/llvm-project/pull/182882.diff
2 Files Affected:
- (modified) libc/src/__support/FPUtil/bfloat16.h (+5)
- (modified) libc/test/src/__support/FPUtil/bfloat16_test.cpp (+15)
``````````diff
diff --git a/libc/src/__support/FPUtil/bfloat16.h b/libc/src/__support/FPUtil/bfloat16.h
index 13e151208567d..7d64b441bf9b2 100644
--- a/libc/src/__support/FPUtil/bfloat16.h
+++ b/libc/src/__support/FPUtil/bfloat16.h
@@ -113,6 +113,11 @@ struct BFloat16 {
LIBC_INLINE BFloat16 operator/(BFloat16 other) const {
return fputil::generic::div<bfloat16>(*this, other);
}
+
+ LIBC_INLINE BFloat16 &operator*=(const BFloat16 &other) {
+ *this = *this * other;
+ return *this;
+ }
}; // struct BFloat16
} // namespace fputil
diff --git a/libc/test/src/__support/FPUtil/bfloat16_test.cpp b/libc/test/src/__support/FPUtil/bfloat16_test.cpp
index a71d971a9ad3d..48b2dfd5c4f3b 100644
--- a/libc/test/src/__support/FPUtil/bfloat16_test.cpp
+++ b/libc/test/src/__support/FPUtil/bfloat16_test.cpp
@@ -67,3 +67,18 @@ TEST_F(LlvmLibcBfloat16ConversionTest, FromInteger) {
EXPECT_FP_EQ_ALL_ROUNDING(mpfr_bfloat, libc_bfloat);
}
}
+
+TEST_F(LlvmLibcBfloat16ConversionTest, MultiplyAssign) {
+ for (uint16_t i = POS_START; i <= POS_STOP; i++) {
+ for (uint16_t j = POS_START; j <= POS_STOP; j++) {
+ BFloat16 a{i}, b{j};
+ MPFRNumber mpfr_a{a}, mpfr_b{j};
+ MPFRNumber mpfr_c = mpfr_a;
+ mpfr_c.mul(mpfr_b);
+ BFloat16 mpfr_bfloat = mpfr_c.as<BFloat16>();
+ a *= b;
+ BFloat16 libc_bfloat = a;
+ EXPECT_FP_EQ_ALL_ROUNDING(mpfr_bfloat, libc_bfloat);
+ }
+ }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/182882
More information about the libc-commits
mailing list