mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Merge branch 'main' into task/215-vop1-int-oracle
This commit is contained in:
7 files changed
+1497
-60
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ remains unsupported.
|
||||
- Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits.
|
||||
|
||||
### Added
|
||||
- Added an independent guide-derived oracle for the gfx1030 VOP1 integer forms `v_not_b32`, `v_bfrev_b32`, `v_ffbh_u32`, `v_ffbl_b32`, `v_ffbh_i32` and `v_swap_b32` (`_e32`) in the reference and the second interpreter (752 lane cases, 610 rejections). The decoder and translator do not implement these forms yet, and native Metal agreement is not yet shown. Part of #215.
|
||||
- Added an independent guide-derived oracle for the Wave32 16-bit (`v_cmp_{lt..ge}_{i16,u16}_e32`) and 64-bit (`v_cmp_{f..t}_{i64,u64}_e32`) integer compares in the reference and the second interpreter (6,212 lane cases, 1,208 rejections; contract in `docs/shaders/vector-compare.md` section 2a). The decoder and translator still reject these forms, and native Metal agreement is not yet shown. Part of #215.
|
||||
- Added `python3 -m qa rdna2 rank` to the read-only RDNA2 planner: it groups undeclared gfx1030 forms by the piece of work that would unlock them (an encoding variant of a declared form, a new operand rule, or a new primitive, from XML identity and operand shape only) and ranks the groups by forms per estimated cost, excluding claimed scopes, with `--no-float` to leave out floating-point groups until the FP contract exists (part of #215).
|
||||
- Added authoritative read-only x86-64 CPU inventory CLI (`python3 -m qa cpu-inventory`) over `crates/loader/x86/instructions.toml` via `generate_x86.load`, with opcode-map/prefix/operand summaries, native vs shared-semantic operation partitions from `dbt.rs`, fixture mnemonic evidence and a separate unsupported catalog. Does not count candidates as implemented. Covered by `tests/qa/test_cpu_inventory.py`.
|
||||
- Added typed runtime inventory CLI (`python3 -m qa runtime-inventory`) over `crates/loader/runtime/services.txt`, reporting implemented/partial/stub services separately from API-set aliases and leaving independently-verified empty unless recorded. Covered by `tests/qa/test_runtime_inventory.py`.
|
||||
|
||||
+128
-25
@@ -57,6 +57,10 @@ pub enum Op {
|
||||
MoveScalar(u8, u8),
|
||||
/// VOPC 32-bit integer compare writing the Wave32 mask to `vcc_lo`.
|
||||
Compare(Comparison, CompareSource, u8),
|
||||
/// VOPC 16- or 64-bit integer compare writing the Wave32 mask to
|
||||
/// `vcc_lo`. For 64-bit forms a `Vector` or `Scalar` source and VSRC1 name
|
||||
/// the low register of a pair.
|
||||
WideCompare(Comparison, CompareWidth, CompareSource, u8),
|
||||
/// SOP2 operation writing an SGPR and SCC.
|
||||
Scalar(ScalarAlu, u8, Source, Source),
|
||||
/// SOPC `s_cmp_eq_{i32,u32}` (opcodes 0 and 6, identical per guide 12.4).
|
||||
@@ -94,18 +98,27 @@ pub struct Comparison {
|
||||
}
|
||||
|
||||
impl Comparison {
|
||||
/// The per-lane result, from an exact comparison of the widened operands.
|
||||
/// The per-lane result for 32-bit operands.
|
||||
fn holds(self, s0: u32, s1: u32) -> bool {
|
||||
let widen = |bits: u32| {
|
||||
if self.signed {
|
||||
i64::from(bits as i32)
|
||||
} else {
|
||||
i64::from(bits)
|
||||
self.holds_at(CompareWidth::Word, u64::from(s0), u64::from(s1))
|
||||
}
|
||||
|
||||
/// The per-lane result, from an exact comparison of the operands widened
|
||||
/// from their low `width` bits; higher bits are ignored.
|
||||
fn holds_at(self, width: CompareWidth, s0: u64, s1: u64) -> bool {
|
||||
let widen = |bits: u64| -> i128 {
|
||||
match (width, self.signed) {
|
||||
(CompareWidth::Half, true) => i128::from(bits as u16 as i16),
|
||||
(CompareWidth::Half, false) => i128::from(bits as u16),
|
||||
(CompareWidth::Word, true) => i128::from(bits as u32 as i32),
|
||||
(CompareWidth::Word, false) => i128::from(bits as u32),
|
||||
(CompareWidth::Double, true) => i128::from(bits as i64),
|
||||
(CompareWidth::Double, false) => i128::from(bits),
|
||||
}
|
||||
};
|
||||
let (s0, s1) = (widen(s0), widen(s1));
|
||||
match self.offset {
|
||||
// Table 61: V_CMP_F_{I,U}32 `D[threadId] = 0`.
|
||||
// Table 61: V_CMP_F_{I,U}{32,64} `D[threadId] = 0`.
|
||||
0 => false,
|
||||
1 => s0 < s1,
|
||||
2 => s0 == s1,
|
||||
@@ -113,12 +126,45 @@ impl Comparison {
|
||||
4 => s0 > s1,
|
||||
5 => s0 != s1,
|
||||
6 => s0 >= s1,
|
||||
// Table 61: V_CMP_T_{I,U}32 `D[threadId] = 1`.
|
||||
// Table 61: V_CMP_T_{I,U}{32,64} `D[threadId] = 1`.
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Operand width of a VOPC integer compare (guide 6.2: the data size is the
|
||||
/// one named by the instruction).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum CompareWidth {
|
||||
/// `_I16`/`_U16`: bits 15:0 of each 32-bit source (6.2.5 and 6.8: VOPC
|
||||
/// selects another half only through SDWA, which is not accepted).
|
||||
Half,
|
||||
/// `_I32`/`_U32`.
|
||||
Word,
|
||||
/// `_I64`/`_U64`: register pairs with the low dword in the lower register
|
||||
/// (3.6.3 for SGPRs; for VGPRs the guide states it for 64-bit addresses,
|
||||
/// 9.1: "ADDR has the LSBs, and ADDR+1 has the MSBs").
|
||||
Double,
|
||||
}
|
||||
|
||||
impl CompareWidth {
|
||||
/// Guide 12.9 Tables 59-61: the base opcode of each accepted group plus
|
||||
/// the relation offset; 16-bit groups have no F (offset 0) or T (7).
|
||||
fn from_opcode(opcode: u16) -> Option<(Comparison, Self)> {
|
||||
let (base, signed, width) = match opcode {
|
||||
128..=135 => (128, true, Self::Word),
|
||||
192..=199 => (192, false, Self::Word),
|
||||
137..=142 => (136, true, Self::Half),
|
||||
169..=174 => (168, false, Self::Half),
|
||||
160..=167 => (160, true, Self::Double),
|
||||
224..=231 => (224, false, Self::Double),
|
||||
_ => return None,
|
||||
};
|
||||
let offset = (opcode - base) as u8;
|
||||
Some((Comparison { offset, signed }, width))
|
||||
}
|
||||
}
|
||||
|
||||
/// First source of a VOPC compare or a VOP2 integer form.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum CompareSource {
|
||||
@@ -634,20 +680,38 @@ pub fn decode(code: &[u8]) -> Result<Vec<DecodedInstruction>, ReferenceError> {
|
||||
}
|
||||
// VOPC (bits 31-25 = 0b0111110): SRC0 bits 0-8, VSRC1 bits 9-16, OP bits 17-24.
|
||||
[lo, packed, upper, tag @ 0x7c..=0x7d, tail @ ..]
|
||||
if matches!(
|
||||
if CompareWidth::from_opcode(
|
||||
(u16::from(*tag & 1) << 7) | u16::from(*upper >> 1),
|
||||
128..=135 | 192..=199
|
||||
) =>
|
||||
)
|
||||
.is_some() =>
|
||||
{
|
||||
let opcode = (u16::from(*tag & 1) << 7) | u16::from(*upper >> 1);
|
||||
let comparison = Comparison {
|
||||
offset: (opcode & 0x3f) as u8,
|
||||
signed: opcode < 192,
|
||||
};
|
||||
let (comparison, width) = CompareWidth::from_opcode(opcode).unwrap();
|
||||
let vsrc1 = (packed >> 1) | ((upper & 1) << 7);
|
||||
let selector = u16::from(*lo) | (u16::from(packed & 1) << 8);
|
||||
// docs/shaders/vector-compare.md subset: no literal for 16-bit;
|
||||
// 64-bit takes v[n:n+1] (n <= 254), s[2k:2k+1] (k <= 52) or
|
||||
// an inline integer, with VSRC1 v[m:m+1] (m <= 254).
|
||||
let accepted = match width {
|
||||
CompareWidth::Half => selector != 255,
|
||||
CompareWidth::Word => true,
|
||||
CompareWidth::Double => {
|
||||
vsrc1 != 255
|
||||
&& matches!(selector, 0..=104 | 128..=208 | 256..=510)
|
||||
&& (selector >= 128 || selector % 2 == 0)
|
||||
}
|
||||
};
|
||||
if !accepted {
|
||||
return Err(error(offset, "unsupported VOPC source"));
|
||||
}
|
||||
let (src0, length) =
|
||||
decode_vector_source(*lo, *packed, tail, offset, "unsupported VOPC source")?;
|
||||
(Op::Compare(comparison, src0, vsrc1), length)
|
||||
let op = if width == CompareWidth::Word {
|
||||
Op::Compare(comparison, src0, vsrc1)
|
||||
} else {
|
||||
Op::WideCompare(comparison, width, src0, vsrc1)
|
||||
};
|
||||
(op, length)
|
||||
}
|
||||
// VOP2 integer forms (bit 31 = 0): OP bits 25-30, VDST 17-24,
|
||||
// VSRC1 9-16, SRC0 0-8.
|
||||
@@ -1227,30 +1291,69 @@ fn execute_wave(program: &[DecodedInstruction], input: &[u32]) -> Result<Vec<u32
|
||||
}
|
||||
}
|
||||
// RDNA 2 ISA section 3.9: VCC[n] = EXEC[n] & test(n), fully written.
|
||||
Op::Compare(comparison, src0, src1) => {
|
||||
Op::Compare(..) | Op::WideCompare(..) => {
|
||||
let (comparison, width, src0, src1) = match op {
|
||||
Op::Compare(comparison, src0, src1) => {
|
||||
(comparison, CompareWidth::Word, src0, src1)
|
||||
}
|
||||
Op::WideCompare(comparison, width, src0, src1) => {
|
||||
(comparison, width, src0, src1)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let mut mask = 0u32;
|
||||
if exec != 0 {
|
||||
// The registers each source occupies: a pair for 64-bit forms.
|
||||
let span = |register: u8| {
|
||||
if width == CompareWidth::Double {
|
||||
vec![register, register + 1]
|
||||
} else {
|
||||
vec![register]
|
||||
}
|
||||
};
|
||||
// Sources are checked once for the wave, even if no present lane is active.
|
||||
let check = |register: u8| {
|
||||
(0..lanes).try_for_each(|lane| read(lane, register).map(|_| ()))
|
||||
span(register).into_iter().try_for_each(|register| {
|
||||
(0..lanes).try_for_each(|lane| read(lane, register).map(|_| ()))
|
||||
})
|
||||
};
|
||||
let join = |values: Vec<u32>| {
|
||||
values
|
||||
.iter()
|
||||
.rev()
|
||||
.fold(0u64, |acc, &value| (acc << 32) | u64::from(value))
|
||||
};
|
||||
let read_pair = |lane: usize, register: u8| {
|
||||
span(register)
|
||||
.into_iter()
|
||||
.map(|register| read(lane, register))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map(join)
|
||||
};
|
||||
let read_scalar_pair = |register: u8| {
|
||||
span(register)
|
||||
.into_iter()
|
||||
.map(|register| read_scalar(Source::Register(register)))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map(join)
|
||||
};
|
||||
match src0 {
|
||||
CompareSource::Vector(register) => check(register)?,
|
||||
CompareSource::Scalar(register) => {
|
||||
read_scalar(Source::Register(register))?;
|
||||
read_scalar_pair(register)?;
|
||||
}
|
||||
CompareSource::Immediate(_) => {}
|
||||
}
|
||||
check(src1)?;
|
||||
for lane in (0..lanes).filter(|&lane| executes(lane)) {
|
||||
let s0 = match src0 {
|
||||
CompareSource::Vector(register) => read(lane, register)?,
|
||||
CompareSource::Scalar(register) => {
|
||||
read_scalar(Source::Register(register))?
|
||||
}
|
||||
CompareSource::Immediate(bits) => bits,
|
||||
CompareSource::Vector(register) => read_pair(lane, register)?,
|
||||
CompareSource::Scalar(register) => read_scalar_pair(register)?,
|
||||
// Table 20: an inline integer is the value 0..64 or
|
||||
// -1..-16 at the operand's width (sign extended).
|
||||
CompareSource::Immediate(bits) => bits as i32 as i64 as u64,
|
||||
};
|
||||
if comparison.holds(s0, read(lane, src1)?) {
|
||||
if comparison.holds_at(width, s0, read_pair(lane, src1)?) {
|
||||
mask |= 1 << lane;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,29 @@ stream carries no wave-size declaration (the VOPC word has no wave-size field),
|
||||
so every caller of the translator and the reference establishes Wave32 by
|
||||
using this ABI; there is no Wave64 entry point to reject.
|
||||
|
||||
### 2a. 16-bit and 64-bit compares (reference interpreters only)
|
||||
|
||||
The reference (`crates/ref`) and the second interpreter
|
||||
(`tests/validation/independent_ref.rs`) also accept the `_e32` forms
|
||||
`v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}` (opcodes 137-142, 169-174) and
|
||||
`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i64,u64}` (160-167, 224-231). The decoder and
|
||||
the translator still reject them (section 4); these forms have an oracle
|
||||
but no translation yet.
|
||||
|
||||
- 16-bit forms read bits 15:0 of each 32-bit source and ignore bits 31:16
|
||||
(an inference from guide 6.2, 6.2.5 and 6.8: only SDWA selects a half).
|
||||
There is no literal source.
|
||||
- 64-bit forms read a pair: v[n:n+1] with n <= 254, an even-aligned
|
||||
s[2k:2k+1] with k <= 52 (3.6.3), or an inline integer, which is
|
||||
sign-extended to 64 bits (-1 is all ones, also for `_u64`; a reading of
|
||||
Table 20). VSRC1 is v[m:m+1] with m <= 254. Literals and VCC as a 64-bit
|
||||
source are rejected.
|
||||
- The result, EXEC masking, VCCZ and the empty-EXEC rule are those of
|
||||
sections 3 and 5.
|
||||
|
||||
The expectations and the guide readings are in
|
||||
`tests/validation/tests/vopc_wide.rs`.
|
||||
|
||||
## 3. Semantics of one supported compare, Wave32
|
||||
|
||||
Let E = EXEC_LO before the instruction and A = the set of lanes that exist in
|
||||
@@ -100,7 +123,9 @@ this wave (all 32 except in a final partial wave, see 7). As an unsigned
|
||||
|
||||
- V_CMPX_* (writes EXEC: divergent execution; needs its own contract).
|
||||
- The VOP3 encoding of any compare (arbitrary SGPR destination, modifiers).
|
||||
- SDWA and DPP forms; 16-bit, 64-bit and float compares; v_cmp_class.
|
||||
- SDWA and DPP forms; float compares; v_cmp_class.
|
||||
- 16-bit and 64-bit compares in the decoder and translator (the reference
|
||||
interpreters accept the subset in 2a).
|
||||
- SRC0 inline float constants (240-248), SGPRs other than s0-s106, TTMPs,
|
||||
M0, EXEC_LO/HI, VCC_HI, SCC/VCCZ/EXECZ selectors, LDS direct.
|
||||
- A normal-SGPR SRC0 without a known value, when EXEC_LO != 0.
|
||||
@@ -226,7 +251,17 @@ programs, plus 2 mask-chain programs (252 in all), and the F/T fixture (253) mat
|
||||
(`vector_compare_native_metal_known_answers`, run by `scripts/test-gpu.sh`). The F/T oracle's own native Metal cases
|
||||
run in `vopc_f_t_match_the_guide_on_native_metal`.
|
||||
|
||||
A deliberately broken copy of each implementation fails these tests: the
|
||||
The 16-bit and 64-bit oracle (`tests/validation/tests/vopc_wide.rs`) checks
|
||||
6,212 lane cases on both reference interpreters, plus 1,208 rejections and the
|
||||
13 neighbouring opcodes, and that the production compiler still rejects all 28
|
||||
forms. Its native Metal test stays ignored (and skipped by `scripts/test-gpu.sh`)
|
||||
until the translator implements these forms. Deliberately broken copies of both
|
||||
interpreters (16-bit reads of 32 bits, swapped pair halves, zero-extended
|
||||
inline integers, flipped signedness, reads under empty EXEC and others) each
|
||||
fail it.
|
||||
|
||||
For the 32-bit forms, a deliberately broken copy of each implementation fails
|
||||
the tests above: the
|
||||
reference with unsigned-only compares or with the EXEC test removed; the
|
||||
second interpreter with unsigned-only compares or with no empty-EXEC rule;
|
||||
the translator with a stale VCC under empty EXEC (CPU), and, on Metal, with
|
||||
@@ -238,7 +273,9 @@ locally on Apple M5 Pro. It is not agreement with RDNA 2 or Xbox hardware.
|
||||
|
||||
## 10. Limitations
|
||||
|
||||
- Wave32 only. No `v_cmpx`, VOP3, SDWA, DPP, 16-bit, 64-bit or float compares.
|
||||
- Wave32 only. No `v_cmpx`, VOP3, SDWA, DPP or float compares. 16-bit and
|
||||
64-bit compares exist only in the reference interpreters (2a); native Metal
|
||||
agreement for them is not shown.
|
||||
- A lane-derived VCC_LO cannot reach EXEC or any scalar instruction, so there
|
||||
is no divergent execution. That needs its own contract.
|
||||
- The skipped region of a runtime `s_cbranch_vccz` holds only integer vector
|
||||
|
||||
+2
-3
@@ -53,7 +53,6 @@ timeout 30s cargo test --locked -p xenora-ffi --features gpu-tests --test audio_
|
||||
# Native Metal known answers of the independent semantic review, including SOP2 scalar ALU
|
||||
# and VOPC compares.
|
||||
cargo test --locked -p xenora-semantic-review --no-run
|
||||
# Oracles whose translator side has not landed are skipped by name until it does
|
||||
# (#215: the PR that translates the forms removes its skip).
|
||||
# Oracles whose translator side has not landed are skipped by name until it does.
|
||||
timeout 120s cargo test --locked -p xenora-semantic-review -- --ignored --nocapture --test-threads=1 \
|
||||
--skip vop1_integer_forms_match_the_guide_on_native_metal
|
||||
--skip vopc_wide_match_the_guide_on_native_metal
|
||||
@@ -29,8 +29,10 @@
|
||||
//! production operator. SOP2 arithmetic runs through a bit-serial ripple
|
||||
//! adder (subtraction as addition of the complement), not host integer ops.
|
||||
//!
|
||||
//! Wave32 VOPC integer compares (`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32}_e32`,
|
||||
//! contract `docs/shaders/vector-compare.md`) need all lanes of a wave, so execution
|
||||
//! Wave32 VOPC integer compares
|
||||
//! (`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32,i64,u64}_e32` and
|
||||
//! `v_cmp_{lt,eq,le,gt,ne,ge}_{i16,u16}_e32`, contract
|
||||
//! `docs/shaders/vector-compare.md`) need all lanes of a wave, so execution
|
||||
//! runs lockstep waves of 32 consecutive dispatch indices with wave-uniform
|
||||
//! scalar state and per-lane vector state. A lane-local failure stops only that
|
||||
//! lane and the lowest-index error is reported, so programs without compares
|
||||
@@ -78,9 +80,11 @@ enum Insn {
|
||||
/// `v_mov_b32_e32 vD, vcc_lo`.
|
||||
VMovFromVcc(u8),
|
||||
/// VOPC compare into VCC_LO: relation 0 f, 1 lt, 2 eq, 3 le, 4 gt, 5 ne, 6 ge, 7 t.
|
||||
/// `bits` is 16, 32 or 64; 64-bit register operands name the low register of a pair.
|
||||
VCmp {
|
||||
relation: u8,
|
||||
signed: bool,
|
||||
bits: u32,
|
||||
src0: CmpSrc,
|
||||
src1: u8,
|
||||
},
|
||||
@@ -202,6 +206,7 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
Insn::VCmp {
|
||||
relation,
|
||||
signed,
|
||||
bits,
|
||||
src0,
|
||||
src1,
|
||||
} => {
|
||||
@@ -214,7 +219,7 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
&lanes,
|
||||
&sgpr,
|
||||
execution_mask,
|
||||
(relation, signed, src0, src1),
|
||||
(relation, signed, bits, src0, src1),
|
||||
offset,
|
||||
)
|
||||
.map(|mask| {
|
||||
@@ -551,29 +556,58 @@ fn compare(
|
||||
lanes: &[Lane],
|
||||
sgpr: &[Option<u32>; 128],
|
||||
execution_mask: u32,
|
||||
(relation, signed, src0, src1): (u8, bool, CmpSrc, u8),
|
||||
(relation, signed, bits, src0, src1): (u8, bool, u32, CmpSrc, u8),
|
||||
offset: usize,
|
||||
) -> Result<u32, String> {
|
||||
if execution_mask == 0 {
|
||||
// Encoding already validated; nothing is read (contract 5).
|
||||
return Ok(0);
|
||||
}
|
||||
let scalar_src0 = match src0 {
|
||||
CmpSrc::Sgpr(reg) => {
|
||||
Some(sgpr[reg as usize].ok_or_else(|| format!("{offset:#x}: uninitialized s{reg}"))?)
|
||||
// Registers per operand: a 64-bit operand is {reg (bits 31:0), reg+1 (63:32)}.
|
||||
let count: u8 = if bits == 64 { 2 } else { 1 };
|
||||
let read_s = |reg: u8| -> Result<u64, String> {
|
||||
let mut value = 0u64;
|
||||
for half in (0..count).rev() {
|
||||
let r = reg + half;
|
||||
let word =
|
||||
sgpr[r as usize].ok_or_else(|| format!("{offset:#x}: uninitialized s{r}"))?;
|
||||
value = value * (1 << 32) + u64::from(word);
|
||||
}
|
||||
CmpSrc::Vcc => Some(sgpr[106].ok_or_else(|| format!("{offset:#x}: uninitialized vcc_lo"))?),
|
||||
CmpSrc::Imm(value) => Some(value),
|
||||
Ok(value)
|
||||
};
|
||||
let read_v = |lane: &Lane, reg: u8| -> Result<u64, String> {
|
||||
let mut value = 0u64;
|
||||
for half in (0..count).rev() {
|
||||
value = value * (1 << 32) + u64::from(read_vgpr(lane, reg + half, offset)?);
|
||||
}
|
||||
Ok(value)
|
||||
};
|
||||
let scalar_src0 = match src0 {
|
||||
CmpSrc::Sgpr(reg) => Some(read_s(reg)?),
|
||||
CmpSrc::Vcc => {
|
||||
Some(u64::from(sgpr[106].ok_or_else(|| {
|
||||
format!("{offset:#x}: uninitialized vcc_lo")
|
||||
})?))
|
||||
}
|
||||
// Inline integers -16..64 keep their value at every width; a
|
||||
// 32-bit literal (32-bit forms only) is used as its 32 bits.
|
||||
CmpSrc::Imm(value) if bits == 64 && value >= 0x8000_0000 => {
|
||||
Some(u64::from(value) + 0xffff_ffff_0000_0000)
|
||||
}
|
||||
CmpSrc::Imm(value) => Some(u64::from(value)),
|
||||
CmpSrc::Vgpr(_) => None,
|
||||
};
|
||||
// VGPR readiness is wave-uniform; validate it on every existing lane so
|
||||
// acceptance does not depend on which lanes are active.
|
||||
for lane in lanes {
|
||||
if let CmpSrc::Vgpr(reg) = src0 {
|
||||
read_vgpr(lane, reg, offset)?;
|
||||
read_v(lane, reg)?;
|
||||
}
|
||||
read_vgpr(lane, src1, offset)?;
|
||||
read_v(lane, src1)?;
|
||||
}
|
||||
// Only the low `bits` bits take part (16-bit forms ignore bits 31:16).
|
||||
let keep = u64::MAX >> (64 - bits);
|
||||
let sign = 1u64 << (bits - 1);
|
||||
let mut mask = 0u32;
|
||||
for (n, lane) in lanes.iter().enumerate() {
|
||||
if (execution_mask >> n) & 1 == 0 {
|
||||
@@ -581,16 +615,13 @@ fn compare(
|
||||
}
|
||||
let a = match (scalar_src0, src0) {
|
||||
(Some(value), _) => value,
|
||||
(None, CmpSrc::Vgpr(reg)) => read_vgpr(lane, reg, offset)?,
|
||||
(None, CmpSrc::Vgpr(reg)) => read_v(lane, reg)?,
|
||||
(None, _) => unreachable!(),
|
||||
};
|
||||
let b = read_vgpr(lane, src1, offset)?;
|
||||
let b = read_v(lane, src1)?;
|
||||
let (a, b) = (a & keep, b & keep);
|
||||
// Signed order equals unsigned order after flipping the sign bit.
|
||||
let (a, b) = if signed {
|
||||
(a ^ 0x8000_0000, b ^ 0x8000_0000)
|
||||
} else {
|
||||
(a, b)
|
||||
};
|
||||
let (a, b) = if signed { (a ^ sign, b ^ sign) } else { (a, b) };
|
||||
// Guide 12.9 Table 59 offsets; F (0) and T (7) ignore the operand
|
||||
// values but still read them (contract 5: sources are validated).
|
||||
let pass = match relation {
|
||||
@@ -1119,17 +1150,37 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
|
||||
// VOPC: bits 31:25 = 0b0111110, OP 24:17, VSRC1 16:9, SRC0 8:0.
|
||||
if first >> 25 == 0b011_1110 {
|
||||
let opcode = (first >> 17) & 0xff;
|
||||
let (signed, relation) = match opcode {
|
||||
128..=135 => (true, opcode - 128),
|
||||
192..=199 => (false, opcode - 192),
|
||||
// Guide 12.9 Table 61 opcode groups (16-bit groups lack F and T).
|
||||
let (signed, bits, relation) = match opcode {
|
||||
128..=135 => (true, 32, opcode - 128),
|
||||
192..=199 => (false, 32, opcode - 192),
|
||||
137..=142 => (true, 16, opcode - 136),
|
||||
169..=174 => (false, 16, opcode - 168),
|
||||
160..=167 => (true, 64, opcode - 160),
|
||||
224..=231 => (false, 64, opcode - 224),
|
||||
_ => return Err(fail("unsupported VOPC opcode")),
|
||||
};
|
||||
let (src0, len) = vector_src0(code, offset, first, "VOPC")?;
|
||||
let src1 = (first >> 9) as u8;
|
||||
// Accepted subset: no literal for 16-bit forms; 64-bit forms take an
|
||||
// even SGPR pair below VCC, a VGPR pair below v255 or an inline integer.
|
||||
let allowed = match (bits, src0) {
|
||||
(16 | 64, CmpSrc::Imm(_)) if len == 8 => false,
|
||||
(64, CmpSrc::Vcc) => false,
|
||||
(64, CmpSrc::Sgpr(reg)) => reg % 2 == 0 && src1 != 255,
|
||||
(64, CmpSrc::Vgpr(reg)) => reg != 255 && src1 != 255,
|
||||
(64, _) => src1 != 255,
|
||||
_ => true,
|
||||
};
|
||||
if !allowed {
|
||||
return Err(fail("unsupported VOPC operand"));
|
||||
}
|
||||
let insn = Insn::VCmp {
|
||||
relation: relation as u8,
|
||||
signed,
|
||||
bits,
|
||||
src0,
|
||||
src1: (first >> 9) as u8,
|
||||
src1,
|
||||
};
|
||||
return Ok((insn, len));
|
||||
}
|
||||
|
||||
@@ -666,16 +666,14 @@ fn vopc_f_t_outside_the_contract_are_rejected() {
|
||||
|
||||
#[test]
|
||||
fn other_constant_compares_stay_unsupported() {
|
||||
// F and T/TRU of the float, 64-bit and v_cmpx groups (Table 61):
|
||||
// F and T/TRU of the float and v_cmpx groups (Table 61):
|
||||
// V_CMP_F_F32 0, V_CMP_TRU_F32 15, V_CMPX_F_F32 16, V_CMPX_TRU_F32 31,
|
||||
// V_CMP_F_I64 160, V_CMP_T_I64 167, V_CMPX_F_I64 176, V_CMPX_T_I64 183,
|
||||
// V_CMP_F_U64 224, V_CMP_T_U64 231, V_CMPX_F_U64 240, V_CMPX_T_U64 247.
|
||||
// V_CMPX_F_I64 176, V_CMPX_T_I64 183, V_CMPX_F_U64 240, V_CMPX_T_U64 247.
|
||||
// The 64-bit V_CMP_F/T (160, 167, 224, 231) are covered by vopc_wide.rs.
|
||||
let setup = vmov(3, 7);
|
||||
// Also the neighbours of the two 32-bit integer groups: 127 and 191 (not
|
||||
// in Table 61), 136 V_CMP_CLASS_F32 and 200 V_CMP_F_F16.
|
||||
for op in [
|
||||
0, 15, 16, 31, 127, 136, 160, 167, 176, 183, 191, 200, 224, 231, 240, 247,
|
||||
] {
|
||||
for op in [0, 15, 16, 31, 127, 136, 176, 183, 191, 200, 240, 247] {
|
||||
let (code, offset) = program(&setup, None, &[vopc(op, vgpr(1), 3)], &[]);
|
||||
assert_rejected_at(&format!("opcode {op}"), &code, offset, &lanes());
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user