From e8ce0d218647fed66f2d44f5ae78eabac1a96367 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 11 Nov 2026 06:55:11 -0800 Subject: [PATCH] Translator: OpenCL mode clamps an integer conversion with .sat In a compute pipeline of OpenCL mode both measured oracles clamp an integer converted to an integer with .sat to the destination's range (probe jobs m3-max-15651 on a Radeon Pro 5300M and m3-max-15652 on a UHD Graphics 630, macOS 26.7.1, OpenCL C of our own, one work-item per operand): int and uint to char, uchar, short, ushort, int and uint; long and ulong to int and uint; ulong to long, long to ulong, int to ulong; char to uint, uchar to int; and convert_uchar_sat_rte(int). The translator wrapped (convert_uchar_sat(300) was 44 where both answer 255). Outside OpenCL mode it still wraps, as the 5300M and the 630 answer there (docs/API.md). ConvertKind::Int carries the destination's signedness where `.sat` is honored (arith::honored); the conversion first clamps the held source to the destination's range (math::saturation_bounds: a bound the source's own range keeps is skipped), by the source's signedness, on native integers and on the wide pairs, then converts as before. Tests: every source of 8..64 bits (signed and unsigned) into every destination of 8..64 bits (signed and unsigned) around each width's bounds, native (convert_suffix.rs) and wide (wide.rs), on the interpreter against exact references; the measured int-to-int forms join tests::engine_convert_rounding's table (OpenCL mode answers both oracles' words, outside it the wrapped plain answer). --- crates/metal2vulkan/src/lower/arith/math.rs | 68 +++++- crates/metal2vulkan/src/lower/arith/mod.rs | 24 +- crates/metal2vulkan/src/lower/arith/tests.rs | 5 +- .../src/lower/arith/tests/convert_suffix.rs | 87 ++++++- .../src/lower/arith/tests/wide.rs | 66 +++++- crates/metal2vulkan/src/lower/arith/wide.rs | 23 +- .../src/tests/engine_convert_rounding.rs | 216 +++++++++++++++++- docs/API.md | 3 +- 8 files changed, 467 insertions(+), 25 deletions(-) diff --git a/crates/metal2vulkan/src/lower/arith/math.rs b/crates/metal2vulkan/src/lower/arith/math.rs index cedbd188f..d2cd4c642 100644 --- a/crates/metal2vulkan/src/lower/arith/math.rs +++ b/crates/metal2vulkan/src/lower/arith/math.rs @@ -2382,8 +2382,13 @@ pub enum ConvertKind { signed: bool, round: Option, }, - /// Integer (`signed` source) to integer. - Int { signed: bool }, + /// Integer (`signed` source) to integer, wrapping; where `saturate` names the destination's + /// signedness (`.sat`, honored in OpenCL mode), clamped to the destination's range first + /// ([`saturation_bounds`]). + Int { + signed: bool, + saturate: Option, + }, /// An 8-bit float (carried in an `i8`) to a float: exact. FromFp8(narrow::Fp8Layout), /// An 8-bit float (carried in an `i8`) to an integer: its value as an `f32` (exact, as @@ -2483,10 +2488,14 @@ pub fn convert( None => Ok(r), } } - ConvertKind::Int { signed } => { + ConvertKind::Int { signed, saturate } => { if from.is_bool() { return cast(fb, CastKind::ZExt, from, to, x); } + let x = match saturate { + Some(dst) => saturate_int(fb, signed, dst, from, to, x)?, + None => x, + }; let widening = to.bits() >= from.bits(); let c = match (widening, signed) { (true, true) => CastKind::SExt, @@ -2662,6 +2671,59 @@ pub fn step_f32( fb.convert(ConvOp::Bitcast, moved, t) } +/// The bounds `.sat` clamps an integer of `src_bits` bits (read as `src_signed`) to before it +/// converts to one of `dst_bits` bits (read as `dst_signed`): the destination's range, each bound +/// `None` where the source's own range already keeps it. +pub fn saturation_bounds( + src_signed: bool, + src_bits: u8, + dst_signed: bool, + dst_bits: u8, +) -> (Option, Option) { + let range = |signed: bool, bits: u8| -> (i128, i128) { + let bits = u32::from(bits); + if signed { + (-(1i128 << (bits - 1)), (1i128 << (bits - 1)) - 1) + } else { + (0, (1i128 << bits) - 1) + } + }; + let (slo, shi) = range(src_signed, src_bits); + let (dlo, dhi) = range(dst_signed, dst_bits); + ((dlo > slo).then_some(dlo), (dhi < shi).then_some(dhi)) +} + +/// Held integer `x` (form `from`, read as `signed`) clamped to the range of integer form `to` +/// read with signedness `dst` ([`saturation_bounds`]): `.sat`'s answer, which the conversion then +/// keeps. +fn saturate_int( + fb: &mut FunctionBuilder<'_>, + signed: bool, + dst: Sign, + from: Form, + to: Form, + x: Value, +) -> BResult { + use crate::lower::arith::ops::int_compare; + let (lo, hi) = saturation_bounds(signed, from.bits(), dst == Sign::Signed, to.bits()); + let (lt, gt) = if signed { + (IntPredicate::Slt, IntPredicate::Sgt) + } else { + (IntPredicate::Ult, IntPredicate::Ugt) + }; + // A bound as the source's held bits: its two's complement, zero-extended from the width. + let held = |v: i128| (v as u64) & ones(from.bits()); + let mut r = x; + for (bound, pred) in [(lo, lt), (hi, gt)] { + if let Some(b) = bound { + let c = splat(fb, from, held(b))?; + let past = int_compare(fb, pred, from, r, c)?; + r = fb.select(past, c, r)?; + } + } + Ok(r) +} + /// The packed-channel layout of a normalized `air.pack`/`air.unpack` format: each channel's /// width, low channel first, and whether channels are signed-normalized; `None` for the packed /// float formats (`rg11b10f`, `rgb9e5`, [`float_unpack_lanes`]). `rgb565` holds red in bits diff --git a/crates/metal2vulkan/src/lower/arith/mod.rs b/crates/metal2vulkan/src/lower/arith/mod.rs index 56045861c..1bef352f2 100644 --- a/crates/metal2vulkan/src/lower/arith/mod.rs +++ b/crates/metal2vulkan/src/lower/arith/mod.rs @@ -459,6 +459,12 @@ impl FamilyStrategy for ArithStrategy { }, .. } => "arith.convert.directed", + S::Convert { + kind: ConvertKind::Int { + saturate: Some(_), .. + }, + .. + } => "arith.convert.clamped", S::Convert { kind: ConvertKind::FromFp8(_), .. @@ -598,7 +604,7 @@ impl FamilyStrategy for ArithStrategy { } /// The words a conversion's honored suffix adds ([`honored`]): the rounding to an integral value; -/// the conversion back, its comparisons and the step of a directed one. +/// the conversion back, its comparisons and the step of a directed one; the two clamps of `.sat`. fn suffix_words(kind: ConvertKind, from: Form) -> u32 { let lanes = u32::from(from.lanes); match kind { @@ -606,6 +612,9 @@ fn suffix_words(kind: ConvertKind, from: Form) -> u32 { ConvertKind::ToFloat { directed: Some(_), .. } => 160 + 128 + 16 * lanes, + ConvertKind::Int { + saturate: Some(_), .. + } => 64 + 16 * lanes, _ => 0, } } @@ -2784,6 +2793,7 @@ fn select_convert( }, (_, s) => ConvertKind::Int { signed: s == NumKind::Signed, + saturate: None, }, }; let kind = honored(cx.inputs.open_cl_mode, c, kind, from, to); @@ -2815,8 +2825,8 @@ fn select_convert( /// `kind`, the conversion `c`'s types name, with the suffix `c` spells where the pipeline honors /// it: in a compute pipeline of OpenCL mode (`open_cl_mode`), as Metal's does there, an integer -/// to `float` by `.rtz`, `.rtp` or `.rtn`, and a `float` to an integer by `.rte`, `.rtp` or `.rtn` -/// (measured on a Radeon Pro 5300M and a UHD Graphics 630: +/// to `float` by `.rtz`, `.rtp` or `.rtn`, a `float` to an integer by `.rte`, `.rtp` or `.rtn`, and +/// an integer to an integer by `.sat` (measured on a Radeon Pro 5300M and a UHD Graphics 630: /// docs/API.md, "Conversions"). Elsewhere, and where a side is a `half` (Metal creates no pipeline /// for one in OpenCL mode), the conversion its types name. pub(super) fn honored( @@ -2840,6 +2850,14 @@ pub(super) fn honored( signed, round: c.rounding.filter(|r| *r != Rounding::Zero), }, + ConvertKind::Int { signed, .. } if c.saturate => ConvertKind::Int { + signed, + saturate: Some(if c.dst_kind == NumKind::Signed { + math::Sign::Signed + } else { + math::Sign::Unsigned + }), + }, kind => kind, } } diff --git a/crates/metal2vulkan/src/lower/arith/tests.rs b/crates/metal2vulkan/src/lower/arith/tests.rs index d358e3565..b18d03438 100644 --- a/crates/metal2vulkan/src/lower/arith/tests.rs +++ b/crates/metal2vulkan/src/lower/arith/tests.rs @@ -3959,7 +3959,10 @@ fn integer_and_float_converts_follow_their_source_kind() { &|fb, x| { math::convert( fb, - ConvertKind::Int { signed }, + ConvertKind::Int { + signed, + saturate: None, + }, ff, tf, x[0], diff --git a/crates/metal2vulkan/src/lower/arith/tests/convert_suffix.rs b/crates/metal2vulkan/src/lower/arith/tests/convert_suffix.rs index 6135a203d..58d7ae37c 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/convert_suffix.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/convert_suffix.rs @@ -1,7 +1,8 @@ //! `air.convert`'s rounding and `.sat` where a compute pipeline of OpenCL mode honors them //! ([`super::super::honored`]), on the CPU interpreter against exact references: an integer to -//! `f32` toward zero, up and down; and an `f32` to an integer to nearest even, up and down, with -//! and without saturation. The wide path's (no `shaderInt64`) are in `wide.rs`. +//! `f32` toward zero, up and down; an `f32` to an integer to nearest even, up and down, with and +//! without saturation; and an integer to an integer clamped to its destination's range. The wide +//! path's (no `shaderInt64`) are in `wide.rs`. use super::super::honored; use super::*; @@ -47,6 +48,17 @@ pub(super) fn integral_of(x: f64, mode: Rounding) -> f64 { } } +/// `.sat`'s answer: the value `v` (of a source read as its kind says) clamped to the range of a +/// `dst`-bit integer read as `dst_signed`, as held bits. +pub(super) fn clamped(v: i128, dst: u8, dst_signed: bool) -> u64 { + let (lo, hi) = if dst_signed { + (smin(dst), smax(dst)) + } else { + (0, umax(dst)) + }; + (v.clamp(lo, hi) as u64) & mask(dst) +} + /// The value of held integer bits `b` of `bits` bits read as `signed`. pub(super) fn value_of(b: u64, bits: u8, signed: bool) -> i128 { if signed { @@ -305,6 +317,58 @@ fn rounded_conversions_to_an_integer_answer_metal_s_words() { } } +/// Integers of 8 to 64 bits, read as signed or unsigned, clamp to every destination of 8 to 64 +/// bits, signed or unsigned, before converting. +#[test] +fn an_integer_saturates_to_every_destination() { + let mut rng = Rng(0x5A7); + for from_bits in [8u8, 16, 32, 64] { + let from = int(from_bits); + let mut vals: Vec = [8u32, 16, 32, 64] + .iter() + .flat_map(|b| { + let p = if *b == 64 { 0 } else { 1u64 << b }; + let h = 1u64 << (b - 1); + [p.wrapping_sub(1), p, p.wrapping_add(1), h - 1, h, h + 1] + }) + .flat_map(|v| [v, v.wrapping_neg()]) + .map(|v| v & mask(from_bits)) + .collect(); + vals.extend(int_values(from_bits, &mut rng, 8)); + vals.sort_unstable(); + vals.dedup(); + let cs = cases(&vals); + for to_bits in [8u8, 16, 32, 64] { + let to = int(to_bits); + for (signed, dst) in [ + (true, Sign::Signed), + (true, Sign::Unsigned), + (false, Sign::Signed), + (false, Sign::Unsigned), + ] { + check( + &format!("{from_bits} (signed={signed}) to {to_bits} {dst:?} sat"), + &[from], + to, + &|fb, x| { + let kind = ConvertKind::Int { + signed, + saturate: Some(dst), + }; + math::convert(fb, kind, from, to, x[0], NanTest::IsNan) + }, + &cs, + &|c| { + let v = value_of(arg(c, 0), from_bits, signed); + Some(vec![clamped(v, to_bits, dst == Sign::Signed)]) + }, + false, + ); + } + } + } +} + /// The conversion of `name` with types `from` and `to` as the arith family selects it in a /// pipeline of OpenCL mode or not. fn selected(name: &str, open_cl_mode: bool, from: Form, to: Form) -> ConvertKind { @@ -330,14 +394,15 @@ fn plain_kind(c: &Convert) -> ConvertKind { }, (_, s) => ConvertKind::Int { signed: s == NumKind::Signed, + saturate: None, }, } } -/// OpenCL mode honors a directed rounding to `f32` and a rounding of an `f32` to an integer other -/// than truncation; it leaves the device's rounding to nearest even, truncation, a `half` side and -/// a suffix between integers as the types name them, and outside OpenCL mode every suffix is the -/// conversion its types name. +/// OpenCL mode honors a directed rounding to `f32`, a rounding of an `f32` to an integer other +/// than truncation, and `.sat` between integers; it leaves the device's rounding to nearest even, +/// truncation, a `half` side and a rounding between integers as the types name them, and outside +/// OpenCL mode every suffix is the conversion its types name. #[test] fn only_a_pipeline_of_opencl_mode_honors_a_suffix() { let (i32f, f32f, h) = (int(32), float(32), float(16)); @@ -378,6 +443,15 @@ fn only_a_pipeline_of_opencl_mode_honors_a_suffix() { round: Some(Rounding::Down), }, ), + ( + "air.convert.u.i8.s.i32.rtz.sat", + i32f, + int(8), + ConvertKind::Int { + signed: true, + saturate: Some(Sign::Unsigned), + }, + ), ]; for (name, from, to, want) in honored_kinds { assert_eq!( @@ -402,7 +476,6 @@ fn only_a_pipeline_of_opencl_mode_honors_a_suffix() { ("air.convert.f.f16.f.f32.rtp", f32f, h), ("air.convert.s.i16.f.f16.rtp.sat", h, int(16)), ("air.convert.s.i16.s.i32.rtp", i32f, int(16)), - ("air.convert.u.i8.s.i32.rtz.sat", i32f, int(8)), ] { let Some(AirIntrinsic::Convert(c)) = AirIntrinsic::parse(name) else { panic!("{name}"); diff --git a/crates/metal2vulkan/src/lower/arith/tests/wide.rs b/crates/metal2vulkan/src/lower/arith/tests/wide.rs index 063ebda9f..fb6098b76 100644 --- a/crates/metal2vulkan/src/lower/arith/tests/wide.rs +++ b/crates/metal2vulkan/src/lower/arith/tests/wide.rs @@ -926,7 +926,18 @@ fn wide_bitcasts_and_integer_converts_move_bits() { &format!("convert {from:?} -> {to:?} signed={signed}"), &[from], to, - &|fb, v| w::convert(fb, ConvertKind::Int { signed }, from, to, v[0]), + &|fb, v| { + w::convert( + fb, + ConvertKind::Int { + signed, + saturate: None, + }, + from, + to, + v[0], + ) + }, &cases, &|c| { let x = arg(c, 0); @@ -1524,9 +1535,10 @@ fn a_fragment_shuffle_bounds_its_emission() { } } -/// The roundings a pipeline of OpenCL mode honors, with a wide side: a wide integer to `f32` -/// toward zero, up and down; and an `f32` to a wide integer to nearest even, up and down, -/// saturating (`convert_suffix.rs` holds the native forms'). +/// The suffixes a pipeline of OpenCL mode honors, with a wide side: a wide integer to `f32` +/// toward zero, up and down; an `f32` to a wide integer to nearest even, up and down, saturating; +/// and `.sat` between a wide integer and a 32-bit or another wide one (`convert_suffix.rs` holds +/// the native forms'). #[test] fn wide_conversions_honor_their_suffixes() { use super::convert_suffix::{ @@ -1577,4 +1589,50 @@ fn wide_conversions_honor_their_suffixes() { ); } } + for (from, to) in [ + (wide(64), int(32)), + (wide(64), int(8)), + (wide(64), wide(64)), + (int(32), wide(64)), + (wide(40), wide(64)), + ] { + let mut vals = rounding_ints(from.bits()); + vals.extend([ + 0x7F, + 0x80, + 0xFF, + 0x100, + 0x7FFF_FFFF, + 0x8000_0000, + 0xFFFF_FFFF, + ]); + let cases: Vec = vals + .iter() + .map(|v| vec![vec![*v & mask(from.bits())]]) + .collect(); + for (signed, dst) in [ + (true, Sign::Signed), + (true, Sign::Unsigned), + (false, Sign::Signed), + (false, Sign::Unsigned), + ] { + check_wide( + &format!("{from:?} signed={signed} to {to:?} {dst:?} sat"), + &[from], + to, + &|fb, v| { + let kind = ConvertKind::Int { + signed, + saturate: Some(dst), + }; + w::convert(fb, kind, from, to, v[0]) + }, + &cases, + &|c| { + let v = value_of(arg(c, 0), from.bits(), signed); + Some(vec![clamped(v, to.bits(), dst == Sign::Signed)]) + }, + ); + } + } } diff --git a/crates/metal2vulkan/src/lower/arith/wide.rs b/crates/metal2vulkan/src/lower/arith/wide.rs index 810f09d65..1c3c72a4f 100644 --- a/crates/metal2vulkan/src/lower/arith/wide.rs +++ b/crates/metal2vulkan/src/lower/arith/wide.rs @@ -888,9 +888,27 @@ pub fn convert( x: SValue, ) -> BResult { match kind { - ConvertKind::Int { signed } => { + ConvertKind::Int { signed, saturate } => { let signed = signed && !from.is_bool(); - let p = to_pair(fb, from, x, signed)?; + let mut p = to_pair(fb, from, x, signed)?; + // `.sat`: the pair (sign-extended to 64 bits where signed) clamped to the + // destination's range, each bound as its 64-bit two's complement. + if let Some(dst) = saturate { + let (lo, hi) = + math::saturation_bounds(signed, from.bits(), dst == Sign::Signed, to.bits()); + let (lt, gt) = if signed { + (IntPredicate::Slt, IntPredicate::Sgt) + } else { + (IntPredicate::Ult, IntPredicate::Ugt) + }; + for (bound, pred) in [(lo, lt), (hi, gt)] { + if let Some(b) = bound { + let c = pk(fb, from.lanes, b as u64)?; + let past = compare(fb, pred, p, c)?; + p = sel(fb, past, c, p)?; + } + } + } from_pair(fb, to, p) } ConvertKind::ToFloat { signed, directed } => { @@ -2150,6 +2168,7 @@ fn select_convert( }, (_, s) => ConvertKind::Int { signed: s == NumKind::Signed, + saturate: None, }, }; let kind = super::honored(cx.inputs.open_cl_mode, c, kind, from, to); diff --git a/crates/metal2vulkan/src/tests/engine_convert_rounding.rs b/crates/metal2vulkan/src/tests/engine_convert_rounding.rs index 2c0ef8718..5f455c250 100644 --- a/crates/metal2vulkan/src/tests/engine_convert_rounding.rs +++ b/crates/metal2vulkan/src/tests/engine_convert_rounding.rs @@ -175,9 +175,10 @@ type Measured = ( [(u64, u64, u64); 4], ); -/// Every rounding the two honor: an integer of 32 or 64 bits to `float` toward zero, up and down; -/// and a `float` to an integer of 8 to 64 bits to nearest even, up and down, saturating or not. -const MEASURED: [Measured; 39] = [ +/// Every form the two honor: an integer of 32 or 64 bits to `float` toward zero, up and down; a +/// `float` to an integer of 8 to 64 bits to nearest even, up and down, saturating or not; and +/// `.sat` between integers (and one rounding between integers, which neither honors). +const MEASURED: [Measured; 58] = [ ( "f.f32.s.i32.rtz", "float", @@ -607,6 +608,215 @@ const MEASURED: [Measured; 39] = [ (0xbf000000, 0x0, 0x0), ], ), + ( + "u.i8.s.i32.rtz.sat", + "i8", + "i32", + [ + (0xffffffff, 0x0, 0xff), + (0x1000000, 0xff, 0x0), + (0x1000001, 0xff, 0x1), + (0x1000002, 0xff, 0x2), + ], + ), + ( + "s.i8.s.i32.rtz.sat", + "i8", + "i32", + [ + (0x1000000, 0x7f, 0x0), + (0x1000001, 0x7f, 0x1), + (0x1000002, 0x7f, 0x2), + (0x1000003, 0x7f, 0x3), + ], + ), + ( + "u.i8.u.i32.rtz.sat", + "i8", + "i32", + [ + (0x1000000, 0xff, 0x0), + (0x1000001, 0xff, 0x1), + (0x1000002, 0xff, 0x2), + (0x1000003, 0xff, 0x3), + ], + ), + ( + "s.i8.u.i32.rtz.sat", + "i8", + "i32", + [ + (0xffffffff, 0x7f, 0xff), + (0x1000000, 0x7f, 0x0), + (0x1000001, 0x7f, 0x1), + (0x1000002, 0x7f, 0x2), + ], + ), + ( + "u.i16.s.i32.rtz.sat", + "i16", + "i32", + [ + (0xffffffff, 0x0, 0xffff), + (0x1000000, 0xffff, 0x0), + (0x1000001, 0xffff, 0x1), + (0x1000002, 0xffff, 0x2), + ], + ), + ( + "s.i16.s.i32.rtz.sat", + "i16", + "i32", + [ + (0x1000000, 0x7fff, 0x0), + (0x1000001, 0x7fff, 0x1), + (0x1000002, 0x7fff, 0x2), + (0x1000003, 0x7fff, 0x3), + ], + ), + ( + "u.i16.u.i32.rtz.sat", + "i16", + "i32", + [ + (0x1000000, 0xffff, 0x0), + (0x1000001, 0xffff, 0x1), + (0x1000002, 0xffff, 0x2), + (0x1000003, 0xffff, 0x3), + ], + ), + ( + "s.i16.u.i32.rtz.sat", + "i16", + "i32", + [ + (0xffffffff, 0x7fff, 0xffff), + (0x1000000, 0x7fff, 0x0), + (0x1000001, 0x7fff, 0x1), + (0x1000002, 0x7fff, 0x2), + ], + ), + ( + "u.i32.s.i32.rtz.sat", + "i32", + "i32", + [ + (0xffffffff, 0x0, 0xffffffff), + (0xfeffffff, 0x0, 0xfeffffff), + (0xfefffffd, 0x0, 0xfefffffd), + (0xfe000001, 0x0, 0xfe000001), + ], + ), + ( + "s.i32.u.i32.rtz.sat", + "i32", + "i32", + [ + (0xffffffff, 0x7fffffff, 0xffffffff), + (0xfeffffff, 0x7fffffff, 0xfeffffff), + (0xfefffffd, 0x7fffffff, 0xfefffffd), + (0xfe000001, 0x7fffffff, 0xfe000001), + ], + ), + ( + "u.i8.s.i32.rte.sat", + "i8", + "i32", + [ + (0xffffffff, 0x0, 0xff), + (0x1000000, 0xff, 0x0), + (0x1000001, 0xff, 0x1), + (0x1000002, 0xff, 0x2), + ], + ), + ( + "s.i16.s.i32.rtp", + "i16", + "i32", + [ + (0x0, 0x0, 0x0), + (0x1, 0x1, 0x1), + (0xffffffff, 0xffff, 0xffff), + (0x1000000, 0x0, 0x0), + ], + ), + ( + "u.i64.s.i32.rtz.sat", + "i64", + "i32", + [ + (0xffffffff, 0x0, 0xffffffffffffffff), + (0xfeffffff, 0x0, 0xfffffffffeffffff), + (0xfefffffd, 0x0, 0xfffffffffefffffd), + (0xfe000001, 0x0, 0xfffffffffe000001), + ], + ), + ( + "s.i32.s.i64.rtz.sat", + "i32", + "i64", + [ + (0x20000000000001, 0x7fffffff, 0x1), + (0x7fffffffffffffff, 0x7fffffff, 0xffffffff), + (0x8000000000000000, 0x80000000, 0x0), + (0x8000000000000001, 0x80000000, 0x1), + ], + ), + ( + "u.i32.s.i64.rtz.sat", + "i32", + "i64", + [ + (0xffffffffffffffff, 0x0, 0xffffffff), + (0x20000000000001, 0xffffffff, 0x1), + (0x8000000000000001, 0x0, 0x1), + (0x4000000000000001, 0xffffffff, 0x1), + ], + ), + ( + "s.i32.u.i64.rtz.sat", + "i32", + "i64", + [ + (0xffffffffffffffff, 0x7fffffff, 0xffffffff), + (0x20000000000001, 0x7fffffff, 0x1), + (0x7fffffffffffffff, 0x7fffffff, 0xffffffff), + (0x8000000000000000, 0x7fffffff, 0x0), + ], + ), + ( + "u.i32.u.i64.rtz.sat", + "i32", + "i64", + [ + (0x20000000000001, 0xffffffff, 0x1), + (0x8000000000000000, 0xffffffff, 0x0), + (0x8000000000000001, 0xffffffff, 0x1), + (0x4000000000000001, 0xffffffff, 0x1), + ], + ), + ( + "s.i64.u.i64.rtz.sat", + "i64", + "i64", + [ + (0xffffffffffffffff, 0x7fffffffffffffff, 0xffffffffffffffff), + (0x8000000000000000, 0x7fffffffffffffff, 0x8000000000000000), + (0x8000000000000001, 0x7fffffffffffffff, 0x8000000000000001), + (0xffffff8000000000, 0x7fffffffffffffff, 0xffffff8000000000), + ], + ), + ( + "u.i64.s.i64.rtz.sat", + "i64", + "i64", + [ + (0xffffffffffffffff, 0x0, 0xffffffffffffffff), + (0x8000000000000000, 0x0, 0x8000000000000000), + (0x8000000000000001, 0x0, 0x8000000000000001), + (0xffffff8000000000, 0x0, 0xffffff8000000000), + ], + ), ]; /// The bytes of an LLVM type's value. diff --git a/docs/API.md b/docs/API.md index 23c51ec77..832269b00 100644 --- a/docs/API.md +++ b/docs/API.md @@ -4996,12 +4996,11 @@ each item named states the rule in full. |---|---|---|---| | integer of 8 to 64 bits to `float`, `.rtz`, `.rtp`, `.rtn` | rounded as named | rounded as named | rounded as named | | `float` to an integer of 8 to 64 bits, `.rte`, `.rtp`, `.rtn` | rounded as named, then clamped where `.sat` | as the 5300M, but a `uint` of 2^31 or more is `0x7fffffff` and a `uchar` with `.sat` above 127 is 127 | rounded as named, then saturated (the 5300M's answer) | + | integer to integer, `.sat` | clamped to the destination's range | clamped to the destination's range | clamped to the destination's range | | a `half` side, any suffix | no pipeline | no pipeline | the conversion its types name | An integer to `float` by `.rte`, a `float` to an integer by `.rtz`, and an integer to an integer with a rounding and no `.sat` are the conversion their types name on both, as on the runtime. - Both clamp an integer to an integer with `.sat` to the destination's range, where the runtime - wraps. Neither creates a pipeline of OpenCL mode for a conversion with a `half` side (its library compiles), so no Metal answer exists for one, and the runtime makes the pipeline. The device has no directed conversion (Vulkan's integer-to-float conversion rounds in a direction of its own,