[llvm] [APFloat] Add APFloat support for E8M0 type (PR #107127)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 09:57:55 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff a8e1c6f99abc273677afed5eaaeee2c0296db59f cbfa6fd8b13507aa06c74e6e072de7c80d80b9c3 --extensions cpp,h -- llvm/include/llvm/ADT/APFloat.h llvm/lib/Support/APFloat.cpp llvm/unittests/ADT/APFloatTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 4c71f4eca5..6c516d6b26 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -146,7 +146,7 @@ static constexpr fltSemantics semFloat8E4M3B11FNUZ = {
 static constexpr fltSemantics semFloat8E3M4 = {3, -2, 5, 8};
 static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
 static constexpr fltSemantics semFloat8E8M0FN = {
-      127, -127, 1, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
+    127, -127, 1, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::AllOnes};
 
 static constexpr fltSemantics semFloat6E3M2FN = {
     4, -2, 3, 6, fltNonfiniteBehavior::FiniteOnly};
@@ -3585,15 +3585,16 @@ APInt IEEEFloat::convertPPCDoubleDoubleAPFloatToAPInt() const {
 template <const fltSemantics &S>
 APInt IEEEFloat::convertIEEEFloatToAPInt() const {
   assert(semantics == &S);
-  const int bias = (semantics == &semFloat8E8M0FN) ?
-    -S.minExponent : -(S.minExponent - 1);
+  const int bias =
+      (semantics == &semFloat8E8M0FN) ? -S.minExponent : -(S.minExponent - 1);
   constexpr unsigned int trailing_significand_bits = S.precision - 1;
   constexpr int integer_bit_part = trailing_significand_bits / integerPartWidth;
   constexpr integerPart integer_bit =
       integerPart{1} << (trailing_significand_bits % integerPartWidth);
   constexpr uint64_t significand_mask = integer_bit - 1;
-  constexpr unsigned int exponent_bits = trailing_significand_bits ?
-    (S.sizeInBits - 1 - trailing_significand_bits) : S.sizeInBits;
+  constexpr unsigned int exponent_bits =
+      trailing_significand_bits ? (S.sizeInBits - 1 - trailing_significand_bits)
+                                : S.sizeInBits;
   static_assert(exponent_bits < 64);
   constexpr uint64_t exponent_mask = (uint64_t{1} << exponent_bits) - 1;
 
diff --git a/llvm/unittests/ADT/APFloatTest.cpp b/llvm/unittests/ADT/APFloatTest.cpp
index 5cfe028ca2..6d03b37c91 100644
--- a/llvm/unittests/ADT/APFloatTest.cpp
+++ b/llvm/unittests/ADT/APFloatTest.cpp
@@ -832,7 +832,8 @@ TEST(APFloatTest, IsSmallestNormalized) {
 
     if (I != APFloat::S_Float8E8M0FN) {
       EXPECT_FALSE(APFloat::getSmallest(Semantics).isSmallestNormalized());
-      EXPECT_FALSE(APFloat::getSmallest(Semantics, true).isSmallestNormalized());
+      EXPECT_FALSE(
+          APFloat::getSmallest(Semantics, true).isSmallestNormalized());
     } else {
       // For E8M0 format, there are no denorms.
       // So, getSmallest is equal to isSmallestNormalized().
@@ -2188,7 +2189,6 @@ TEST(APFloatTest, getSmallestNormalized) {
   EXPECT_FALSE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
   EXPECT_TRUE(test.isSmallestNormalized());
-
 }
 
 TEST(APFloatTest, getZero) {
@@ -7250,16 +7250,16 @@ TEST(APFloatTest, getExactLog2) {
     }
 
     if (APFloat::hasExponentOnly(Semantics)) {
-      EXPECT_EQ(-127,
-                scalbn(One, MinExp - Precision - 1, APFloat::rmNearestTiesToEven)
-                    .getExactLog2());
+      EXPECT_EQ(-127, scalbn(One, MinExp - Precision - 1,
+                             APFloat::rmNearestTiesToEven)
+                          .getExactLog2());
       EXPECT_EQ(-127,
                 scalbn(One, MinExp - Precision, APFloat::rmNearestTiesToEven)
                     .getExactLog2());
     } else {
-      EXPECT_EQ(INT_MIN,
-                scalbn(One, MinExp - Precision - 1, APFloat::rmNearestTiesToEven)
-                    .getExactLog2());
+      EXPECT_EQ(INT_MIN, scalbn(One, MinExp - Precision - 1,
+                                APFloat::rmNearestTiesToEven)
+                             .getExactLog2());
       EXPECT_EQ(INT_MIN,
                 scalbn(One, MinExp - Precision, APFloat::rmNearestTiesToEven)
                     .getExactLog2());

``````````

</details>


https://github.com/llvm/llvm-project/pull/107127


More information about the llvm-commits mailing list