Half + - * on the device's 16-bit arithmetic take the AIR's own contraction

A half fadd, fsub or fmul on the device's 16-bit arithmetic (ArithStrategy::F16:
MoltenVK, measured, and the float-controls profiles) was always kept apart: a
sum or difference decorated NoContraction and a product as Fma(a, b, -0.0)
decorated NoContraction, whatever the AIR's flags allowed. That holds Metal's
exact half bits at the cost of every fusion the flags allow (AGENTS.md rule 1:
the device's native arithmetic). It now decides as float does (contraction()):
an operation whose flags carry both contract and reassoc is undecorated, its
product a plain OpFMul, and the device's compiler groups and fuses it; any
other keeps today's form.

Notes mirror float's: note_rewrites already records FastMathRewrites where a
neighbour can be rewritten. On MoltenVK, Metal's fast compile folds an
undecorated 16-bit operation's conversions away and answers the float result
unrounded (the MetalHalfArithmetic measurement), so there a fast operation
records FastMathRewrites, whose doc (and docs/API.md's catalogue entry and the
FAST-PATHS device-gap row) now says so, and requires no MetalHalfArithmetic,
which the kept form still requires.

On an owned proxy (hnq_half_layer_composite) on the Iris Xe, the step-1
prototype of this form cut the SIMD8 cycle estimate from 58584 to 33092.

Tests: f16_binary's rounded-result and one-instruction tests under both
contractions; half_arithmetic_on_the_device_takes_the_airs_contraction
compiles fast, contract-only and flagless half + - * on every profile that
computes them in 16 bits and checks the instruction, its decoration, the note,
the requirement and the interpreted answers.
This commit is contained in:
Anees Iqbal committed 2026-11-11 15:37:33 -08:00
1 parent 2f6c6195ff
commit e393b10cb7
9 files changed
+252 -53

No files matched your search

+7 -4
View File
@@ -3795,10 +3795,13 @@ bound.
any other is kept apart (`NoContraction`); Metal's compiler groups and fuses by its own choice.
On a device without `shaderFloat16`, a chain of such `half` additions, subtractions and products
is held at `float` precision between the roundings where its values leave it
(`HalfChainPolicy::AtExits`, the default; `HalfChainPolicy::EachOperation` rounds each).
Cost: a sum of mixed signs grouped otherwise, or a multiply-add fused on one side alone, differs
from Metal's by any amount relative to the result; a held `half` chain by the roundings it
skips, a value inside it past `half`'s range staying finite.
(`HalfChainPolicy::AtExits`, the default; `HalfChainPolicy::EachOperation` rounds each). On
MoltenVK a `half` addition, subtraction or product carrying both flags is the 16-bit instruction
left undecorated, whose conversions Metal's fast compile folds away: the `float` result,
unrounded. Cost: a sum of mixed signs grouped otherwise, or a multiply-add fused on one side
alone, differs from Metal's by any amount relative to the result; a held `half` chain, or a
MoltenVK `half` operation left to the compiler, by the roundings it skips, a value inside it past
`half`'s range staying finite.
- `metal2vulkan-degrade-tessellation-winding` (precision). `PrecisionNote::TessellationWinding`: A
tessellation pipeline's vertex order: Metal's clockwise output winding is declared
`VertexOrderCcw` and its counter-clockwise one `VertexOrderCw`, as MoltenVK maps them under