[llvm] [llvm][NFC] `APFloat`: Add missing semantics to enum (PR #117291)

Matthias Springer via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 10:48:57 PST 2024


================
@@ -214,13 +223,41 @@ struct APFloatBase {
     // types, there are no infinity or NaN values. The format is detailed in
     // https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
     S_Float4E2M1FN,
-
+    // TODO: Documentation is missing.
     S_x87DoubleExtended,
-    S_MaxSemantics = S_x87DoubleExtended,
+    // These are legacy semantics for the fallback, inaccrurate implementation
+    // of IBM double-double, if the accurate semPPCDoubleDouble doesn't handle
+    // the operation. It's equivalent to having an IEEE number with consecutive
+    // 106 bits of mantissa and 11 bits of exponent.
+    //
+    // It's not equivalent to IBM double-double. For example, a legit IBM
+    // double-double, 1 + epsilon:
+    //
+    // 1 + epsilon = 1 + (1 >> 1076)
+    //
+    // is not representable by a consecutive 106 bits of mantissa.
+    //
+    // Currently, these semantics are used in the following way:
+    //
+    //   semPPCDoubleDouble -> (IEEEdouble, IEEEdouble) ->
+    //   (64-bit APInt, 64-bit APInt) -> (128-bit APInt) ->
+    //   semPPCDoubleDoubleLegacy -> IEEE operations
+    //
+    // We use bitcastToAPInt() to get the bit representation (in APInt) of the
+    // underlying IEEEdouble, then use the APInt constructor to construct the
+    // legacy IEEE float.
+    //
+    // TODO: Implement all operations in semPPCDoubleDouble, and delete these
+    // semantics.
+    S_PPCDoubleDoubleLegacy,
----------------
matthias-springer wrote:

It looks like `S_PPCDoubleDoubleLegacy` was meant to be removed, but nothing has happened in over 1.5 years. Probably even longer because the last change was just a refactoring.

I think `S_PPCDoubleDoubleLegacy` should be added here to make sure we have a consistent code base. (Unless somebody volunteers to finish the `PPCDoubleDoubleLegacy` removal.)

I am trying to decouple APFloat and the floating-point semantics and special cases like these make that difficult.


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


More information about the llvm-commits mailing list