You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: llvm/docs/LangRef.rst
+55-29Lines changed: 55 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21407,7 +21407,7 @@ This intrinsic is not supported on all targets. Some targets may not support
21407
21407
all rounding modes.
21408
21408
21409
21409
'``llvm.convert.to.arbitrary.fp``' Intrinsic
21410
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21410
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21411
21411
21412
21412
Syntax:
21413
21413
"""""""
@@ -21446,20 +21446,53 @@ Arguments:
21446
21446
accepted by :ref:`llvm.fptrunc.round <int_fptrunc_round>` (for example,
21447
21447
``"round.tonearest"`` or ``"round.towardzero"``).
21448
21448
21449
+
The rounding mode is only consulted when ``value`` is not exactly representable in the target format.
21450
+
If the value is exactly representable, all rounding modes produce the same result.
21451
+
21449
21452
``saturation``
21450
-
A compile-time constant boolean value (``i1``). When ``true``, values outside the
21451
-
representable range of the target format are clamped to the minimum or maximum normal value.
21452
-
When ``false``, no saturation is applied. This parameter must be an immediate constant.
21453
+
A compile-time constant boolean value (``i1``). This parameter controls how overflow is handled
21454
+
when values exceed the representable finite range of the target format:
21455
+
21456
+
- When ``true``: overflowing values are clamped to the minimum or maximum representable finite value
21457
+
(saturating to the largest negative finite value or largest positive finite value).
21458
+
- When ``false``: overflowing values are converted to infinity (preserving sign of the original value) if the
21459
+
target format supports infinity, or return a poison value if infinity is not supported
21460
+
by the target format.
21461
+
21462
+
This parameter must be an immediate constant.
21453
21463
21454
21464
Semantics:
21455
21465
""""""""""
21456
21466
21457
21467
The intrinsic converts the native LLVM floating-point value to the arbitrary FP
21458
21468
format specified by ``interpretation``, applying the requested rounding mode and
21459
-
saturation behavior. The result is returned as an integer (e.g., ``i8`` for FP8,
21460
-
``i6`` for FP6) containing the encoded arbitrary FP bits. When saturation is enabled,
21461
-
values that exceed the representable range are clamped to the minimum or maximum
21462
-
normal value of the target format.
21469
+
saturation behavior. The conversion is performed in two steps: first, the value is
21470
+
rounded according to the specified rounding mode to fit the target format's precision;
21471
+
then, if the rounded result exceeds the target format's representable range, saturation
21472
+
is applied according to the ``saturation`` parameter. The result is returned as an
21473
+
integer (e.g., ``i8`` for FP8, ``i6`` for FP6) containing the encoded arbitrary FP bits.
21474
+
21475
+
**Handling of special values:**
21476
+
21477
+
- **NaN**: If the input is NaN and the target format supports NaN, it is converted to a NaN
21478
+
representation in the target format. The exact NaN payload and quiet/signaling status are
21479
+
implementation-defined; implementations may preserve them when the target supports it.
21480
+
If the target format does not support NaN, the intrinsic returns a poison value.
21481
+
- **Infinity**: If the input is +/-Inf:
21482
+
21483
+
- When ``saturation`` is ``false`` and the target format supports infinity, +/-Inf is preserved.
21484
+
- When ``saturation`` is ``false`` and the target format does not support infinity (e.g., formats
21485
+
with "FN" suffix), the intrinsic returns a poison value.
21486
+
- When ``saturation`` is ``true``, +/-Inf is clamped to the maximum/minimum representable finite value.
21487
+
21488
+
- **Overflow**: When a finite value exceeds the representable range:
21489
+
21490
+
- When ``saturation`` is ``true``, the value is clamped to the maximum/minimum representable finite value.
21491
+
- When ``saturation`` is ``false`` and the target format supports infinity, the value becomes +/-Inf.
21492
+
- When ``saturation`` is ``false`` and the target format does not support infinity, the intrinsic
21493
+
returns a poison value.
21494
+
21495
+
For FP6/FP4 interpretations, producers are expected to use ``saturation`` = ``true``; using ``saturation`` = ``false`` and generating NaN/Inf/overflowing values is undefined (poison).
0 commit comments