[flang-commits] [flang] faffcc3 - [flang][runtime] Refine list-directed REAL(2) output

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jul 13 16:10:57 PDT 2022


Author: Peter Klausler
Date: 2022-07-13T16:10:46-07:00
New Revision: faffcc3a46cb667fb8e2e6d0e6c14ed74300d7b5

URL: https://github.com/llvm/llvm-project/commit/faffcc3a46cb667fb8e2e6d0e6c14ed74300d7b5
DIFF: https://github.com/llvm/llvm-project/commit/faffcc3a46cb667fb8e2e6d0e6c14ed74300d7b5.diff

LOG: [flang][runtime] Refine list-directed REAL(2) output

The rule used by list-directed REAL output editing to select
between Ew.d and Fw.d output editing breaks down for 16-bit
floating-point data, since the number of significant decimal
digits is so low that Ew,d output editing is nearly always selected.
Cap the test so that five-digit values will be output with Fw.d
editing.

Differential Revision: https://reviews.llvm.org/D129672

Added: 
    

Modified: 
    flang/runtime/edit-output.cpp

Removed: 
    


################################################################################
diff  --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 6ccaa00a1630..b49e22238304 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -531,7 +531,12 @@ bool RealOutputEditing<binaryPrecision>::EditListDirectedOutput(
     return EditEorDOutput(edit);
   }
   int expo{converted.decimalExponent};
-  if (expo < 0 || expo > BinaryFloatingPoint::decimalPrecision) {
+  // The decimal precision of 16-bit floating-point types is very low,
+  // so use a reasonable cap of 6 to allow more values to be emitted
+  // with Fw.d editing.
+  static constexpr int maxExpo{
+      std::max(6, BinaryFloatingPoint::decimalPrecision)};
+  if (expo < 0 || expo > maxExpo) {
     DataEdit copy{edit};
     copy.modes.scale = 1; // 1P
     return EditEorDOutput(copy);


        


More information about the flang-commits mailing list