NativeMinMax: state fast::median3's two-NaN answer in the recorded bound

What: the recorded bound of PrecisionNote::NativeMinMax (artifact.rs,
docs/API.md's catalogue, lower::arith's docs) now names the answer it left
out. A fast::median3 whose first two operands are NaNs and whose third is a
number answers the number. Metal's fast form answers the second operand, a
NaN. New test lower::arith::tests::specials::
median3_of_two_nans_beside_a_number_answers_the_number.

Why: the 780M venue re-record of nan-model-min-max-of-nan-operands-under-fast-math
(27f7c2fd) differed from the M3 Max in 50 of 1024 words under NativeMinMax.
42 fall inside the stated ties (two NaNs, signed zeros, a denormal). The 8
outside are median3 of two NaN operands beside +0: the device answers 0x0
where Metal answers the second NaN ([486] 0x0/0xffeaaaaa, [494]
0x0/0x7fc00001, ...). The 0 comes from the lowering's composition
min(max(c, min(a, b)), max(a, b)) of NMin and NMax, introduced by 9afdb1e150
(rule 1: the device's min and max). NMin and NMax answer the number beside a
NaN, so any composition of them answers c here; answering b would take a select
that emulates Metal's NaN pick, which rule 1 forbids. The answer is no
translator fold: it is precise median3's own answer on Metal (the twin
55bca0fd answers 0 at the same eight lanes), and MSL leaves a NaN operand
under fast math undefined (section 8.1), so Metal's fast NaN is one reading of
an undefined answer. The bound said "the one Metal answers but at three ties",
which these lanes broke. It now states the fourth difference.

Verified: the new test runs both forms on the interpreter over the four
two-NaN rows of MEDIAN3 and the case's eight lanes. Each answers the number,
which is precise Metal's answer. The table's fast answers are the second
operand in exactly the ten rows whose first two operands are NaNs.
This commit is contained in:
Anees Iqbal committed 2026-11-11 05:45:58 -08:00
1 parent 1e1a17581d
commit 7a2221ccf7
5 files changed
+77 -15

No files matched your search

+6 -1
View File
@@ -4293,7 +4293,12 @@ bound.
`float` or `half` is the device's `GLSL.std.450` `NMin`, `NMax` or `NClamp`, on a device not
measured to answer Metal's operand; and `median3` on every device, `min(max(c, min(a, b)),
max(a, b))` of the device's `NMin` and `NMax`, whose pick of two NaNs and of an `f32` denormal is
the device's (Metal's `fast::median3` answers `b` for two NaN first operands).
the device's. The result is one of the operands, Metal's but at three ties (of two NaNs a NaN of
the device's bits, where Metal answers the second operand's; of `+0` and `-0` either zero; an
`f32` denormal beside a zero or a denormal compared by its value, where Metal compares it as a
zero and answers the second) and one undefined answer: `fast::median3` of two NaN first operands
and a number answers the number, as precise `median3` does on Metal, where Metal's fast form
answers the second NaN. MSL leaves a NaN operand under fast math undefined (section 8.1).
- `metal2vulkan-degrade-native-dot` (precision). `PrecisionNote::NativeDot`: Native device maths:
Metal's `dot` on `float` and `half` is the device's `OpDot` (a `half` one summed in `float` and
rounded once to `half`), not Metal's fused chain of its products, on every device but for a