[llvm] [RFC][SPIR-V] Add intrinsics to convert to/from ap.float (PR #164252)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 8 17:49:56 PST 2025
================
@@ -21406,6 +21406,144 @@ environment <floatenv>` *except* for the rounding mode.
This intrinsic is not supported on all targets. Some targets may not support
all rounding modes.
+'``llvm.convert.to.arbitrary.fp``' Intrinsic
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Syntax:
+"""""""
+
+::
+
+ declare <iNxM> @llvm.convert.to.arbitrary.fp.<iNxM>.<fNxM>(
+ <fNxM> <value>, metadata <interpretation>,
+ metadata <rounding mode>, i1 <saturation>)
+
+Overview:
+"""""""""
+
+The ``llvm.convert.to.arbitrary.fp`` intrinsic converts a native LLVM
+floating-point value to an arbitrary FP format, returning the result as an integer
+containing the arbitrary FP bits. This intrinsic is overloaded on both its return
+type and first argument.
+
+Arguments:
+""""""""""
+
+``value``
+ The native LLVM floating-point value to convert (e.g., ``half``, ``float``, ``double``).
+
+``interpretation``
+ A metadata string describing the target arbitrary FP format. Supported format names include:
+
+ - FP8 formats: ``"Float8E5M2"``, ``"Float8E5M2FNUZ"``, ``"Float8E4M3"``,
+ ``"Float8E4M3FN"``, ``"Float8E4M3FNUZ"``, ``"Float8E4M3B11FNUZ"``, ``"Float8E3M4"``,
+ ``"Float8E8M0FNU"``
+ - FP6 formats: ``"Float6E3M2FN"``, ``"Float6E2M3FN"``
+ - FP4 formats: ``"Float4E2M1FN"``
+
+``rounding mode``
+ A metadata string specifying the rounding mode. The permitted strings match those
+ accepted by :ref:`llvm.fptrunc.round <int_fptrunc_round>` (for example,
+ ``"round.tonearest"`` or ``"round.towardzero"``).
+
+``saturation``
+ A compile-time constant boolean value (``i1``). When ``true``, values outside the
+ representable range of the target format are clamped to the minimum or maximum normal value.
+ When ``false``, no saturation is applied. This parameter must be an immediate constant.
----------------
MrSidims wrote:
> Does this flag flip between saturating to +huge/-huge and +inf/-inf
Exactly, I've changed the description for intrinsics, hope it address this and other questions.
https://github.com/llvm/llvm-project/pull/164252
More information about the llvm-commits
mailing list