diff --git a/docs/API.md b/docs/API.md index 663d439e7..adacf1251 100644 --- a/docs/API.md +++ b/docs/API.md @@ -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 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 45d5453c7..65580126c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -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 |