@@ -436,6 +436,49 @@ const_cast no no no no
436
436
437
437
See also :ref: `langext-__builtin_shufflevector `, :ref: `langext-__builtin_convertvector `.
438
438
439
+ Half-Precision Floating Point
440
+ =============================
441
+
442
+ Clang supports two half-precision (16-bit) floating point types: ``__fp16 `` and
443
+ ``_Float16 ``. ``__fp16 `` is defined in the ARM C Language Extensions (`ACLE
444
+ <http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053d/IHI0053D_acle_2_1.pdf> `_)
445
+ and ``_Float16 `` in ISO/IEC TS 18661-3:2015.
446
+
447
+ ``__fp16 `` is a storage and interchange format only. This means that values of
448
+ ``__fp16 `` promote to (at least) float when used in arithmetic operations.
449
+ There are two ``__fp16 `` formats. Clang supports the IEEE 754-2008 format and
450
+ not the ARM alternative format.
451
+
452
+ ISO/IEC TS 18661-3:2015 defines C support for additional floating point types.
453
+ ``_FloatN `` is defined as a binary floating type, where the N suffix denotes
454
+ the number of bits and is 16, 32, 64, or greater and equal to 128 and a
455
+ multiple of 32. Clang supports ``_Float16 ``. The difference from ``__fp16 `` is
456
+ that arithmetic on ``_Float16 `` is performed in half-precision, thus it is not
457
+ a storage-only format. ``_Float16 `` is available as a source language type in
458
+ both C and C++ mode.
459
+
460
+ It is recommended that portable code use the ``_Float16 `` type because
461
+ ``__fp16 `` is an ARM C-Language Extension (ACLE), whereas ``_Float16 `` is
462
+ defined by the C standards committee, so using ``_Float16 `` will not prevent
463
+ code from being ported to architectures other than Arm. Also, ``_Float16 ``
464
+ arithmetic and operations will directly map on half-precision instructions when
465
+ they are available (e.g. Armv8.2-A), avoiding conversions to/from
466
+ single-precision, and thus will result in more performant code. If
467
+ half-precision instructions are unavailable, values will be promoted to
468
+ single-precision, similar to the semantics of ``__fp16 `` except that the
469
+ results will be stored in single-precision.
470
+
471
+ In an arithmetic operation where one operand is of ``__fp16 `` type and the
472
+ other is of ``_Float16 `` type, the ``_Float16 `` type is first converted to
473
+ ``__fp16 `` type and then the operation is completed as if both operands were of
474
+ ``__fp16 `` type.
475
+
476
+ To define a ``_Float16 `` literal, suffix ``f16 `` can be appended to the compile-time
477
+ constant declaration. There is no default argument promotion for ``_Float16 ``; this
478
+ applies to the standard floating types only. As a consequence, for example, an
479
+ explicit cast is required for printing a ``_Float16 `` value (there is no string
480
+ format specifier for ``_Float16 ``).
481
+
439
482
Messages on ``deprecated `` and ``unavailable `` Attributes
440
483
=========================================================
441
484
0 commit comments