Apple's OpenCL compiler spells every convert_* it emits as an air.convert with a
rounding after the types (.rte, .rtz, .rtp, .rtn) and, to an integer, .sat after it
(convert_float4_rte(uchar4) is air.convert.f.v4f32.u.v4i8.rte, convert_int_sat(float)
is air.convert.s.i32.f.f32.rtz.sat; the forms are read from the OpenCL runtime library
the macOS 27.2 Metal toolchain ships). Convert::parse took exactly four tokens, so each
such name was an unknown intrinsic and the pipeline was refused.
- metal2vulkan-air: Convert gains `rounding: Option<ConvertRounding>` and `saturate`;
a rounding is accepted between numbers only (no bool, no 8-bit float) and .sat only
after one, to an integer. Static folding leaves the saturating and the directed forms
alone.
- Lowering (lower/arith/rounding.rs):
- float to integer: RoundEven / Ceil / Floor first (rte / rtp / rtn; rtz is the
conversion's own truncation), then the saturating conversion every air.convert to an
integer takes; the NaN test reads the operand itself. Denormal notes as rint / ceil /
floor take them.
- integer to integer: plain; .sat clamps to the range both types share (SClamp/SMax/SMin
of the sign extension, masked, or UMin; pairs on the wide path).
- integer to float and float to narrower float, nearest even: the plain conversion. Where
it can round to f32/f64 the entry declares RoundingModeRTE for the width and the widths
the device's independence ties to it (narrow::rte_modes); a device that cannot declare
them records the new PrecisionNote::NativeConversionRounding.
- toward zero or an infinity: no Vulkan conversion rounds so per instruction, so the
result is computed exactly by integer arithmetic: the magnitude's dropped bits with an
increment where the lane rounds away (f32, f64 from 64-bit, the wide path through its
sticky 32-bit fold), f32 to half on the bits (normal, overflow, subnormal, inf, NaN),
double to float by stepping the device's faithful conversion, double to half through
the round-to-odd f32. A conversion that cannot round is the plain one.
- PrecisionNote::NativeConversionRounding (native-conversion-rounding): codec, runtime
Degradation, comparison table (unbounded), fast_paths ledger class, docs/API.md.
- SEMANTICS_VERSION 2021, ARTIFACT_FORMAT_VERSION 501 (the codec gains the note);
api_signatures and the air api_surface blessed.
- Fixture kernel_convert_rounding_modes (owned MSL, air-rename to 64 suffixed intrinsics).
Unverified at this commit: build and tests follow in potluck jobs.