Files
metal2vulkan/docs
Anees Iqbal ed114bcf43 Answer Metal's maths special values and fast functions by the device's instructions
The fast transcendental functions and the special values take the device's instructions, with
the precision contract's and c3's near-equivalent checks held at the device's notes.

One work packet, landed as 3 commits on archive/development-linear-2026-10-29, in order:

* Answer Metal's maths special values and fast functions by the device's instructions (d49cbcd398)

The fast sin, cos, tan, sinh, cosh, tanh and atanh are the device's Sin, Cos,
Tan, Sinh, Cosh, Tanh and Atanh on every device: no flush past Metal's last
evaluated quadrant, no kept denormal, no MSL Table 8.2 formula. The half zero and
NaN-sign tables are gone: a half function is its float instruction rounded. pow,
powr, fast::powr, atan2 and fast::atan2 keep only the C99/MSL special values
GLSL.std.450 leaves undefined (a negative base, 0^y with y <= 0, atan2(0,0),
infinities, pow's odd-integer sign), by the device's comparisons: no bit-level
denormal-as-zero reading, no canonical NaN over a NaN operand (the device's sum
instead), no pow(x, 1) = x, no flush of a denormal atan2 result. The fast
functions take libm::Fun entries of their own, so MoltenVK records
DeviceTranscendentals where its instruction is not Metal's fast function;
elsewhere NativeTranscendentals and DeviceDenormals as before; the NaNs no longer
claimed record NativeNanEncoding or DeviceNanEncoding. half fmod's zero stays on
the exact remainder routine (capability; no note path there yet). Dead code goes:
Lib's Metal mode and denormal::flush. FAST-PATHS rows, the libm module doc, and
API.md's fneg/fabs paragraph (now the device's OpFNegate and FAbs) and
native-transcendentals entry say so; known-gaps.tsv gains the M3's
fast-float-tanh row. SEMANTICS_VERSION 1918.

Verified: arith unit tests 192/192, engine tests of the path 42/42 (metal
denormals, arith, metal math, float call notes), fast_paths/profile/
api_signatures 47/47, runtime degradation and catalogue 17/17; clippy plain and
m2v_gpu, rustdoc; restoring pow(x,1) = x and a fast::sin flush fails the new
tests; conformance replay of pass-bytes-half-tanh-regimes on the Apple M3 Max
matches the ledger (exit 0; MoltenVK's Tanh is MSL's precise tanh, 2623 of 4096
words differ from Metal's fast::tanh, DeviceTranscendentals declared).
golden_hashes.tsv moves 1224 cells (65 rows over 59 fixtures), re-blessed on
development. Not run: lavapipe and other venues, the validation crate.

* Hold the precision contract's fast tanh at the device's Tanh notes (685db3e29f)

d49cbcd398 made a fast float tanh the device's Tanh instead of the MSL formula
the crate computed with a division of its own, so on lavapipe it records
NativeTranscendentals, not DeviceArithmetic, and on MoltenVK, whose Tanh is
Metal's precise tanh rather than its fast one, DeviceTranscendentals instead of
nothing. api_surface's the_precision_contract_names_each_float_operations_notes
still held the formula's notes and failed in development's gate at
b7f6dec939; it and its doc now hold the device's.

Verified: the api_surface binary passes (with fast_paths, golden_hashes and the
conformance ledger tests, 41/41) at 11eaace858.

* Hold c3's near-equivalent checks at the device's tanh and NaN notes (43a9c268e4)

d49cbcd398 made a fast float tanh the device's Tanh instead of the MSL formula
the crate computed with a division of its own, and left the NaN of pow and of
fast sin and cos to the device, so three c3 tests held the old notes and failed
on development:

- the_products_own_approximations_are_its_near_equivalents: tanh (fast or
  precise, float or half, lavapipe or MoltenVK) is now no near-equivalent;
  fast atan2 keeps DeviceArithmetic. Fast tanh(44) stays Apple's unstated word
  even where the row records DeviceArithmetic for another operation.
- a_nan_encoding_the_product_answers_is_not_a_near_equivalent: on lavapipe F32
  exactly precise pow and fast sin and cos record DeviceNanEncoding; the test
  asserts that set over msl::Prim::ALL. A differing NaN of fast sin(inf) and of
  precise pow(-1, 0.5) is now the note's (near_equivalent, open); precise
  sin(inf), mul and div keep the old answer.
- an_unstated_word_the_product_approximates_keeps_its_reading_open: fast fmod
  keeps its open reading and refusal (now the named-lowering check); fast
  tanh(44) is the device's answer, unstated, and the sign-off stands with
  DeviceArithmetic recorded.

Doc comments say what is true now. No product code changes.

Verified: cargo nextest run -p metal2vulkan-validation --all-features -E
'test(/^c3::/)' 72/72 passed (3 failed before); clippy -p
metal2vulkan-validation --all-targets --all-features -D warnings clean. The
lavapipe/MoltenVK note sets were read from lowering_notes for every prim.
2026-10-29 15:43:50 +02:00
..