diff --git a/Cargo.lock b/Cargo.lock index c93dfd4d..f6bcc2cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,7 @@ name = "xenora-decoder" version = "0.1.0" dependencies = [ "xenora-isa", + "xenora-ref", ] [[package]] diff --git a/crates/decoder/Cargo.toml b/crates/decoder/Cargo.toml index 7ecdbba3..d4837e8b 100644 --- a/crates/decoder/Cargo.toml +++ b/crates/decoder/Cargo.toml @@ -9,5 +9,8 @@ publish = false [dependencies] xenora-isa = { path = "../isa" } +[dev-dependencies] +xenora-ref = { path = "../ref" } + [lints] workspace = true diff --git a/crates/decoder/tests/gfx1030.rs b/crates/decoder/tests/gfx1030.rs index c93d2526..af1a920c 100644 --- a/crates/decoder/tests/gfx1030.rs +++ b/crates/decoder/tests/gfx1030.rs @@ -3,9 +3,10 @@ use std::path::PathBuf; use std::process::{Command, Stdio}; use xenora_decoder::{ - Architecture, DecodeError, DecodeErrorKind, DecodedInstruction, Instruction, VectorSource, - decode, + Architecture, DecodeError, DecodeErrorKind, DecodedInstruction, Instruction, ScalarSource, + VectorSource, decode, }; +use xenora_ref::{Op, Source, VectorAlu}; const FIXTURE: &[u8] = include_bytes!("../../../fixtures/rdna2/add.bin"); const BITWISE_FIXTURE: &[u8] = include_bytes!("../../../fixtures/rdna2/bitwise-branch.bin"); @@ -80,6 +81,7 @@ fn every_non_boundary_prefix_reports_the_incomplete_instruction() { }, } ); + assert_eq!(xenora_ref::decode(prefix).unwrap_err().offset, offset); } offset += usize::from(len); } @@ -110,12 +112,14 @@ fn rejects_other_opcodes_and_noncanonical_operands() { let bytes: Vec<_> = words.iter().flat_map(|word| word.to_le_bytes()).collect(); let error = decode(Architecture::Gfx1030, &bytes).unwrap_err(); assert_eq!(error.offset, 0); + assert_eq!(xenora_ref::decode(&bytes).unwrap_err().offset, 0); assert!(matches!( error.kind, DecodeErrorKind::UnsupportedForm { mnemonic: actual, .. } if actual == *mnemonic )); } + assert_eq!(xenora_ref::decode(&[0xff; 4]).unwrap_err().offset, 0); assert_eq!( decode(Architecture::Gfx1030, &[0xff; 4]).unwrap_err().kind, DecodeErrorKind::UnsupportedOpcode { word: 0xffff_ffff } @@ -174,26 +178,168 @@ fn scalar_sources_keep_literal_width_and_register_class() { ); } -#[test] -#[ignore = "requires LLVM with the gfx1030 AMDGPU target"] -fn compares_fixture_instructions_against_llvm() { - // Also covered by the independent reference decoder's high-register test. - let high_registers: &[u8] = &[ - 0xfe, 0x03, 0xfe, 0x7f, 0xff, 0, 0x25, 0xd5, 0x80, 0xff, 0x03, 0x02, 0, 0, 0x81, 0xbf, - ]; - for fixture in [FIXTURE, BITWISE_FIXTURE, FLOAT_FIXTURE, high_registers] { - compare_against_llvm(fixture); +fn reference_source(vector: VectorSource) -> Source { + match vector { + VectorSource::Register(reg) => Source::Register(reg), + VectorSource::Immediate(bits) => Source::Immediate(bits), } } -fn compare_against_llvm(fixture: &[u8]) { +fn reference_scalar(scalar: ScalarSource) -> Source { + match scalar { + ScalarSource::Register(reg) => Source::Register(reg), + ScalarSource::Immediate(bits) => Source::Immediate(bits), + } +} + +fn reference_op(instruction: Instruction) -> Op { + match instruction { + Instruction::BufferLoadDword { + data, + index, + resource, + } => Op::Load { + data, + index, + resource, + }, + Instruction::BufferStoreDword { + data, + index, + resource, + } => Op::Store { + data, + index, + resource, + }, + Instruction::WaitLoad => Op::WaitRead, + Instruction::WaitStore => Op::WaitWrite, + Instruction::MoveB32 { dst, src } => Op::Move(dst, reference_source(src)), + Instruction::AddNoCarryU32 { dst, src0, src1 } => Op::Add(dst, src0, src1), + Instruction::ScalarMoveB32 { dst, src } => Op::ScalarMove(dst, reference_scalar(src)), + Instruction::ScalarCompareEqU32 { src0, src1 } => { + Op::CompareEqual(reference_scalar(src0), reference_scalar(src1)) + } + Instruction::BranchSccZero { target } => Op::Branch { + target, + if_scc_zero: true, + }, + Instruction::Branch { target } => Op::Branch { + target, + if_scc_zero: false, + }, + Instruction::VectorAndB32 { dst, src0, src1 } => { + Op::Vector(VectorAlu::And, dst, src0, src1) + } + Instruction::VectorXorB32 { dst, src0, src1 } => { + Op::Vector(VectorAlu::Xor, dst, src0, src1) + } + Instruction::VectorAddF32 { dst, src0, src1 } => { + Op::Vector(VectorAlu::FloatAdd, dst, src0, src1) + } + Instruction::VectorMulF32 { dst, src0, src1 } => { + Op::Vector(VectorAlu::FloatMultiply, dst, src0, src1) + } + Instruction::EndProgram => Op::End, + } +} + +#[test] +#[ignore = "requires LLVM with the gfx1030 AMDGPU target"] +fn compares_fixture_instructions_against_llvm() { + let high_registers: &[u8] = &[ + 0xfe, 0x03, 0xfe, 0x7f, 0xff, 0, 0x25, 0xd5, 0x80, 0xff, 0x03, 0x02, 0, 0, 0x81, 0xbf, + ]; + let matrix = assemble_matrix(); + let mut forms = std::collections::BTreeSet::new(); + let mut count = 0; + for fixture in [ + FIXTURE, + BITWISE_FIXTURE, + FLOAT_FIXTURE, + high_registers, + &matrix, + ] { + count += compare_against_llvm(fixture, &mut forms); + } + assert_eq!(forms.len(), 15, "forms compared: {forms:?}"); + eprintln!( + "{count} three-way instruction comparisons across {} forms", + forms.len() + ); +} + +fn assemble_matrix() -> Vec { + // Cover register banks and extrema, immediate classes in both scalar + // compare positions, zero displacement and branches over literal words. + let mut assembly = String::from( + " + buffer_load_dword v255, v128, s[100:103], 0 idxen + buffer_store_dword v128, v255, s[96:99], 0 idxen + v_and_b32_e32 v255, v128, v254 + v_xor_b32_e32 v128, v255, v127 + v_add_f32_e32 v255, v254, v128 + v_mul_f32_e32 v128, v127, v255 + s_mov_b32 s105, s104 + s_mov_b32 s0, 0xdeadbeef + s_cmp_eq_u32 s105, s0 + s_cmp_eq_u32 s105, 0xdeadbeef + s_cmp_eq_u32 0xdeadbeef, s105 + s_cmp_eq_u32 -16, 64 + s_cmp_eq_u32 -16, s105 + s_cmp_eq_u32 s105, -16 + s_cmp_eq_u32 -16, 0xdeadbeef + s_cmp_eq_u32 0xdeadbeef, -16 + s_cbranch_scc0 0 + s_branch 2 + v_mov_b32_e32 v128, 0x12345678 + v_mov_b32_e32 v255, lit(0x1) + s_mov_b32 s105, lit(0x1) + s_cmp_eq_u32 s105, lit(0x1) + ", + ); + use std::fmt::Write as _; + for value in -16..=64 { + writeln!(assembly, "v_mov_b32_e32 v255, {value}").unwrap(); + writeln!(assembly, "s_mov_b32 s105, {value}").unwrap(); + writeln!(assembly, "s_cmp_eq_u32 {value}, {value}").unwrap(); + } + assembly.push_str("s_endpgm\n"); + let output = llvm_mc(&[], assembly.as_bytes()); + assert_llvm_success(&output); + let stdout = String::from_utf8(output.stdout).unwrap(); + let encodings: Vec<_> = stdout + .lines() + .filter_map(|line| line.split_once("; encoding: [")) + .map(|(_, encoding)| encoding_bytes(encoding)) + .collect(); + assert_eq!( + encodings.len(), + assembly + .lines() + .filter(|line| !line.trim().is_empty()) + .count(), + "LLVM must encode every matrix row" + ); + encodings.into_iter().flatten().collect() +} + +fn encoding_bytes(encoding: &str) -> Vec { + encoding + .trim_end_matches(']') + .split(',') + .map(|byte| u8::from_str_radix(byte.trim().trim_start_matches("0x"), 16).unwrap()) + .collect() +} + +fn llvm_mc(mode: &[&str], input: &[u8]) -> std::process::Output { let executable = std::env::var_os("LLVM_BIN").map_or_else( || PathBuf::from("llvm-mc"), |directory| PathBuf::from(directory).join("llvm-mc"), ); let mut child = Command::new(executable) + .args(mode) .args([ - "-disassemble", "-show-encoding", "-triple=amdgcn-amd-amdhsa", "-mcpu=gfx1030", @@ -204,20 +350,24 @@ fn compare_against_llvm(fixture: &[u8]) { .stderr(Stdio::piped()) .spawn() .expect("launch llvm-mc (provide its directory in LLVM_BIN or put it on PATH)"); - { - let mut input = child.stdin.take().unwrap(); - for byte in fixture { - write!(input, "0x{byte:02x} ").unwrap(); - } - writeln!(input).unwrap(); - } + child.stdin.take().unwrap().write_all(input).unwrap(); + child.wait_with_output().unwrap() +} - let output = child.wait_with_output().unwrap(); +fn assert_llvm_success(output: &std::process::Output) { assert!( output.status.success() && output.stderr.is_empty(), "llvm-mc failed or emitted diagnostics: {}", String::from_utf8_lossy(&output.stderr) ); +} + +fn compare_against_llvm( + fixture: &[u8], + forms: &mut std::collections::BTreeSet<&'static str>, +) -> usize { + let output = llvm_disassemble(fixture); + assert_llvm_success(&output); let stdout = String::from_utf8(output.stdout).unwrap(); let llvm: Vec<_> = stdout .lines() @@ -226,23 +376,89 @@ fn compare_against_llvm(fixture: &[u8]) { let xenora = decode(Architecture::Gfx1030, fixture).unwrap(); assert_eq!(llvm.len(), xenora.len()); + let reference = xenora_ref::decode(fixture).unwrap(); + let count = llvm.len(); + assert_eq!(count, reference.len()); let mut llvm_offset = 0; - for ((assembly, encoding), decoded) in llvm.into_iter().zip(xenora) { - let llvm_bytes: Vec<_> = encoding - .trim_end_matches(']') - .split(',') - .map(|byte| u8::from_str_radix(byte.trim().trim_start_matches("0x"), 16).unwrap()) - .collect(); + for (((assembly, encoding), decoded), reference) in llvm.into_iter().zip(xenora).zip(reference) + { + let llvm_bytes = encoding_bytes(encoding); let llvm_end = llvm_offset + llvm_bytes.len(); assert_eq!(decoded.offset, llvm_offset); + assert_eq!(reference.offset, llvm_offset); assert_eq!(usize::from(decoded.byte_len), llvm_bytes.len()); + assert_eq!(reference.byte_len, llvm_bytes.len()); assert_eq!(llvm_bytes, fixture[llvm_offset..llvm_end]); let assembly = normalize_llvm_assembly(assembly.trim(), llvm_end); - assert_eq!(decoded.instruction.to_string(), assembly); - eprintln!("{decoded} ({} bytes)", decoded.byte_len); + assert_eq!( + decoded.instruction.to_string(), + assembly, + "LLVM at {llvm_offset:#x}" + ); + assert_eq!( + reference.op, + reference_op(decoded.instruction), + "reference at {llvm_offset:#x}" + ); + forms.insert(decoded.instruction.mnemonic()); llvm_offset = llvm_end; } assert_eq!(llvm_offset, fixture.len()); + count +} + +fn llvm_disassemble(fixture: &[u8]) -> std::process::Output { + let input = fixture + .iter() + .map(|byte| format!("0x{byte:02x} ")) + .collect::(); + llvm_mc(&["-disassemble"], input.as_bytes()) +} + +#[test] +#[ignore = "requires LLVM with the gfx1030 AMDGPU target"] +fn distinguishes_llvm_invalid_encodings_from_xenora_subset_rejections() { + let malformed: &[&[u32]] = &[&[0xffff_ffff], &[0xe030_2000], &[0xd525_0001]]; + let outside_subset: &[&[u32]] = &[ + &[0x7e04_0200], // VOP1 SGPR source + &[0x3602_0680], // VOP2 inline source + &[0xbf8c_3f71], // Different wait counter + &[0xbf82_ffff], // Backward branch + &[0xbf82_0001, 0xbf81_0000], // Branch to EOF + &[0xbf84_0001, 0x7e04_02ff, 0x1234_5678, 0xbf81_0000], // Branch into literal + ]; + for (words, llvm_accepts) in malformed + .iter() + .map(|words| (words, false)) + .chain(outside_subset.iter().map(|words| (words, true))) + { + let bytes: Vec<_> = words.iter().flat_map(|word| word.to_le_bytes()).collect(); + assert_eq!(decode(Architecture::Gfx1030, &bytes).unwrap_err().offset, 0); + assert_eq!(xenora_ref::decode(&bytes).unwrap_err().offset, 0); + let output = llvm_disassemble(&bytes); + if llvm_accepts { + assert_llvm_success(&output); + assert!(!output.stdout.is_empty()); + } else { + assert!( + String::from_utf8_lossy(&output.stderr).contains("invalid instruction encoding") + ); + assert!(output.stdout.is_empty()); + } + } + eprintln!( + "{} malformed and {} out-of-subset LLVM probes", + malformed.len(), + outside_subset.len() + ); +} + +fn literal_bits(text: &str) -> Option { + let digits = text + .strip_prefix("lit(")? + .strip_suffix(')')? + .strip_prefix("0x")?; + u32::from_str_radix(digits, 16).ok() } fn normalize_llvm_assembly(assembly: &str, next_offset: usize) -> String { @@ -257,12 +473,28 @@ fn normalize_llvm_assembly(assembly: &str, next_offset: usize) -> String { "v_mov_b32_e32" => { let (destination, source) = operands.split_once(", ").unwrap(); let normalized = match source { - "0" => "0x0", - "1.0" => "0x3f800000", - _ => source, + "1.0" => "0x3f800000".to_owned(), + literal if literal_bits(literal).is_some() => { + format!("0x{:x}", literal_bits(literal).unwrap()) + } + _ => source.parse::().map_or_else( + |_| source.to_owned(), + |value| format!("0x{:x}", value as u32), + ), }; format!("{mnemonic} {destination}, {normalized}") } + "s_mov_b32" | "s_cmp_eq_u32" => { + let (left, right) = operands.split_once(", ").unwrap(); + let scalar = |operand: &str| match literal_bits(operand) { + Some(bits) => match bits as i32 { + inline @ -16..=64 => inline.to_string(), + _ => format!("0x{bits:x}"), + }, + None => operand.to_owned(), + }; + format!("{mnemonic} {}, {}", scalar(left), scalar(right)) + } _ => assembly.to_owned(), } } diff --git a/crates/ref/src/lib.rs b/crates/ref/src/lib.rs index 92e55bca..dd2e0e9b 100644 --- a/crates/ref/src/lib.rs +++ b/crates/ref/src/lib.rs @@ -21,16 +21,18 @@ impl fmt::Display for ReferenceError { impl std::error::Error for ReferenceError {} +/// Register index or immediate bits. The opcode determines the register bank. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum Source { +pub enum Source { Register(u8), Immediate(u32), } +/// Operations decoded independently by the reference interpreter. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum Op { - Load(u8), - Store(u8), +pub enum Op { + Load { data: u8, index: u8, resource: u8 }, + Store { data: u8, index: u8, resource: u8 }, WaitRead, WaitWrite, Move(u8, Source), @@ -42,8 +44,9 @@ enum Op { End, } +/// VOP2 operations decoded by the reference interpreter. #[derive(Clone, Copy, Debug, Eq, PartialEq)] -enum VectorAlu { +pub enum VectorAlu { And, Xor, FloatAdd, @@ -58,7 +61,43 @@ pub fn execute(code: &[u8], input: &[u32]) -> Result, ReferenceError> { if input.is_empty() || input.len() > MAX_INPUT_WORDS { return Err(error(0, "input word count outside reference limits")); } + if code.len() > MAX_CODE_BYTES { + return Err(error(0, "instruction stream exceeds reference limit")); + } let program = decode(code)?; + for instruction in &program { + match instruction.op { + Op::End if instruction.offset + instruction.byte_len != code.len() => { + return Err(error( + instruction.offset + instruction.byte_len, + "trailing code after s_endpgm", + )); + } + Op::Load { + index, resource, .. + } if (index, resource) != (0, 0) => { + return Err(error( + instruction.offset, + "load outside synthetic binding ABI", + )); + } + Op::Store { + index, resource, .. + } if (index, resource) != (0, 4) => { + return Err(error( + instruction.offset, + "store outside synthetic binding ABI", + )); + } + _ => {} + } + } + if !program + .last() + .is_some_and(|instruction| instruction.op == Op::End) + { + return Err(error(code.len(), "missing s_endpgm")); + } input .iter() .map(|&word| execute_lane(&program, word)) @@ -69,18 +108,55 @@ fn error(offset: usize, detail: &'static str) -> ReferenceError { ReferenceError { offset, detail } } -// AMD RDNA 2 ISA guide, Instruction Encoding: identify the fixture forms by -// bytes first, and independently extract the few variable fields they accept. -fn decode(code: &[u8]) -> Result, ReferenceError> { - if code.len() > MAX_CODE_BYTES { - return Err(error(0, "instruction stream exceeds reference limit")); - } +/// An operation and its span in the original byte stream. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct DecodedInstruction { + pub offset: usize, + pub byte_len: usize, + pub op: Op, +} + +/// Decode the supported gfx1030 subset without applying the execution ABI. +/// +/// AMD RDNA 2 ISA guide, Instruction Encoding. Identify the forms by bytes +/// and independently extract their variable fields. +/// +/// # Errors +/// +/// Returns the failing byte offset for an unsupported, truncated +/// or invalid instruction stream. +pub fn decode(code: &[u8]) -> Result, ReferenceError> { let mut program = Vec::new(); let mut offset = 0; while let Some(bytes) = code.get(offset..).filter(|bytes| !bytes.is_empty()) { let (op, length) = match bytes { - [0x00, 0x20, 0x30, 0xe0, 0, data, 0, 0x80, ..] => (Op::Load(*data), 8), - [0x00, 0x20, 0x70, 0xe0, 0, data, 1, 0x80, ..] => (Op::Store(*data), 8), + [ + 0, + 0x20, + opcode @ (0x30 | 0x70), + 0xe0, + index, + data, + group @ 0..=25, + 0x80, + .., + ] => { + let (data, index, resource) = (*data, *index, *group * 4); + let op = if *opcode == 0x30 { + Op::Load { + data, + index, + resource, + } + } else { + Op::Store { + data, + index, + resource, + } + }; + (op, 8) + } [0x70, 0x3f, 0x8c, 0xbf, ..] => (Op::WaitRead, 4), [0x00, 0x00, 0xfd, 0xbb, ..] => (Op::WaitWrite, 4), [0x00, 0x00, 0x81, 0xbf, ..] => (Op::End, 4), @@ -151,28 +227,26 @@ fn decode(code: &[u8]) -> Result, ReferenceError> { )); } }; - program.push((offset, op)); + program.push(DecodedInstruction { + offset, + byte_len: length, + op, + }); offset += length; - if op == Op::End { - if offset != code.len() { - return Err(error(offset, "trailing code after s_endpgm")); - } - for &(offset, op) in &program { - if let Op::Branch { target, .. } = op - && program - .binary_search_by_key(&target, |&(offset, _)| offset) - .is_err() - { - return Err(error( - offset, - "branch target is not an instruction boundary", - )); - } - } - return Ok(program); + } + for instruction in &program { + if let Op::Branch { target, .. } = instruction.op + && program + .binary_search_by_key(&target, |item| item.offset) + .is_err() + { + return Err(error( + instruction.offset, + "branch target is not an instruction boundary", + )); } } - Err(error(offset, "missing s_endpgm")) + Ok(program) } fn decode_scalar( @@ -233,7 +307,7 @@ fn vector_alu(op: VectorAlu, a: u32, b: u32, offset: usize) -> Result Result { +fn execute_lane(program: &[DecodedInstruction], input: u32) -> Result { let mut registers = [None; 256]; let mut scalars = [None; 106]; let mut scc = None; @@ -241,7 +315,7 @@ fn execute_lane(program: &[(usize, Op)], input: u32) -> Result Result { + Op::Load { data: dst, .. } => { if dst == 0 || pending_read.is_some() { return Err(error( offset, @@ -271,7 +345,7 @@ fn execute_lane(program: &[(usize, Op)], input: u32) -> Result { + Op::Store { data: src, .. } => { let value = read(src)?; if pending_write.is_some() || output.is_some() { return Err(error(offset, "multiple writes to the output")); @@ -427,9 +501,21 @@ mod tests { assert_eq!( decode(&code), Ok(vec![ - (0, Op::Move(255, Source::Register(254))), - (4, Op::Add(255, 128, 255)), - (12, Op::End), + DecodedInstruction { + offset: 0, + byte_len: 4, + op: Op::Move(255, Source::Register(254)) + }, + DecodedInstruction { + offset: 4, + byte_len: 8, + op: Op::Add(255, 128, 255) + }, + DecodedInstruction { + offset: 12, + byte_len: 4, + op: Op::End + }, ]) ); } diff --git a/docs/progress.md b/docs/progress.md index 6dc1bf0d..f5b2c68e 100644 --- a/docs/progress.md +++ b/docs/progress.md @@ -13,7 +13,7 @@ cargo fmt --all -- --check cargo clippy --locked --workspace --all-targets --all-features -- -D warnings cargo test --locked --workspace scripts/assemble-fixture.sh --check -LLVM_BIN="$(brew --prefix llvm)/bin" cargo test --locked -p xenora-decoder --test gfx1030 -- --ignored --nocapture +LLVM_BIN="$(brew --prefix llvm)/bin" cargo test --locked -p xenora-decoder --test gfx1030 -- --include-ignored --nocapture scripts/test-gpu.sh scripts/demo.sh scripts/audit/native.sh @@ -25,7 +25,7 @@ The independent CPU validation tests are part of the workspace. The native suite ## Remaining work -1. R2 owns the automated three-way decoder check and broader independent interpreter validation. Start from [the independent test report](../tests/validation/README.md). +1. The automated G6 check covers all 15 decoded forms. R2 still needs to sign off on the [three-way evidence](shaders/instruction-coverage.md#automated-three-way-comparison) at the final candidate and finish G5 interpreter assurance. 2. Run `scripts/fuzz.sh instruction_stream`, `scripts/fuzz.sh fixture` and `scripts/fuzz.sh reference` serially. Each defaults to 600 seconds. The interrupted corpus is retained under ignored `artifacts/fuzz/` and no campaign remains running. 3. R2 owns source, semantic and oracle mutation execution and survivor triage. Recreate the source population with `cargo mutants --workspace --list --json --file 'crates/decoder/src/**' --file 'crates/shader/src/**' --file 'crates/ref/src/**'` before executing it. The first inventory has 373 entries. Resolve any new tests and reassess the denominator before reporting a gate result. 4. Implement benchmark coverage across the correctness corpus and execute on AC power with the machine idle. The checkout has verified correctness results and no benchmark measurements. diff --git a/docs/shaders/instruction-coverage.md b/docs/shaders/instruction-coverage.md index bf53aa7e..0d867ed0 100644 --- a/docs/shaders/instruction-coverage.md +++ b/docs/shaders/instruction-coverage.md @@ -16,15 +16,42 @@ initialization and memory safety require verification after decoding. | `s_waitcnt_vscnt null, 0` | SOPK, exact null source and zero immediate | 4 B | yes | yes | pass | | `s_endpgm` | SOPP, zero immediate | 4 B | yes | yes | pass | -The production decoder matched all three fixture streams with LLVM 23.1.6. -The comparison checks instruction order, byte offsets, lengths, re-encoded -bytes, mnemonics and operands. It normalizes LLVM's spelling of zero in -`s_waitcnt_vscnt`. This comparison covers the production decoder and LLVM. -The independent decoder and execution stages require their own evidence. +## Automated three-way comparison + +LLVM 23.1.6, the production decoder and the independent reference decoder +matched 303 instructions across five streams. These include three fixtures, +a high-register sequence and a 266-instruction matrix assembled by LLVM. +The harness checks byte offsets, widths, encoded bytes from LLVM, mnemonic +and operands, and the typed reference operation against the production +operation. It covers all 15 forms in this document. + +The matrix checks the 81 inline integer selectors in VOP1, SOP1 and SOPC, +forced literals that could otherwise be inline, literal selection in either +SOPC operand, high SGPR and VGPR indices, MUBUF descriptor and index +operands, and zero and nonzero forward branch displacements. The decoder +trace exposes MUBUF operands independently of the synthetic execution ABI, +which still requires the original index and resource bindings. + +Three malformed LLVM probes produced diagnostics, and six valid encodings +or disassemblable branch sequences were deliberately rejected by both Xenora +decoders. Both Xenora decoders also reject all 37 interior truncation offsets +in the add fixture and all 18 existing unsupported-encoding cases. +These case counts overlap where the same bytes are used in distinct tests. +The truncated VOP1 literal is checked in Xenora only. LLVM 23.1.6's direct +literal-truncation probe crashed, so it is outside the automated LLVM +negative matrix. + +This is form and operand-class coverage. The matrix does not enumerate +every register combination, literal value or forward displacement. LLVM +supplies encoding and disassembly evidence. The reference and semantic +review tests exercise execution, including both SCC outcomes and the exact +FP32 domain. The native GPU demo verifies the three executable fixtures. ```sh -LLVM_BIN="$(brew --prefix llvm)/bin" scripts/assemble-fixture.sh --check -LLVM_BIN="$(brew --prefix llvm)/bin" cargo test -p xenora-decoder --test gfx1030 -- --ignored --nocapture +scripts/assemble-fixture.sh --check +LLVM_BIN="$(brew --prefix llvm)/bin" cargo test --locked -p xenora-decoder --test gfx1030 -- --include-ignored --nocapture +cargo test --locked -p xenora-ref -p xenora-semantic-review +scripts/demo.sh ``` The [source notes](../research/rdna2.md) record the XML revision and license. diff --git a/docs/testing/phase01-checkpoint.md b/docs/testing/phase01-checkpoint.md index 938acacd..47f2640e 100644 --- a/docs/testing/phase01-checkpoint.md +++ b/docs/testing/phase01-checkpoint.md @@ -9,7 +9,7 @@ | G3 | `scripts/test-gpu.sh` passed 12 tests with zero failures or skips on Apple M5. The runtime reported Metal API and GPU validation enabled. Includes original offscreen vertex and fragment MSL with 48 checked RGBA8 pixels. Candidate rerun required. Log `artifacts/phase01/native-gpu-final.log`. | | G4 | `scripts/demo.sh` passed all three original fixtures with both validation layers on. Exact readbacks are below. Confirm the command from the final candidate checkout. Log `artifacts/phase01/demo-final.log`. | | G5 | R2 passed four independent CPU tests across widened integer known answers, both SCC outcomes, malformed branch rejection and exact FP32 boundaries. Full independent reference-interpreter assurance and candidate certification remain open. | -| G6 | LLVM 23.1.6 matched production decoding for 34 fixture instructions spanning 15 forms. Automatic comparison with the independent reference decoder is pending. Log `artifacts/phase01/llvm-oracle.log`. | +| G6 | Automated form coverage is complete. LLVM 23.1.6 and both Xenora decoders matched 303 instructions across all 15 supported forms. Candidate-commit and independent reviewer sign-off remain open. See the [coverage matrix](../shaders/instruction-coverage.md#automated-three-way-comparison). | | G7 | `cargo mutants --workspace --list --json` restricted to the decoder, compiler and reference sources enumerated 373 source mutants. The source, semantic and oracle campaigns and survivor triage remain pending. No kill rate is available. | | G8 | `scripts/audit/claims.sh` passed for 15 entries (A=4, B=2, D=6, E=2, U=1). The lint checks registered references and verification state. The audit of all hardware claims in prose remains open. | | G9 | An earlier compiler campaign was interrupted after 74,020,192 reported executions. The latest decoder campaign was interrupted after 106,796,894 reported executions, about 212 seconds, exit 130. Neither log reports a crash before interruption. Latest compiler and reference campaigns were not started. The required 600 seconds per target remain pending. | @@ -43,3 +43,20 @@ The published baseline `96cff7c66e55f1e4693ace19577c207795258d5c` passed its [Na **G11 remains open.** The locked runtime dependency declarations are MIT-compatible selections. The three pinned upstream objc2 licensing explanations match the repository copy byte for byte. The full upstream MIT text is now included with its revision. The sufficiency of copyright notices for locked versions and the Apple SDK terms for a linked distributable remain unresolved. See the [runtime redistribution review](../licenses.md#runtime-redistribution-review). Sprint verification passed `cargo fmt --all -- --check`, all-features workspace Clippy with warnings denied, and 17 tests across decoder, reference and semantic review. The opt-in LLVM test passed separately with 37 instruction comparisons. Claims and dependency-direction checks passed. Both lockfiles passed `cargo audit --no-fetch` against the local advisory database. Local LLVM output is in ignored `artifacts/licensing/llvm.log`. + + +## Three-way decoder assurance, 2026-11-22 + +G6 now has automated three-way coverage for the supported gfx1030 subset. The +LLVM-enabled run passed 8 tests, including 303 successful instruction +comparisons across all 15 forms, 3 malformed LLVM probes, and 6 LLVM-decodable +cases rejected by both Xenora decoders. The reference decoder previously +rejected non-fixture MUBUF operands at decode time. It now reports the full +supported MUBUF encoding while retaining the original synthetic ABI guard +in execution. It still has no production decoder or ISA dependency. + +Formatting, all-features Clippy, the 24 default workspace tests, fixture +reproduction, claims and dependency checks, 12 native tests, and all three +validated GPU demos passed. The two LLVM tests excluded from the default +workspace run passed in the explicit LLVM run. Logs are under ignored +`artifacts/g6/`. G11 and the other open release requirements are unchanged.