Docs: a fast-math NaN constant beside a run value stores the NaN; the fold's wording

API.md, section 10, Function constants: an fadd, fsub, fmul or fdiv under
nnan whose operand is a function constant bound to a NaN is poison in the
AIR. The translation answers the NaN operand unchanged, as it does without
fast math, where that NaN is Metal's answer. On the M3 Max, Metal drops a
kernel's store of it.

Measured in job m3-max-12877 with case 2d9a7e3091e1f9d9..., which is the
fixture sfold_fast_poison in a scratch corpus:
- Metal on apple-m3-max-macos27.0.1 left every poison row's float and
  half store at the 0xCD fill, and wrote the run-value row.
- MoltenVK with the folds wrote the NaN operand unchanged in every poison
  row (ffc12345, 7f800321, fd21).
- MoltenVK with the base translator dropped the float rows, and wrote ff21
  and 0 in the half rows.
The case is not committed: the corpus compares exactly.

ARCHITECTURE.md: the canon row now says a NaN operand is as it is beside a
value the run computes, and quieted where every operand is a constant.

(cherry picked from commit cddef968a3a8a971341fafcc5469e141fb97b434)
This commit is contained in:
Anees Iqbal committed 2026-11-09 20:44:24 -08:00
1 parent 80f02b63b9
commit 25401533b9
2 files changed
+12 -1

No files matched your search

+11
View File
@@ -4791,6 +4791,17 @@ each item named states the rule in full.
function's `function_constants_dictionary`), and the runtime refuses such a state as Metal does
(`Invalid` with `Problem::UnspecializedFunction`). A linked function keeps its own rule (section
3, "Linked functions: names and constants").
- **A fast-math float operation of a NaN function constant and a value the run computes stores
that NaN.** An `fadd`, `fsub`, `fmul` or `fdiv` that carries `nnan` (Metal's default fast math)
and whose operand is a function constant bound to a NaN is `poison` in the AIR once the
constants are bound, so any value is a correct answer for it. The translation answers the NaN
operand, its bits unchanged, as it does for the same operation without fast math, where that NaN
is Metal's answer. Metal answers a NaN for a fragment function's output of it on an Apple M3 Max,
an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under macOS 27.0.1. On the M3 Max a
kernel's store of it writes nothing, `float` and `half` alike, and the memory keeps what it
held, while the same kernel's store of the run value is written (the fixture
`sfold_fast_poison`, case `2d9a7e3091e1f9d9`, job m3-max-12877; the case stays out of the
corpus, whose comparisons are exact). The runtime on MoltenVK writes the NaN there.
- **A linked function's constant without a value reads as zero too**, where the function was made
specialized (section 3, "Linked functions: names and constants"). Metal makes that pipeline,
and its read is undefined: a kernel storing `x * scale + 1` of such a function stored nothing on
+1 -1
View File
@@ -67,7 +67,7 @@ rest is `crates/metal2vulkan/src/`.
| Module | Role |
|---|---|
| `air` (`metal2vulkan-air`) | The container (metallib, bitcode wrapper, raw module), the bitstream and bitcode readers, the typed IR, the `air.*` and `llvm.*` intrinsic families, the metadata ABI (`AirAbi`), and canonicalization (`canon`: inlining (each `byval` argument's copy made at its call first), function constants, SCCP (reading the integer fields of a constant global whose value is known, folding the integer bit operations `llvm.ctpop`, `llvm.bitreverse` and `llvm.bswap` on constants, settling the float operations a constant operand decides whatever the others hold (a NaN operand, the first in order, quieted; a product by a zero under `nnan` and `nsz`, `+0`), and reading the immediates of an intrinsic call that its function's parameters gave it once inlining makes them its call site's constants), the unrolling of loops whose constant trip count decides a branch where that leaves the entry no larger, devirtualization, linking, pruning, pointee erasure, the speculation of the short branch arms Metal's backend runs in every lane, the split of a whole array's or struct's load or store in buffer or threadgroup memory into its members' accesses, and a kernel of a pipeline of OpenCL mode linked as Metal links it: the three hidden buffers appended, its buffer indices 3 on, and OpenCL C's work-item reads made reads of their built-ins or of the first buffer, `canon::opencl`). Canonicalization also writes the formats the binder and runtime read: the visible-function table's words and the rasterization-rate map's parameter data |
| `air` (`metal2vulkan-air`) | The container (metallib, bitcode wrapper, raw module), the bitstream and bitcode readers, the typed IR, the `air.*` and `llvm.*` intrinsic families, the metadata ABI (`AirAbi`), and canonicalization (`canon`: inlining (each `byval` argument's copy made at its call first), function constants, SCCP (reading the integer fields of a constant global whose value is known, folding the integer bit operations `llvm.ctpop`, `llvm.bitreverse` and `llvm.bswap` on constants, settling the float operations a constant operand decides whatever the others hold (a NaN operand, the first in order: as it is beside a value the run computes, quieted where every operand is a constant; a product by a zero under `nnan` and `nsz`, `+0`), and reading the immediates of an intrinsic call that its function's parameters gave it once inlining makes them its call site's constants), the unrolling of loops whose constant trip count decides a branch where that leaves the entry no larger, devirtualization, linking, pruning, pointee erasure, the speculation of the short branch arms Metal's backend runs in every lane, the split of a whole array's or struct's load or store in buffer or threadgroup memory into its members' accesses, and a kernel of a pipeline of OpenCL mode linked as Metal links it: the three hidden buffers appended, its buffer indices 3 on, and OpenCL C's work-item reads made reads of their built-ins or of the first buffer, `canon::opencl`). Canonicalization also writes the formats the binder and runtime read: the visible-function table's words and the rasterization-rate map's parameter data |
| `graph` | The shared RPO, dominator tree, loop forest and SCC |
| `budget` | `Budget`, `CancelToken`, and the per-attempt `Meter`: deadline, cancellation, work units, the byte ledger and every structural cap |
| `memory/` | Pointer provenance, the `MemoryPlan`, leaf access emitters, arenas, root and handle lookups, word composition, atomics |