[PATCH] D138540: Fix APFloat::toString on Float8E5M2 values.
Benjamin Kramer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 00:52:19 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7476d59414d3: Fix APFloat::toString on Float8E5M2 values. (authored by reedwm, committed by bkramer).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138540/new/
https://reviews.llvm.org/D138540
Files:
llvm/lib/Support/APFloat.cpp
llvm/unittests/ADT/APFloatTest.cpp
Index: llvm/unittests/ADT/APFloatTest.cpp
===================================================================
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -5152,6 +5152,26 @@
}
}
+TEST(APFloatTest, F8ToString) {
+ for (APFloat::Semantics S :
+ {APFloat::S_Float8E5M2, APFloat::S_Float8E4M3FN}) {
+ SCOPED_TRACE("Semantics=" + std::to_string(S));
+ for (int i = 0; i < 256; i++) {
+ SCOPED_TRACE("i=" + std::to_string(i));
+ APFloat test(APFloat::Float8E5M2(), APInt(8, i));
+ llvm::SmallString<128> str;
+ test.toString(str);
+
+ if (test.isNaN()) {
+ EXPECT_EQ(str, "NaN");
+ } else {
+ APFloat test2(APFloat::Float8E5M2(), str);
+ EXPECT_TRUE(test.bitwiseIsEqual(test2));
+ }
+ }
+ }
+}
+
TEST(APFloatTest, IEEEdoubleToDouble) {
APFloat DPosZero(0.0);
APFloat DPosZeroToDouble(DPosZero.convertToDouble());
Index: llvm/lib/Support/APFloat.cpp
===================================================================
--- llvm/lib/Support/APFloat.cpp
+++ llvm/lib/Support/APFloat.cpp
@@ -4099,6 +4099,11 @@
// Fill the buffer.
unsigned precision = significand.getBitWidth();
+ if (precision < 4) {
+ // We need enough precision to store the value 10.
+ precision = 4;
+ significand = significand.zext(precision);
+ }
APInt ten(precision, 10);
APInt digit(precision, 0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138540.482385.patch
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221213/d485b04f/attachment.bin>
More information about the llvm-commits
mailing list