[llvm] [IR][AsmParser] Revamp how floating-point literals work in LLVM IR. (PR #121838)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 21:19:46 PST 2025


================
@@ -4469,31 +4471,36 @@ Simple Constants
     The identifier '``none``' is recognized as an empty token constant
     and must be of :ref:`token type <t_token>`.
 
-The one non-intuitive notation for constants is the hexadecimal form of
-floating-point constants. For example, the form
-'``double    0x432ff973cafa8000``' is equivalent to (but harder to read
-than) '``double 4.5e+15``'. The only time hexadecimal floating-point
-constants are required (and the only time that they are generated by the
-disassembler) is when a floating-point constant must be emitted but it
-cannot be represented as a decimal floating-point number in a reasonable
-number of digits. For example, NaN's, infinities, and other special
-values are represented in their IEEE hexadecimal format so that assembly
-and disassembly do not cause any bits to change in the constants.
-
-When using the hexadecimal form, constants of types bfloat, half, float, and
-double are represented using the 16-digit form shown above (which matches the
-IEEE754 representation for double); bfloat, half and float values must, however,
-be exactly representable as bfloat, IEEE 754 half, and IEEE 754 single
-precision respectively. Hexadecimal format is always used for long double, and
-there are three forms of long double. The 80-bit format used by x86 is
-represented as ``0xK`` followed by 20 hexadecimal digits. The 128-bit format
-used by PowerPC (two adjacent doubles) is represented by ``0xM`` followed by 32
-hexadecimal digits. The IEEE 128-bit format is represented by ``0xL`` followed
-by 32 hexadecimal digits. Long doubles will only work if they match the long
-double format on your target.  The IEEE 16-bit format (half precision) is
-represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
-format is represented by ``0xR`` followed by 4 hexadecimal digits. All
-hexadecimal formats are big-endian (sign bit at the left).
+Floating-point constants support the following kinds of strings:
+
+   +---------------+---------------------------------------------------+
+   | Syntax        | Description                                       |
+   +===============+===================================================+
+   | ``+4.5e-13``  | Common decimal literal. Signs are optional, as is |
+   |               | the exponent portion. The decimal point is        |
+   |               | required, as is one or more leading digits before |
+   |               | the decimal point.                                |
+   +---------------+---------------------------------------------------+
+   | ``-0x1.fp13`` | Common hexadecimal literal. Signs are optional.   |
----------------
arsenm wrote:

Should we switch the default syntax to hex float? Not as part of this PR, it would be more disruptive 

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


More information about the llvm-commits mailing list