Arithmetic: a narrow integer's high bits are cleared by OpBitwiseAnd on every device again

e709d20810 cleared the bits above a narrow width in a 32-bit container with
OpBitFieldUExtract(x, 0, N) on every device, under an unchanged SEMANTICS_VERSION (2205; its
batch bumped once at the end, 64045848c4). The consumer's Windows host (Intel UHD 630, driver
101.2145) loses its device at a desktop's first pipelines from 2206 on; its keep at e709d20810
ran from a warm runtime cache written at 9ea53f7acd under the same 2205, so it ran the AND
modules and never the extract.

ops::mask is the AND by 2^N - 1 again, the form every device ran from 11-17 until this morning.
On the RTX 5080 Laptop under NVIDIA 615.71.09 rt's every_device_zero_extends_a_narrow_clamped_sum
passed with the AND in the rounds at e9d5240b77 (m3-max-58802), 8012fff5a1 (58892) and
96d335ef46 (59572); on the RTX 3090 under 620.70.06 the forced AND gave 0 of 256 wrong words over
sixteen shapes (70761aa00f, m3-max-41627). The AND's one known failure is 615.71.09 on Ampere
GA10x, which no card we run has; the runtime's README records it.

- lower/arith/ops.rs: mask is the AND alone; the extract branch goes.
- SEMANTICS_VERSION 2211 in this commit, a number no pin has used, so every cache holds the
  change cold.
- Tests: lower/arith/tests.rs a_narrow_mask_after_a_signed_clamp_is_an_and (masks, no extract);
  rt tests::narrow asserts four or more masks by a narrow width's bits and no extract.
- The runtime's README, known gaps of pipeline states: the AND's old NVIDIA failure, and why the
  extract is not used.
This commit is contained in:
Anees Iqbal committed 2026-11-20 14:29:28 -08:00
1 parent b621a8e17f
commit 8347a38f5f
5 files changed
+28 -30

No files matched your search

+7
View File
@@ -2463,6 +2463,13 @@ or does not check is rebuilt from the generations' names, with young counted ful
### Known gaps of pipeline states
- A narrow integer's high bits (an 8- or 16-bit value held in a 32-bit word) are cleared by
`OpBitwiseAnd` by the width's mask on every device. NVIDIA's driver 615.71.09 on Ampere GA10x
dropped that mask after a signed clamp to exactly the narrow range, so such a kernel answered the
clamp's sign-extended words there; 620.70.06 answers right, and no card the runtime is run on has
that driver on that architecture. The other form, `OpBitFieldUExtract(x, 0, N)`, loses the
device on Intel's Windows driver 101.2145 (UHD 630) at a desktop's first pipelines, so it is not
used. Test: `tests::narrow`'s `every_device_zero_extends_a_narrow_clamped_sum`.
- Some forms argument buffers take under `MTLArgumentBuffersTier1` or `MTLArgumentBuffersTier2`,
which `Device::argument_buffers_support` answers, are not lowered by the translator's identity
domains, which every state is translated under: a state over a function that holds one is
@@ -2,9 +2,10 @@
//! kind: a kernel the translator compiles adds and subtracts two values sign-extended from 16 and
//! from 8 bits, clamps each result signed to exactly its width's range, truncates it and
//! zero-extends it. On every device the module clears the bits above each width with
//! `OpBitFieldUExtract(x, 0, N)`, never `OpBitwiseAnd` by the width's mask, which a driver's
//! compiler dropped after the clamp (NVIDIA 615.71.09 on Ampere GA10x answered sign-extended words;
//! 620.70.06 does not), and every word is zero-extended.
//! `OpBitwiseAnd` by the width's mask, never `OpBitFieldUExtract(x, 0, N)`, which Intel's Windows
//! driver 101.2145 loses its device on (a driver's compiler dropped the mask after the clamp on
//! NVIDIA 615.71.09 on Ampere GA10x, which answered sign-extended words; 620.70.06 does not), and
//! every word is zero-extended.
//!
//! `llvm-as` assembles the kernel; without it the test skips visibly.
@@ -156,8 +157,8 @@ entry:
(extracts, ands)
}
/// The kernel, translated, clears its narrow results' high bits by extracts and answers every
/// word zero-extended on every device.
/// The kernel, translated, clears its narrow results' high bits by masks and answers every word
/// zero-extended on every device.
#[test]
fn every_device_zero_extends_a_narrow_clamped_sum() {
let bitcode = match llvm_assemble_text(KERNEL) {
@@ -179,8 +180,8 @@ entry:
.compile_compute_pipeline(&descriptor, &Budget::standard())
.unwrap_or_else(|error| panic!("{name}: {error}"));
let (extracts, ands) = masks(&pipeline.stage.spirv);
assert!(extracts >= 4, "{name}: {extracts} extracts");
assert_eq!(ands, 0, "{name}: masks by a narrow width's bits");
assert!(ands >= 4, "{name}: {ands} masks by a narrow width's bits");
assert_eq!(extracts, 0, "{name}: {extracts} extracts");
let state = device
.new_compute_pipeline_state(&descriptor, crate::tests::no_constexpr_samplers)
.unwrap_or_else(|error| panic!("{name}: {error}"));
+1 -1
View File
@@ -61,7 +61,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2208;
pub const SEMANTICS_VERSION: u32 = 2211;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
+6 -16
View File
@@ -127,26 +127,16 @@ pub fn fsplat(fb: &mut FunctionBuilder<'_>, f: Form, x: f64) -> BResult<Value> {
splat(fb, f, f.const_bits(x))
}
/// `x` with the bits above its AIR width cleared (a no-op for a full-width integer): in a 32-bit
/// container `OpBitFieldUExtract(x, 0, N)`, on every device, else `x & (2^N - 1)`, the same bits.
/// No driver can drop the extract as one did the mask after a signed clamp to exactly the narrow
/// range (NVIDIA 615.71.09 on Ampere GA10x answered the clamp's sign-extended words).
/// `x` with the bits above its AIR width cleared (a no-op for a full-width integer): `x & (2^N -
/// 1)`, on every device. `OpBitFieldUExtract(x, 0, N)` gives the same bits, but Intel's Windows
/// driver 101.2145 on the UHD 630 loses its device on a desktop's first pipelines in that form, so
/// the mask is the one form. NVIDIA 615.71.09 on Ampere GA10x dropped this mask after a signed
/// clamp to exactly the narrow range (it answered sign-extended words); 620.70.06 does not, and no
/// card we run has that driver on that architecture (the runtime's README, known gaps).
pub fn mask(fb: &mut FunctionBuilder<'_>, f: Form, x: Value) -> BResult<Value> {
if !f.legalized() {
return Ok(x);
}
if f.container() == 32 {
let u32_ = Form {
held: Held::Int {
bits: 32,
container: 32,
},
lanes: 1,
};
let zero = splat(fb, u32_, 0)?;
let width = splat(fb, u32_, u64::from(f.bits()))?;
return fb.bit_field_extract(false, x, zero, width);
}
let m = splat(fb, f, ones(f.bits()))?;
fb.binary(BinOp::BitwiseAnd, x, m)
}
+6 -6
View File
@@ -1946,13 +1946,13 @@ fn signed_narrow_saturation_clamps_without_signed_min_or_max() {
}
}
/// A narrow integer's mask in a 32-bit container is `OpBitFieldUExtract(x, 0, N)` and never
/// `OpBitwiseAnd`, and the source-arithmetic shape whose mask a driver dropped (NVIDIA 615.71.09
/// on Ampere GA10x) answers its definition at every edge: two values sign-extended from `N` bits,
/// A narrow integer's mask in a 32-bit container is `OpBitwiseAnd` by `2^N - 1` and never
/// `OpBitFieldUExtract`, and the source-arithmetic shape whose mask a driver dropped (NVIDIA
/// 615.71.09 on Ampere GA10x) answers its definition at every edge: two values sign-extended from `N` bits,
/// added or subtracted, clamped signed to exactly `N` bits' range (`SClamp`, and `SMin` then
/// `SMax`), truncated to `N` bits. At 8 and 16 bits, scalar and three lanes.
#[test]
fn a_narrow_mask_after_a_signed_clamp_is_an_extract() {
fn a_narrow_mask_after_a_signed_clamp_is_an_and() {
let mut rng = Rng(0x0D0D_0D0E);
for bits in [8u8, 16] {
let vals = int_values(bits, &mut rng, 3);
@@ -1996,8 +1996,8 @@ fn a_narrow_mask_after_a_signed_clamp_is_an_extract() {
)
})
.count();
assert!(extracts > 0, "{what}: no extract");
assert_eq!(ands, 0, "{what}: a mask");
assert!(ands > 0, "{what}: no mask");
assert_eq!(extracts, 0, "{what}: an extract");
let usize_lanes = usize::from(lanes);
let mut cases: Vec<Case> = Vec::new();
for (i, x) in vals.iter().enumerate() {