mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Merge upstream main a2a6a56 into system runtime branch
Signed-off-by: Adeeb Rahman <therealabeeb@icloud.com>
This commit is contained in:
commit
6c460f7c1c
17 files changed
+6164
-225
No files matched your search
@@ -10,6 +10,7 @@ Guest execution uses original, purpose-built test programs. Commercial Xbox game
|
||||
remains unsupported.
|
||||
|
||||
### Changed
|
||||
- Moved the six hand-written gfx1030 VOP2 logical and shift forms (`v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`, `v_ashrrev_i32`, AMD guide section 12.7) into the semantic registry under a new VGPR-only operand rule `vop2_vgpr2`, with no behaviour change: a sweep of 132,608 VOP2, VOP1 and SOP1 words decodes to the same text, length and error before and after, the MSL goldens are unchanged, and the runtime-region allowlist admits exactly the same six forms. The per-lane `VectorBinary` gained `And`, `Or`, `Xor` and the three shifts (count masked to S0[4:0]); 6 hand-written instruction variants and their decoder and lowering arms are gone (17 hand-written forms remain). Part of #215.
|
||||
- Added non-blocking Metal compute submission through `submit_words` and `wait`, with completion-aware resource retirement and a sixteen-dispatch in-flight limit. Synchronous calls keep their existing behavior. The benchmark reports the host submission split and compares synchronous and pipelined batches.
|
||||
- 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.
|
||||
|
||||
@@ -24,6 +25,7 @@ remains unsupported.
|
||||
- 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`.
|
||||
|
||||
- Added `crates/loader/tests/cpu_known_answers.rs` (#155): 736 x86-64 cases whose results, flags, MXCSR state and faults come from the Intel SDM, with the AMD APM for some MXCSR flags, plus arithmetic, shift, packed-integer, multiply, divide and floating-point sweeps computed from the manuals' definitions. 700 cases were written before the CPU source was read; the rest and the sweeps came afterwards. The interpreter and the DBT both run them; the DBT route (ARM64 code or Rust helper) is confirmed by the fallback counter for straight-line cases and predicted for the others. 592 cases are verified, 133 use forms both engines refuse, and eleven, plus a self-modifying-code test, record open defects in five ignored tests: the reported address of a page-crossing fault, the fault class of a non-canonical address and of an instruction over 15 bytes, PE set by an exact unmasked overflow, and DBT blocks that stay cached after the guest rewrites them. Not compared with x86 hardware; awaiting independent review.
|
||||
- Added a typed runtime service registry (`crates/loader/runtime/services.txt`) and `xenora-runtime-gen`, which generates Win64 argument and result adapters, static metadata and a coverage report. It covers 20 services: 16 existing kernel32 services moved to typed handlers, and `sqrt`, `sqrtf`, `fabs` and `fabsf` with arguments and results in XMM registers. Conflicting keys, unlisted API sets, unsupported types and behaviour without an existing test are rejected. See `docs/runtime/registry.md`.
|
||||
- Added SSE and SSE2 floating point in scalar and packed, binary32 and binary64 forms: add, subtract, multiply, divide, minimum, maximum, square root, compares, COMI/UCOMI and the conversions between formats and integers (parts of #127 and #128; awaiting independent review). `crates/loader/src/softfloat.rs` computes every result exactly and rounds once, with MXCSR rounding modes, sticky flags, denormals-are-zero, flush-to-zero, tininess after rounding and x86 NaN rules; host floating point is not used because ARM64 differs. An unmasked exception exits with `SimdException` and leaves everything but MXCSR unchanged. RCP, RSQRT and MMX conversions are rejected, and no floating-point form is translated to NEON yet.
|
||||
- Added 6,824 floating-point vectors computed with exact fractions by `tests/x86/float_reference.py`, run through both engines from registers and memory and through the packed forms, and more than two million round-to-nearest results compared with the host's IEEE 754 hardware.
|
||||
@@ -273,6 +275,7 @@ remains unsupported.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed the intermittent failure of the frame-loop memory-footprint test (#290). Each frame-loop session opened its own Metal command queue. The first command buffer on a queue makes the GPU driver allocate a working set for it (about 45 MiB on an Apple M5 with Metal validation), and the driver frees it asynchronously 10–50 ms after the queue is released, so the process footprint read right after a session ended depended on how far that release had got. Measured immediately after each of 50 destroys, it ranged from 45 to 96 MiB; the unchanged test failed 5 times in 30 runs, with up to 26 MiB of apparent growth. There was no leak: one second after each destroy the footprint was back at the same floor every time. Frame-loop sessions now share one process-wide Metal device and command queue, so the working set is allocated once and kept: the same readings stay within 93–98 MiB across 50 sessions, and the unchanged test passed 30 runs in a row (largest growth 0.31 MiB). The cost is that the process keeps that GPU memory (about 50 MiB with validation, 58 MiB total footprint without) after its first frame loop. A new 50-session test (normal completion, pause and resume, destroy while running) checks the readings stay within 16 MiB; it fails without the fix.
|
||||
- Stop ignoring `fixtures/pe/trusted-runner.exe`. The runner embeds it with `include_bytes!`, so ignoring the file made a fresh checkout fail to compile.
|
||||
- Corrected the ARM64 STP pre-index encoder, which had a hardcoded -32-byte immediate and therefore adjusted the host stack by the wrong amount once the translator frame grew to 48 bytes. The wrong frame silently corrupted the caller's stack and caused SIGSEGV in every native translation test. Emitter encodings are now checked against LLVM's assembler, and a test asserts that each translated block opens and closes the same 48-byte frame.
|
||||
- Translated guest memory faults now stop the block before it commits further architectural effects. A faulting push, call or store leaves guest RSP and registers unchanged, the reported instruction count covers only completed work, and guest RIP identifies the faulting instruction. Previously the block continued after the helper recorded a fault, so later instructions and writes still took effect.
|
||||
|
||||
@@ -8,11 +8,8 @@ Xenora is an open-source project written primarily in Rust that builds and verif
|
||||
|
||||
Xenora is still experimental. Verified work is restricted to independently authored synthetic programs and shaders; authentic Xbox executable loading, system-service compatibility and commercial game execution remain unsupported. See the [current limitations](#current-limitations).
|
||||
|
||||
### At a glance
|
||||
|
||||
- **Native graphics:** translated gfx1030 vertex and pixel stages and native passes (indexed draws, blend, depth) run on Apple Silicon GPUs — verified, see [Blend pass](#blend-pass) and [Verified Apple M5 results](#verified-apple-m5-results).
|
||||
- **Guest execution:** bounded x86-64 execution, original PE32+ loading, synthetic services and guest-driven GPU dispatch — verified milestones X1–X9.
|
||||
- **Not supported:** authentic Xbox executable loading and commercial game execution; see the [milestone table](#development-milestones).
|
||||
> [!CAUTION]
|
||||
> **Xenora strictly opposes piracy.** Xenora is an independent, clean-room, general-purpose emulation research project that neither distributes copyrighted game files nor supports unauthorized content, DRM circumvention, or leaked materials. Use only legally obtained software. Xenora is not affiliated with Microsoft, Rockstar Games, Take-Two Interactive, or any other publisher or platform holder.
|
||||
|
||||
[](https://github.com/ranveersoni98/Xenora/actions/workflows/ci.yml)
|
||||
|
||||
@@ -58,8 +55,6 @@ The latest verified milestones include **translated gfx1030 vertex and pixel sha
|
||||
|
||||
All existing verification refers to independently authored synthetic programs and shaders. Commercial-game compatibility remains unverified.
|
||||
|
||||
See the [X9 acceptance matrix](docs/testing/x9-acceptance.md) for specific tests, results and unsupported behavior.
|
||||
|
||||
## Native graphics translation
|
||||
|
||||
Xenora's graphics pipeline translates a supported subset of AMD RDNA 2 instructions into Metal Shading Language.
|
||||
@@ -376,4 +371,4 @@ See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for third-party attribution
|
||||
|
||||
Xenora is an independent open-source project and is not affiliated with Microsoft, Xbox, Rockstar Games or Apple.
|
||||
|
||||
---
|
||||
---
|
||||
+11
-53
@@ -10,13 +10,12 @@ pub use xenora_isa::{
|
||||
use xenora_isa::{
|
||||
BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, EXP, IMAGE_SAMPLE_LZ, S_BRANCH, S_CBRANCH_EXECZ,
|
||||
S_CBRANCH_SCC0, S_CBRANCH_VCCZ, S_ENDPGM, S_MOV_B32, S_WAITCNT, S_WAITCNT_VSCNT, V_ADD_F32,
|
||||
V_AND_B32, V_ASHRREV_I32, V_INTERP_P1_F32, V_INTERP_P2_F32, V_LSHLREV_B32, V_LSHRREV_B32,
|
||||
V_MOV_B32, V_MUL_F32, V_OR_B32, V_XOR_B32, VCC_LO,
|
||||
V_INTERP_P1_F32, V_INTERP_P2_F32, V_MOV_B32, V_MUL_F32, VCC_LO,
|
||||
};
|
||||
|
||||
use xenora_isa::meta::EncodingFamily;
|
||||
use xenora_isa::semantics::FORM_IDS;
|
||||
pub use xenora_isa::semantics::VectorBinary;
|
||||
use xenora_isa::semantics::{FORM_IDS, OperandRule};
|
||||
|
||||
/// Metadata forms that [`decode`] turns into an [`Instruction`] for at least one
|
||||
/// operand combination: the hand-written forms below followed by every form of
|
||||
@@ -41,7 +40,7 @@ const fn concat_forms<const N: usize>() -> [(&'static str, EncodingFamily); N] {
|
||||
}
|
||||
|
||||
/// Decoded forms not yet described by the semantic registry.
|
||||
const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 23] = [
|
||||
const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 17] = [
|
||||
("BUFFER_LOAD_DWORD", EncodingFamily::Mubuf),
|
||||
("BUFFER_STORE_DWORD", EncodingFamily::Mubuf),
|
||||
("EXP", EncodingFamily::Exp),
|
||||
@@ -55,16 +54,10 @@ const HANDWRITTEN_FORMS: [(&str, EncodingFamily); 23] = [
|
||||
("S_WAITCNT", EncodingFamily::Sopp),
|
||||
("S_WAITCNT_VSCNT", EncodingFamily::Sopk),
|
||||
("V_ADD_F32", EncodingFamily::Vop2),
|
||||
("V_AND_B32", EncodingFamily::Vop2),
|
||||
("V_ASHRREV_I32", EncodingFamily::Vop2),
|
||||
("V_INTERP_P1_F32", EncodingFamily::Vintrp),
|
||||
("V_INTERP_P2_F32", EncodingFamily::Vintrp),
|
||||
("V_LSHLREV_B32", EncodingFamily::Vop2),
|
||||
("V_LSHRREV_B32", EncodingFamily::Vop2),
|
||||
("V_MOV_B32", EncodingFamily::Vop1),
|
||||
("V_MUL_F32", EncodingFamily::Vop2),
|
||||
("V_OR_B32", EncodingFamily::Vop2),
|
||||
("V_XOR_B32", EncodingFamily::Vop2),
|
||||
];
|
||||
|
||||
/// A successfully decoded instruction and its location in the input stream.
|
||||
@@ -401,7 +394,14 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
// VOP2: SRC0 in bits 0-8, VSRC1 in bits 9-16, VDST in bits 17-24.
|
||||
let dst = ((first >> 17) & 0xff) as u8;
|
||||
let src1 = ((first >> 9) & 0xff) as u8;
|
||||
let (src0, len) = vector_src0(first, bytes, op.assembly_name())?;
|
||||
let (src0, len) = match op.operand_rule() {
|
||||
// Operand rule `vop2_vgpr2`: SRC0 must select a VGPR (256-511).
|
||||
OperandRule::Vop2Vgpr2 => {
|
||||
let (_, src0, _) = vop2_registers(first, op.assembly_name())?;
|
||||
(VectorSource::Register(src0), 4)
|
||||
}
|
||||
_ => vector_src0(first, bytes, op.assembly_name())?,
|
||||
};
|
||||
return Ok((
|
||||
Instruction::VectorAlu {
|
||||
op,
|
||||
@@ -412,48 +412,6 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
len,
|
||||
));
|
||||
}
|
||||
if V_LSHLREV_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_lshlrev_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 },
|
||||
V_LSHLREV_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_ASHRREV_I32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_ashrrev_i32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 },
|
||||
V_ASHRREV_I32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_LSHRREV_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_lshrrev_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 },
|
||||
V_LSHRREV_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_AND_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_and_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorAndB32 { dst, src0, src1 },
|
||||
V_AND_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_OR_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_or_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorOrB32 { dst, src0, src1 },
|
||||
V_OR_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_XOR_B32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_xor_b32_e32")?;
|
||||
return Ok((
|
||||
Instruction::VectorXorB32 { dst, src0, src1 },
|
||||
V_XOR_B32.byte_len(),
|
||||
));
|
||||
}
|
||||
if V_ADD_F32.matches(first) {
|
||||
let (dst, src0, src1) = vop2_registers(first, "v_add_f32_e32")?;
|
||||
return Ok((
|
||||
|
||||
@@ -432,22 +432,32 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
target,
|
||||
condition: BranchCondition::Always,
|
||||
},
|
||||
Instruction::VectorAndB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::And, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ShiftLeft, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ArithmeticShiftRight, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::ShiftRight, dst, src0, src1)
|
||||
}
|
||||
Instruction::VectorOrB32 { dst, src0, src1 } => Op::Vector(VectorAlu::Or, dst, src0, src1),
|
||||
Instruction::VectorXorB32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::Xor, dst, src0, src1)
|
||||
}
|
||||
// The six logical and shift forms migrated from hand-written code
|
||||
// (#215 M27) keep the reference's VGPR-only VectorAlu ops.
|
||||
Instruction::VectorAlu {
|
||||
op:
|
||||
op @ (VectorAluOp::AndB32
|
||||
| VectorAluOp::OrB32
|
||||
| VectorAluOp::XorB32
|
||||
| VectorAluOp::LshlrevB32
|
||||
| VectorAluOp::LshrrevB32
|
||||
| VectorAluOp::AshrrevI32),
|
||||
dst,
|
||||
src0: VectorSource::Register(src0),
|
||||
src1,
|
||||
} => Op::Vector(
|
||||
match op {
|
||||
VectorAluOp::AndB32 => VectorAlu::And,
|
||||
VectorAluOp::OrB32 => VectorAlu::Or,
|
||||
VectorAluOp::XorB32 => VectorAlu::Xor,
|
||||
VectorAluOp::LshlrevB32 => VectorAlu::ShiftLeft,
|
||||
VectorAluOp::LshrrevB32 => VectorAlu::ShiftRight,
|
||||
_ => VectorAlu::ArithmeticShiftRight,
|
||||
},
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
),
|
||||
Instruction::VectorAddF32 { dst, src0, src1 } => {
|
||||
Op::Vector(VectorAlu::FloatAdd, dst, src0, src1)
|
||||
}
|
||||
@@ -500,6 +510,7 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
VectorAluOp::AddNcU32 => VectorInteger::Add,
|
||||
VectorAluOp::SubNcU32 => VectorInteger::Subtract,
|
||||
VectorAluOp::SubrevNcU32 => VectorInteger::SubtractReverse,
|
||||
_ => panic!("{op:?} decodes only with a VGPR SRC0 (operand rule vop2_vgpr2)"),
|
||||
},
|
||||
dst,
|
||||
match src0 {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//! the guest leaves its loop and halts.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
|
||||
use std::sync::{Arc, Condvar, Mutex, MutexGuard, OnceLock};
|
||||
use std::thread::JoinHandle;
|
||||
|
||||
use xenora_loader::startup::{StartupLayout, run_synthetic_startup};
|
||||
@@ -206,8 +206,8 @@ impl FrameLoop {
|
||||
include_bytes!("../../../fixtures/rdna2/x9-constant-ps.bin"),
|
||||
)
|
||||
.map_err(|e| format!("shader translation: {e}"))?;
|
||||
let gpu = NativeCompute::new().map_err(|e| format!("Metal device: {e}"))?;
|
||||
// The session's GPU resources live on the guest thread, where the import runs.
|
||||
let gpu = shared_gpu()?;
|
||||
// The import runs on the guest thread, so the session's shader lives there too.
|
||||
GPU.with(|slot| *slot.borrow_mut() = Some((gpu, shader.msl)));
|
||||
|
||||
let shared = Arc::clone(self);
|
||||
@@ -315,7 +315,26 @@ impl FrameLoop {
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
static GPU: RefCell<Option<(NativeCompute, String)>> = const { RefCell::new(None) };
|
||||
static GPU: RefCell<Option<(&'static NativeCompute, String)>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
/// One Metal device and command queue shared by every frame-loop session (#290).
|
||||
///
|
||||
/// The first command buffer submitted on a queue makes the GPU driver allocate a
|
||||
/// working set for it (about 45 MiB on an Apple M5 with Metal validation), and the
|
||||
/// driver frees that memory asynchronously, 10–50 ms after the queue is released.
|
||||
/// A queue per session therefore allocated and freed it once per session, and the
|
||||
/// process footprint depended on how far that release had progressed. One queue
|
||||
/// for the process allocates the working set once and keeps it: bounded caching,
|
||||
/// not per-session churn. `NativeCompute` is `Send + Sync`, and rendering takes
|
||||
/// `&self`, so concurrent sessions can share it. A device that cannot be opened
|
||||
/// is reported to every session that asks.
|
||||
fn shared_gpu() -> Result<&'static NativeCompute, String> {
|
||||
static SHARED: OnceLock<Result<NativeCompute, String>> = OnceLock::new();
|
||||
SHARED
|
||||
.get_or_init(|| NativeCompute::new().map_err(|e| format!("Metal device: {e}")))
|
||||
.as_ref()
|
||||
.map_err(Clone::clone)
|
||||
}
|
||||
|
||||
/// Frame `index` is a red strip in column `index % 4` on the clear colour.
|
||||
|
||||
+139
-21
@@ -82,25 +82,6 @@ fn wait_until(session: u64, what: &str, done: impl Fn(&Status) -> bool) -> Statu
|
||||
}
|
||||
}
|
||||
|
||||
/// Footprint once it has stopped changing. After a session is destroyed, Metal gives
|
||||
/// back its memory asynchronously: measured on an Apple M5, a reading taken right after
|
||||
/// destroy was up to about 45 MiB above the floor it returned to within one second,
|
||||
/// every time. A single immediate reading therefore mixes in memory that is already on
|
||||
/// its way out. Read every 50 ms until two consecutive readings agree within 1 MiB
|
||||
/// (at most 5 s). A genuine leak still settles high, so it is still caught.
|
||||
fn settled_footprint() -> u64 {
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
let mut previous = footprint();
|
||||
loop {
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
let current = footprint();
|
||||
if current.abs_diff(previous) < 1 << 20 || Instant::now() >= deadline {
|
||||
return current;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
/// Physical memory footprint of this process (macOS `proc_pid_rusage`, RUSAGE_INFO_V2).
|
||||
fn footprint() -> u64 {
|
||||
unsafe extern "C" {
|
||||
@@ -264,11 +245,11 @@ fn repeated_sessions_do_not_grow_the_memory_footprint() {
|
||||
// Warm up so one-time allocations (Metal device, shader compiler) are excluded.
|
||||
run();
|
||||
run();
|
||||
let baseline = settled_footprint();
|
||||
let baseline = footprint();
|
||||
for _ in 0..5 {
|
||||
run();
|
||||
}
|
||||
let after = settled_footprint();
|
||||
let after = footprint();
|
||||
let growth = after.saturating_sub(baseline);
|
||||
println!("footprint baseline={baseline} after_5_sessions={after} growth={growth}");
|
||||
assert!(
|
||||
@@ -276,3 +257,140 @@ fn repeated_sessions_do_not_grow_the_memory_footprint() {
|
||||
"footprint grew by {growth} bytes over 5 sessions of 300 frames"
|
||||
);
|
||||
}
|
||||
|
||||
/// Regression test for #290: the footprint read right after each destroy must stay
|
||||
/// flat across many sessions. Each session used to open its own Metal command queue,
|
||||
/// and the GPU driver frees a queue's working set (about 45 MiB on an Apple M5 with
|
||||
/// validation) asynchronously after release, so these readings swung by about 50 MiB
|
||||
/// from session to session. Sessions now share one queue. The mix of sessions covers
|
||||
/// normal completion, pause and resume, and destruction while running.
|
||||
#[test]
|
||||
fn fifty_sessions_keep_a_flat_footprint_after_each_destroy() {
|
||||
let _serial = SERIAL.lock().unwrap_or_else(|p| p.into_inner());
|
||||
let one = |kind: usize| {
|
||||
let session = session();
|
||||
match kind {
|
||||
0 => {
|
||||
assert_eq!(xenora_session_start_frame_loop(session, 100), XENORA_OK);
|
||||
let s = wait_until(session, "100 frames", |s| s.state != XENORA_LOOP_RUNNING);
|
||||
assert_eq!((s.state, s.completed), (XENORA_LOOP_FINISHED, 100));
|
||||
}
|
||||
1 => {
|
||||
assert_eq!(xenora_session_start_frame_loop(session, 100), XENORA_OK);
|
||||
wait_until(session, "10 frames", |s| s.completed >= 10);
|
||||
assert_eq!(xenora_session_pause_frame_loop(session), XENORA_OK);
|
||||
assert_eq!(xenora_session_resume_frame_loop(session), XENORA_OK);
|
||||
let s = wait_until(session, "100 frames", |s| s.state != XENORA_LOOP_RUNNING);
|
||||
assert_eq!((s.state, s.completed), (XENORA_LOOP_FINISHED, 100));
|
||||
}
|
||||
_ => {
|
||||
assert_eq!(
|
||||
xenora_session_start_frame_loop(session, XENORA_FRAME_LOOP_MAX_FRAMES),
|
||||
XENORA_OK
|
||||
);
|
||||
wait_until(session, "a frame", |s| s.completed >= 1);
|
||||
}
|
||||
}
|
||||
assert_eq!(xenora_session_destroy(session), XENORA_OK);
|
||||
footprint()
|
||||
};
|
||||
one(0); // the first session allocates the shared queue's working set
|
||||
let readings: Vec<u64> = (0..50).map(|i| one(i % 3)).collect();
|
||||
let mib: Vec<u64> = readings.iter().map(|r| r >> 20).collect();
|
||||
println!("footprint after each destroy (MiB): {mib:?}");
|
||||
let median = |values: &[u64]| {
|
||||
let mut sorted = values.to_vec();
|
||||
sorted.sort_unstable();
|
||||
sorted[sorted.len() / 2]
|
||||
};
|
||||
// Sustained growth: the typical reading at the end against the start.
|
||||
let (start, end) = (median(&readings[..10]), median(&readings[40..]));
|
||||
assert!(
|
||||
end.saturating_sub(start) < 16 << 20,
|
||||
"footprint grew from {start} to {end} bytes (median of first and last ten sessions)"
|
||||
);
|
||||
// Per-session churn, the cause fixed in #290: with a queue per session, about half
|
||||
// of all readings sat some 45 MiB away from the median. With the shared queue,
|
||||
// a reading is still occasionally caught while the driver frees a batch of
|
||||
// per-frame render resources: graphics-tagged memory only, 16 to 44 MiB, gone
|
||||
// within about 100 ms, measured in 13 of 6,000 sessions (0.22%). Allowing two such
|
||||
// readings in 50 keeps a false failure near 1 in 5,000 runs while per-session
|
||||
// churn would exceed it every time.
|
||||
let centre = median(&readings);
|
||||
let outliers: Vec<u64> = readings
|
||||
.iter()
|
||||
.filter(|&&r| r.abs_diff(centre) >= 16 << 20)
|
||||
.map(|r| r >> 20)
|
||||
.collect();
|
||||
assert!(
|
||||
outliers.len() <= 2,
|
||||
"{} of 50 readings were 16 MiB or more from the median {} MiB: {outliers:?}",
|
||||
outliers.len(),
|
||||
centre >> 20
|
||||
);
|
||||
}
|
||||
|
||||
/// Two sessions render at the same time through the shared Metal queue (#290). Each
|
||||
/// must keep its own frame sequence and pixels, pausing one must not stop the other,
|
||||
/// and destroying one mid-run must not disturb the other.
|
||||
#[test]
|
||||
fn concurrent_sessions_share_the_queue_but_stay_isolated() {
|
||||
let _serial = SERIAL.lock().unwrap_or_else(|p| p.into_inner());
|
||||
let (a, b) = (session(), session());
|
||||
assert_eq!(xenora_session_start_frame_loop(a, 400), XENORA_OK);
|
||||
assert_eq!(xenora_session_start_frame_loop(b, 250), XENORA_OK);
|
||||
wait_until(a, "session A started", |s| s.completed >= 5);
|
||||
wait_until(b, "session B started", |s| s.completed >= 5);
|
||||
|
||||
// Pausing A holds only A.
|
||||
assert_eq!(xenora_session_pause_frame_loop(a), XENORA_OK);
|
||||
let a_held = wait_until(a, "session A paused", |s| s.state == XENORA_LOOP_PAUSED);
|
||||
let b_before = status(b).completed;
|
||||
let b_moving = wait_until(b, "session B progress while A is paused", |s| {
|
||||
s.completed >= b_before + 20 || s.state != XENORA_LOOP_RUNNING
|
||||
});
|
||||
assert!(
|
||||
b_moving.completed > b_before,
|
||||
"B kept rendering while A was paused"
|
||||
);
|
||||
let a_still = status(a);
|
||||
assert_eq!(a_still.state, XENORA_LOOP_PAUSED);
|
||||
// At most the frame A was rendering when paused can still complete.
|
||||
assert!(a_still.completed <= a_held.completed + 1);
|
||||
assert_eq!(a_still.rgba.to_vec(), expected(a_still.frame_id));
|
||||
assert_eq!(xenora_session_resume_frame_loop(a), XENORA_OK);
|
||||
|
||||
// Both finish with their own counts and their own final frames.
|
||||
let a_done = wait_until(a, "session A finished", |s| s.state != XENORA_LOOP_RUNNING);
|
||||
let b_done = wait_until(b, "session B finished", |s| s.state != XENORA_LOOP_RUNNING);
|
||||
assert_eq!(
|
||||
(a_done.state, a_done.completed, a_done.frame_id),
|
||||
(XENORA_LOOP_FINISHED, 400, 399)
|
||||
);
|
||||
assert_eq!(
|
||||
(b_done.state, b_done.completed, b_done.frame_id),
|
||||
(XENORA_LOOP_FINISHED, 250, 249)
|
||||
);
|
||||
assert_eq!(a_done.rgba.to_vec(), expected(399));
|
||||
assert_eq!(b_done.rgba.to_vec(), expected(249));
|
||||
assert_eq!(xenora_session_destroy(a), XENORA_OK);
|
||||
assert_eq!(xenora_session_destroy(b), XENORA_OK);
|
||||
|
||||
// Destroying one running session leaves the other running to completion.
|
||||
let (c, d) = (session(), session());
|
||||
assert_eq!(
|
||||
xenora_session_start_frame_loop(c, XENORA_FRAME_LOOP_MAX_FRAMES),
|
||||
XENORA_OK
|
||||
);
|
||||
assert_eq!(xenora_session_start_frame_loop(d, 300), XENORA_OK);
|
||||
wait_until(c, "session C started", |s| s.completed >= 5);
|
||||
wait_until(d, "session D started", |s| s.completed >= 5);
|
||||
assert_eq!(xenora_session_destroy(c), XENORA_OK);
|
||||
let d_done = wait_until(d, "session D finished", |s| s.state != XENORA_LOOP_RUNNING);
|
||||
assert_eq!(
|
||||
(d_done.state, d_done.completed, d_done.frame_id),
|
||||
(XENORA_LOOP_FINISHED, 300, 299)
|
||||
);
|
||||
assert_eq!(d_done.rgba.to_vec(), expected(299));
|
||||
assert_eq!(xenora_session_destroy(d), XENORA_OK);
|
||||
}
|
||||
@@ -222,6 +222,12 @@ VECTOR_PRIMITIVES = {
|
||||
("mul24", "unsigned"): "Mul24Unsigned",
|
||||
("mul_hi24", "signed"): "MulHi24Signed",
|
||||
("mul_hi24", "unsigned"): "MulHi24Unsigned",
|
||||
("and", "bitwise"): "And",
|
||||
("or", "bitwise"): "Or",
|
||||
("xor", "bitwise"): "Xor",
|
||||
("lshl", "bitwise"): "ShiftLeft",
|
||||
("lshr", "bitwise"): "ShiftRight",
|
||||
("ashr", "signed"): "ArithmeticShiftRight",
|
||||
}
|
||||
|
||||
# Operand rules the decoder implements, each exactly once. A registry rule must
|
||||
@@ -346,6 +352,26 @@ OPERAND_RULES = {
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
"vop2_vgpr2": {
|
||||
"rust": "Vop2Vgpr2",
|
||||
"enum": "VectorAluOp",
|
||||
"shape": {
|
||||
"family": "VOP2",
|
||||
"dst": {"field": "VDST", "class": "vgpr", "min": 0, "max": 255},
|
||||
"src": [
|
||||
{"field": "SRC0", "class": "vgpr"},
|
||||
{"field": "VSRC1", "class": "vgpr"},
|
||||
],
|
||||
"max_literals": 0,
|
||||
},
|
||||
# The subset the hand-written decoder accepted before the registry (#215
|
||||
# M27): SRC0 must select a VGPR (256-511); the decoder rejects the rest.
|
||||
"unsupported": {
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal",
|
||||
},
|
||||
"kind": "vector",
|
||||
},
|
||||
}
|
||||
|
||||
VARIANT = re.compile(r"^[A-Z][A-Za-z0-9]*$")
|
||||
@@ -546,7 +572,8 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
fields = [(rule["dst"]["field"], False)] if "dst" in rule else []
|
||||
fields += [(src["field"], True) for src in rule["src"]]
|
||||
shift = form["operation"] in CONTROL_S1 and len(rule["src"]) > 1
|
||||
count_field = rule["src"][1]["field"] if shift else None
|
||||
# The shift count is S1, or S0 for a form that reads its sources reversed.
|
||||
count_field = rule["src"][0 if SOURCE_ORDER_KEY in form else 1]["field"] if shift else None
|
||||
for field, is_source in fields:
|
||||
if field not in operands:
|
||||
errors.append(f"{label}: XML has no operand {field}")
|
||||
@@ -942,8 +969,15 @@ def render(registry, snapshot):
|
||||
"/// Registry schema of the generated tables.",
|
||||
f"pub const GENERATED_SCHEMA: u32 = {registry['schema']};",
|
||||
]
|
||||
# Rules that share a generated enum (VOP2 `vop2_vgpr` and `vop2_vgpr2`) render
|
||||
# it once, with the forms of all of them in registry order.
|
||||
rendered = set()
|
||||
for rule_name in rule_names:
|
||||
selected = [form for form in forms if form["operands"] == rule_name]
|
||||
enum = OPERAND_RULES[rule_name]["enum"]
|
||||
if enum in rendered:
|
||||
continue
|
||||
rendered.add(enum)
|
||||
selected = [form for form in forms if OPERAND_RULES[form["operands"]]["enum"] == enum]
|
||||
out += _render_enum(rule_name, selected, snapshot, positions)
|
||||
variants = registry.get("encoding_variant", [])
|
||||
variant_positions = {
|
||||
@@ -1093,6 +1127,9 @@ def _render_variants(rule_name, variants, registry, snapshot, positions):
|
||||
def _render_enum(rule_name, forms, snapshot, positions):
|
||||
enum = OPERAND_RULES[rule_name]["enum"]
|
||||
kind = OPERAND_RULES[rule_name]["kind"]
|
||||
rules = sorted({form["operands"] for form in forms})
|
||||
if any(OPERAND_RULES[name]["kind"] != kind for name in rules):
|
||||
raise ValueError(f"{enum}: operand rules {rules} of one enum differ in kind")
|
||||
table = re.sub(r"(?<!^)(?=[A-Z])", "_", enum).upper() + "_BY_OPCODE"
|
||||
family = forms[0]["family"]
|
||||
encoding = snapshot["encodings"][_family_encoding(family)]
|
||||
@@ -1109,7 +1146,8 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
raise ValueError(f"{family}: identifiers do not split into fixed bits and OP")
|
||||
out = [
|
||||
"",
|
||||
f"/// {family} operations declared in the semantic registry (operand rule `{rule_name}`).",
|
||||
f"/// {family} operations declared in the semantic registry (operand rule"
|
||||
f"{'s' if len(rules) > 1 else ''} {', '.join(f'`{name}`' for name in rules)}).",
|
||||
"#[derive(Clone, Copy, Debug, Eq, PartialEq)]",
|
||||
f"pub enum {enum} {{",
|
||||
]
|
||||
@@ -1241,6 +1279,18 @@ def _render_enum(rule_name, forms, snapshot, positions):
|
||||
f" Self::{form['variant']} => {'true' if SOURCE_ORDER_KEY in form else 'false'},"
|
||||
for form in forms
|
||||
]
|
||||
out += [
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" /// The operand rule the decoder applies to the 32-bit encoding.",
|
||||
" pub const fn operand_rule(self) -> OperandRule {",
|
||||
" match self {",
|
||||
]
|
||||
out += [
|
||||
f" Self::{form['variant']} => OperandRule::{OPERAND_RULES[form['operands']]['rust']},"
|
||||
for form in forms
|
||||
]
|
||||
out += [" }", " }", "}"]
|
||||
return out
|
||||
if kind == "vector_compare":
|
||||
|
||||
@@ -223,3 +223,128 @@ wave = "any"
|
||||
operands = "vop2_vgpr"
|
||||
spec = [{ document = "guide", section = "12.7", page = 134 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
# ---- VOP2 logical and shift forms migrated from hand-written code (#215 M27) ----
|
||||
# Per lane under EXEC; no SCC, VCC or EXEC write (guide 12.7). The shifts read
|
||||
# their sources reversed: D = S1 shifted by S0[4:0]; ASHRREV fills with S1's sign.
|
||||
# These keep the subset the hand-written decoder accepted: both sources VGPRs.
|
||||
[operand_rules.vop2_vgpr2]
|
||||
family = "VOP2"
|
||||
dst = { field = "VDST", class = "vgpr", min = 0, max = 255 }
|
||||
src = [
|
||||
{ field = "SRC0", class = "vgpr" },
|
||||
{ field = "VSRC1", class = "vgpr" },
|
||||
]
|
||||
max_literals = 0
|
||||
unsupported = [
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal",
|
||||
]
|
||||
|
||||
[[form]]
|
||||
name = "V_LSHRREV_B32"
|
||||
family = "VOP2"
|
||||
opcode = 22
|
||||
variant = "LshrrevB32"
|
||||
operation = "lshr"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_ASHRREV_I32"
|
||||
family = "VOP2"
|
||||
opcode = 24
|
||||
variant = "AshrrevI32"
|
||||
operation = "ashr"
|
||||
signedness = "signed"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_LSHLREV_B32"
|
||||
family = "VOP2"
|
||||
opcode = 26
|
||||
variant = "LshlrevB32"
|
||||
operation = "lshl"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
shift_count_bits = 5
|
||||
source_order = "reversed"
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_AND_B32"
|
||||
family = "VOP2"
|
||||
opcode = 27
|
||||
variant = "AndB32"
|
||||
operation = "and"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_OR_B32"
|
||||
family = "VOP2"
|
||||
opcode = 28
|
||||
variant = "OrB32"
|
||||
operation = "or"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[form]]
|
||||
name = "V_XOR_B32"
|
||||
family = "VOP2"
|
||||
opcode = 29
|
||||
variant = "XorB32"
|
||||
operation = "xor"
|
||||
signedness = "bitwise"
|
||||
carry_in = "none"
|
||||
width = 32
|
||||
scc = "unchanged"
|
||||
vcc = "unchanged"
|
||||
exec = "unchanged"
|
||||
wave = "any"
|
||||
operands = "vop2_vgpr2"
|
||||
spec = [{ document = "guide", section = "12.7", page = 133 }]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
@@ -209,18 +209,6 @@ pub enum Instruction {
|
||||
BranchVccZero { target: usize },
|
||||
/// SOPP unconditional jump to a stream byte offset.
|
||||
Branch { target: usize },
|
||||
/// VOP2 logical left shift with the count in src0.
|
||||
VectorLshlrevB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 logical right shift with the count in src0.
|
||||
VectorLshrrevB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 arithmetic right shift with the count in src0.
|
||||
VectorAshrrevI32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise AND.
|
||||
VectorAndB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise OR.
|
||||
VectorOrB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 bitwise XOR.
|
||||
VectorXorB32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 single-precision addition. Execution requires an explicit FP mode.
|
||||
VectorAddF32 { dst: u8, src0: u8, src1: u8 },
|
||||
/// VOP2 single-precision multiplication. Execution requires an explicit FP mode.
|
||||
@@ -288,12 +276,6 @@ impl Instruction {
|
||||
Self::BranchExecZero { .. } => "s_cbranch_execz",
|
||||
Self::BranchVccZero { .. } => "s_cbranch_vccz",
|
||||
Self::Branch { .. } => "s_branch",
|
||||
Self::VectorLshlrevB32 { .. } => "v_lshlrev_b32_e32",
|
||||
Self::VectorLshrrevB32 { .. } => "v_lshrrev_b32_e32",
|
||||
Self::VectorAshrrevI32 { .. } => "v_ashrrev_i32_e32",
|
||||
Self::VectorAndB32 { .. } => "v_and_b32_e32",
|
||||
Self::VectorOrB32 { .. } => "v_or_b32_e32",
|
||||
Self::VectorXorB32 { .. } => "v_xor_b32_e32",
|
||||
Self::VectorAddF32 { .. } => "v_add_f32_e32",
|
||||
Self::VectorMulF32 { .. } => "v_mul_f32_e32",
|
||||
Self::Export { .. } => "exp",
|
||||
@@ -337,12 +319,6 @@ impl fmt::Display for Instruction {
|
||||
Self::VectorAluVop3 {
|
||||
dst, src0, src1, ..
|
||||
}
|
||||
| Self::VectorLshlrevB32 { dst, src0, src1 }
|
||||
| Self::VectorLshrrevB32 { dst, src0, src1 }
|
||||
| Self::VectorAshrrevI32 { dst, src0, src1 }
|
||||
| Self::VectorAndB32 { dst, src0, src1 }
|
||||
| Self::VectorOrB32 { dst, src0, src1 }
|
||||
| Self::VectorXorB32 { dst, src0, src1 }
|
||||
| Self::VectorAddF32 { dst, src0, src1 }
|
||||
| Self::VectorMulF32 { dst, src0, src1 } => {
|
||||
write!(formatter, " v{dst}, v{src0}, v{src1}")
|
||||
|
||||
@@ -119,6 +119,18 @@ pub enum VectorBinary {
|
||||
MulHi24Signed,
|
||||
/// Bits 63:32 of `a[23:0] * b[23:0]`.
|
||||
MulHi24Unsigned,
|
||||
/// `a & b`.
|
||||
And,
|
||||
/// `a | b`.
|
||||
Or,
|
||||
/// `a ^ b`.
|
||||
Xor,
|
||||
/// `a << (b & 31)`.
|
||||
ShiftLeft,
|
||||
/// Logical `a >> (b & 31)`.
|
||||
ShiftRight,
|
||||
/// Arithmetic (sign-filling) `a >> (b & 31)`.
|
||||
ArithmeticShiftRight,
|
||||
}
|
||||
|
||||
/// How the operands are interpreted. `Bitwise` exactly when the operation is logical.
|
||||
@@ -204,6 +216,9 @@ pub enum OperandRule {
|
||||
/// integer -16..64 or a literal word; VSRC1 is a VGPR. Everything else is
|
||||
/// rejected as unsupported.
|
||||
Vop2Vgpr,
|
||||
/// VOP2 vector, VGPR sources only: VDST is v0-v255; SRC0 and VSRC1 are VGPRs.
|
||||
/// Everything else (SGPR, inline, literal SRC0) is rejected as unsupported.
|
||||
Vop2Vgpr2,
|
||||
}
|
||||
|
||||
/// Evidence a form needs before it counts as verified.
|
||||
|
||||
+231
-27
@@ -1198,7 +1198,7 @@ impl ScalarCompareOp {
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP2 operations declared in the semantic registry (operand rule `vop2_vgpr`).
|
||||
/// VOP2 operations declared in the semantic registry (operand rules `vop2_vgpr`, `vop2_vgpr2`).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorAluOp {
|
||||
/// `v_mul_i32_i24` (VOP2 opcode 9): signed mul24, SCC = unchanged.
|
||||
@@ -1225,6 +1225,18 @@ pub enum VectorAluOp {
|
||||
SubNcU32,
|
||||
/// `v_subrev_nc_u32` (VOP2 opcode 39): unsigned sub, SCC = unchanged.
|
||||
SubrevNcU32,
|
||||
/// `v_lshrrev_b32` (VOP2 opcode 22): bitwise lshr, SCC = unchanged.
|
||||
LshrrevB32,
|
||||
/// `v_ashrrev_i32` (VOP2 opcode 24): signed ashr, SCC = unchanged.
|
||||
AshrrevI32,
|
||||
/// `v_lshlrev_b32` (VOP2 opcode 26): bitwise lshl, SCC = unchanged.
|
||||
LshlrevB32,
|
||||
/// `v_and_b32` (VOP2 opcode 27): bitwise and, SCC = unchanged.
|
||||
AndB32,
|
||||
/// `v_or_b32` (VOP2 opcode 28): bitwise or, SCC = unchanged.
|
||||
OrB32,
|
||||
/// `v_xor_b32` (VOP2 opcode 29): bitwise xor, SCC = unchanged.
|
||||
XorB32,
|
||||
}
|
||||
|
||||
/// VectorAluOp by VOP2 OP field value; `None` for undeclared opcodes.
|
||||
@@ -1251,14 +1263,14 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
Some(VectorAluOp::MinU32),
|
||||
Some(VectorAluOp::MaxU32),
|
||||
None,
|
||||
Some(VectorAluOp::LshrrevB32),
|
||||
None,
|
||||
Some(VectorAluOp::AshrrevI32),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(VectorAluOp::LshlrevB32),
|
||||
Some(VectorAluOp::AndB32),
|
||||
Some(VectorAluOp::OrB32),
|
||||
Some(VectorAluOp::XorB32),
|
||||
Some(VectorAluOp::XnorB32),
|
||||
None,
|
||||
None,
|
||||
@@ -1297,7 +1309,7 @@ const VECTOR_ALU_OP_BY_OPCODE: [Option<VectorAluOp>; 64] = [
|
||||
|
||||
impl VectorAluOp {
|
||||
/// Every operation, in registry order.
|
||||
pub const ALL: [Self; 12] = [
|
||||
pub const ALL: [Self; 18] = [
|
||||
Self::MulI32I24,
|
||||
Self::MulHiI32I24,
|
||||
Self::MulU32U24,
|
||||
@@ -1310,6 +1322,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32,
|
||||
Self::SubNcU32,
|
||||
Self::SubrevNcU32,
|
||||
Self::LshrrevB32,
|
||||
Self::AshrrevI32,
|
||||
Self::LshlrevB32,
|
||||
Self::AndB32,
|
||||
Self::OrB32,
|
||||
Self::XorB32,
|
||||
];
|
||||
|
||||
/// Selects the operation from a first instruction word: the VOP2 encoding
|
||||
@@ -1336,6 +1354,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => "v_add_nc_u32",
|
||||
Self::SubNcU32 => "v_sub_nc_u32",
|
||||
Self::SubrevNcU32 => "v_subrev_nc_u32",
|
||||
Self::LshrrevB32 => "v_lshrrev_b32",
|
||||
Self::AshrrevI32 => "v_ashrrev_i32",
|
||||
Self::LshlrevB32 => "v_lshlrev_b32",
|
||||
Self::AndB32 => "v_and_b32",
|
||||
Self::OrB32 => "v_or_b32",
|
||||
Self::XorB32 => "v_xor_b32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1354,6 +1378,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => 65,
|
||||
Self::SubNcU32 => 66,
|
||||
Self::SubrevNcU32 => 67,
|
||||
Self::LshrrevB32 => 68,
|
||||
Self::AshrrevI32 => 69,
|
||||
Self::LshlrevB32 => 70,
|
||||
Self::AndB32 => 71,
|
||||
Self::OrB32 => 72,
|
||||
Self::XorB32 => 73,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1372,6 +1402,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => "v_add_nc_u32_e32",
|
||||
Self::SubNcU32 => "v_sub_nc_u32_e32",
|
||||
Self::SubrevNcU32 => "v_subrev_nc_u32_e32",
|
||||
Self::LshrrevB32 => "v_lshrrev_b32_e32",
|
||||
Self::AshrrevI32 => "v_ashrrev_i32_e32",
|
||||
Self::LshlrevB32 => "v_lshlrev_b32_e32",
|
||||
Self::AndB32 => "v_and_b32_e32",
|
||||
Self::OrB32 => "v_or_b32_e32",
|
||||
Self::XorB32 => "v_xor_b32_e32",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1390,6 +1426,12 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => VectorBinary::Add,
|
||||
Self::SubNcU32 => VectorBinary::Sub,
|
||||
Self::SubrevNcU32 => VectorBinary::Sub,
|
||||
Self::LshrrevB32 => VectorBinary::ShiftRight,
|
||||
Self::AshrrevI32 => VectorBinary::ArithmeticShiftRight,
|
||||
Self::LshlrevB32 => VectorBinary::ShiftLeft,
|
||||
Self::AndB32 => VectorBinary::And,
|
||||
Self::OrB32 => VectorBinary::Or,
|
||||
Self::XorB32 => VectorBinary::Xor,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1408,6 +1450,36 @@ impl VectorAluOp {
|
||||
Self::AddNcU32 => false,
|
||||
Self::SubNcU32 => false,
|
||||
Self::SubrevNcU32 => true,
|
||||
Self::LshrrevB32 => true,
|
||||
Self::AshrrevI32 => true,
|
||||
Self::LshlrevB32 => true,
|
||||
Self::AndB32 => false,
|
||||
Self::OrB32 => false,
|
||||
Self::XorB32 => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The operand rule the decoder applies to the 32-bit encoding.
|
||||
pub const fn operand_rule(self) -> OperandRule {
|
||||
match self {
|
||||
Self::MulI32I24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulHiI32I24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulU32U24 => OperandRule::Vop2Vgpr,
|
||||
Self::MulHiU32U24 => OperandRule::Vop2Vgpr,
|
||||
Self::MinI32 => OperandRule::Vop2Vgpr,
|
||||
Self::MaxI32 => OperandRule::Vop2Vgpr,
|
||||
Self::MinU32 => OperandRule::Vop2Vgpr,
|
||||
Self::MaxU32 => OperandRule::Vop2Vgpr,
|
||||
Self::XnorB32 => OperandRule::Vop2Vgpr,
|
||||
Self::AddNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::SubNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::SubrevNcU32 => OperandRule::Vop2Vgpr,
|
||||
Self::LshrrevB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::AshrrevI32 => OperandRule::Vop2Vgpr2,
|
||||
Self::LshlrevB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::AndB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::OrB32 => OperandRule::Vop2Vgpr2,
|
||||
Self::XorB32 => OperandRule::Vop2Vgpr2,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1764,22 +1836,22 @@ impl VectorCompareOp {
|
||||
/// The validated registry row.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::CmpLtI32 => 68,
|
||||
Self::CmpEqI32 => 69,
|
||||
Self::CmpLeI32 => 70,
|
||||
Self::CmpGtI32 => 71,
|
||||
Self::CmpNeI32 => 72,
|
||||
Self::CmpGeI32 => 73,
|
||||
Self::CmpLtU32 => 74,
|
||||
Self::CmpEqU32 => 75,
|
||||
Self::CmpLeU32 => 76,
|
||||
Self::CmpGtU32 => 77,
|
||||
Self::CmpNeU32 => 78,
|
||||
Self::CmpGeU32 => 79,
|
||||
Self::CmpFI32 => 80,
|
||||
Self::CmpTI32 => 81,
|
||||
Self::CmpFU32 => 82,
|
||||
Self::CmpTU32 => 83,
|
||||
Self::CmpLtI32 => 74,
|
||||
Self::CmpEqI32 => 75,
|
||||
Self::CmpLeI32 => 76,
|
||||
Self::CmpGtI32 => 77,
|
||||
Self::CmpNeI32 => 78,
|
||||
Self::CmpGeI32 => 79,
|
||||
Self::CmpLtU32 => 80,
|
||||
Self::CmpEqU32 => 81,
|
||||
Self::CmpLeU32 => 82,
|
||||
Self::CmpGtU32 => 83,
|
||||
Self::CmpNeU32 => 84,
|
||||
Self::CmpGeU32 => 85,
|
||||
Self::CmpFI32 => 86,
|
||||
Self::CmpTI32 => 87,
|
||||
Self::CmpFU32 => 88,
|
||||
Self::CmpTU32 => 89,
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -1915,13 +1987,13 @@ impl VectorAluVop3Op {
|
||||
/// The validated registry row of this encoding.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::AddNcU32 => 84,
|
||||
Self::AddNcU32 => 90,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity of every registry form and encoding variant, in registry order.
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 91] = [
|
||||
("S_ADD_U32", EncodingFamily::Sop2),
|
||||
("S_SUB_U32", EncodingFamily::Sop2),
|
||||
("S_ADD_I32", EncodingFamily::Sop2),
|
||||
@@ -1990,6 +2062,12 @@ pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
("V_ADD_NC_U32", EncodingFamily::Vop2),
|
||||
("V_SUB_NC_U32", EncodingFamily::Vop2),
|
||||
("V_SUBREV_NC_U32", EncodingFamily::Vop2),
|
||||
("V_LSHRREV_B32", EncodingFamily::Vop2),
|
||||
("V_ASHRREV_I32", EncodingFamily::Vop2),
|
||||
("V_LSHLREV_B32", EncodingFamily::Vop2),
|
||||
("V_AND_B32", EncodingFamily::Vop2),
|
||||
("V_OR_B32", EncodingFamily::Vop2),
|
||||
("V_XOR_B32", EncodingFamily::Vop2),
|
||||
("V_CMP_LT_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_EQ_I32", EncodingFamily::Vopc),
|
||||
("V_CMP_LE_I32", EncodingFamily::Vopc),
|
||||
@@ -2010,7 +2088,7 @@ pub const FORM_IDS: [(&str, EncodingFamily); 85] = [
|
||||
];
|
||||
|
||||
/// One validated row per registry form, in registry order.
|
||||
pub static FORMS: [FormSemantics; 85] = [
|
||||
pub static FORMS: [FormSemantics; 91] = [
|
||||
FormSemantics {
|
||||
name: "S_ADD_U32",
|
||||
family: EncodingFamily::Sop2,
|
||||
@@ -3439,6 +3517,132 @@ pub static FORMS: [FormSemantics; 85] = [
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_LSHRREV_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 22,
|
||||
operation: Operation::LogicalShiftRight,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_ASHRREV_I32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 24,
|
||||
operation: Operation::ArithmeticShiftRight,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_LSHLREV_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 26,
|
||||
operation: Operation::ShiftLeft,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 5,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_AND_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 27,
|
||||
operation: Operation::And,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_OR_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 28,
|
||||
operation: Operation::Or,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_XOR_B32",
|
||||
family: EncodingFamily::Vop2,
|
||||
opcode: 29,
|
||||
operation: Operation::Xor,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop2Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LT_I32",
|
||||
family: EncodingFamily::Vopc,
|
||||
|
||||
@@ -102,8 +102,8 @@ fn vector_alu_dispatch_selects_exactly_the_registry_vop2_forms() {
|
||||
assert_eq!(op.swaps_sources(), row.swap_sources);
|
||||
assert_eq!(row.scc, SccEffect::Unchanged);
|
||||
}
|
||||
// The hand-written VOP2 forms (v_and_b32, v_add_f32, ...) must not be
|
||||
// dispatched here.
|
||||
// Exactly the registry VOP2 forms are dispatched here; the hand-written
|
||||
// ones (v_add_f32, v_mul_f32) must not be.
|
||||
dispatch_selects_exactly(EncodingFamily::Vop2, |word| {
|
||||
VectorAluOp::from_word(word).map(|op| op.semantics().name)
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+34
-58
@@ -9,8 +9,8 @@ pub use graphics::{PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics};
|
||||
|
||||
pub use xenora_decoder::Architecture;
|
||||
use xenora_decoder::{
|
||||
DecodeError, DecodedInstruction, Instruction, ScalarSource, VectorAluVop3Op, VectorBinary,
|
||||
VectorCompareOp, VectorSource,
|
||||
DecodeError, DecodedInstruction, Instruction, ScalarSource, VectorAluOp, VectorAluVop3Op,
|
||||
VectorBinary, VectorCompareOp, VectorSource,
|
||||
};
|
||||
|
||||
/// SGPR index of `vcc_lo`.
|
||||
@@ -156,14 +156,7 @@ impl Op {
|
||||
Binary::FloatAdd | Binary::FloatMul => format!(
|
||||
"as_type<uint>(as_type<float>({left}) {symbol} as_type<float>({right}))"
|
||||
),
|
||||
Binary::ArithmeticShiftRight => {
|
||||
format!("as_type<uint>(as_type<int>({left}) {symbol} ({right} & 31u))")
|
||||
}
|
||||
Binary::ShiftLeft | Binary::ShiftRight => {
|
||||
format!("{left} {symbol} ({right} & 31u)")
|
||||
}
|
||||
Binary::Vector(operation) => vector_expression(operation, &left, &right),
|
||||
_ => format!("{left} {symbol} {right}"),
|
||||
}
|
||||
}
|
||||
Self::MergeLanes {
|
||||
@@ -215,12 +208,6 @@ fn compare_expression(op: VectorCompareOp, left: &str, right: &str) -> String {
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Binary {
|
||||
ShiftLeft,
|
||||
ShiftRight,
|
||||
ArithmeticShiftRight,
|
||||
And,
|
||||
Or,
|
||||
Xor,
|
||||
FloatAdd,
|
||||
FloatMul,
|
||||
/// A registry VOP2 integer operation (or its VOP3 encoding), lowered by its
|
||||
@@ -231,12 +218,6 @@ enum Binary {
|
||||
impl Binary {
|
||||
fn operator(self) -> (&'static str, &'static str) {
|
||||
match self {
|
||||
Self::ShiftLeft => ("lshl.b32", "<<"),
|
||||
Self::ShiftRight => ("lshr.b32", ">>"),
|
||||
Self::ArithmeticShiftRight => ("ashr.i32", ">>"),
|
||||
Self::And => ("and.b32", "&"),
|
||||
Self::Or => ("or.b32", "|"),
|
||||
Self::Xor => ("xor.b32", "^"),
|
||||
Self::FloatAdd => ("add.f32", "+"),
|
||||
Self::FloatMul => ("mul.f32", "*"),
|
||||
Self::Vector(operation) => (
|
||||
@@ -252,6 +233,12 @@ impl Binary {
|
||||
VectorBinary::Mul24Unsigned => "mul24.u32",
|
||||
VectorBinary::MulHi24Signed => "mulhi24.i32",
|
||||
VectorBinary::MulHi24Unsigned => "mulhi24.u32",
|
||||
VectorBinary::And => "and.b32",
|
||||
VectorBinary::Or => "or.b32",
|
||||
VectorBinary::Xor => "xor.b32",
|
||||
VectorBinary::ShiftLeft => "lshl.b32",
|
||||
VectorBinary::ShiftRight => "lshr.b32",
|
||||
VectorBinary::ArithmeticShiftRight => "ashr.i32",
|
||||
},
|
||||
"",
|
||||
),
|
||||
@@ -286,6 +273,15 @@ fn vector_expression(operation: VectorBinary, left: &str, right: &str) -> String
|
||||
format!("as_type<uint>(mulhi({}, {}))", i24(left), i24(right))
|
||||
}
|
||||
VectorBinary::MulHi24Unsigned => format!("mulhi({}, {})", u24(left), u24(right)),
|
||||
VectorBinary::And => format!("{left} & {right}"),
|
||||
VectorBinary::Or => format!("{left} | {right}"),
|
||||
VectorBinary::Xor => format!("{left} ^ {right}"),
|
||||
// MSL leaves shifts by 32 or more undefined; the guide reads S0[4:0].
|
||||
VectorBinary::ShiftLeft => format!("{left} << ({right} & 31u)"),
|
||||
VectorBinary::ShiftRight => format!("{left} >> ({right} & 31u)"),
|
||||
VectorBinary::ArithmeticShiftRight => {
|
||||
format!("as_type<uint>(as_type<int>({left}) >> ({right} & 31u))")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -689,15 +685,22 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
dst,
|
||||
..
|
||||
}
|
||||
| Instruction::VectorLshlrevB32 { dst, .. }
|
||||
| Instruction::VectorLshrrevB32 { dst, .. }
|
||||
| Instruction::VectorAshrrevI32 { dst, .. }
|
||||
| Instruction::VectorAndB32 { dst, .. }
|
||||
| Instruction::VectorOrB32 { dst, .. }
|
||||
| Instruction::VectorXorB32 { dst, .. } => dst,
|
||||
// Of the registry VOP2 forms, the contract admits only the six
|
||||
// logical and shift forms that were hand-written before (#215 M27).
|
||||
| Instruction::VectorAlu {
|
||||
op:
|
||||
VectorAluOp::LshlrevB32
|
||||
| VectorAluOp::LshrrevB32
|
||||
| VectorAluOp::AshrrevI32
|
||||
| VectorAluOp::AndB32
|
||||
| VectorAluOp::OrB32
|
||||
| VectorAluOp::XorB32,
|
||||
dst,
|
||||
..
|
||||
} => dst,
|
||||
_ => {
|
||||
return Err(error(
|
||||
"code skipped by a runtime s_cbranch_vccz may contain only v_mov_b32, v_add_nc_u32_e64 and the hand-written integer VOP2 forms",
|
||||
"code skipped by a runtime s_cbranch_vccz may contain only v_mov_b32, v_add_nc_u32_e64 and the VOP2 logical and shift forms",
|
||||
));
|
||||
}
|
||||
};
|
||||
@@ -728,12 +731,6 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
match instruction.instruction {
|
||||
Instruction::MoveB32 { .. }
|
||||
| Instruction::VectorAluVop3 { .. }
|
||||
| Instruction::VectorLshlrevB32 { .. }
|
||||
| Instruction::VectorLshrrevB32 { .. }
|
||||
| Instruction::VectorAshrrevI32 { .. }
|
||||
| Instruction::VectorAndB32 { .. }
|
||||
| Instruction::VectorOrB32 { .. }
|
||||
| Instruction::VectorXorB32 { .. }
|
||||
| Instruction::VectorAddF32 { .. }
|
||||
| Instruction::VectorMulF32 { .. }
|
||||
| Instruction::VectorAlu { .. } => continue,
|
||||
@@ -851,27 +848,6 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
Op::Binary(Binary::Vector(op.lowering()), left, right),
|
||||
)
|
||||
}
|
||||
Instruction::VectorLshlrevB32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ShiftLeft, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorAshrrevI32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ArithmeticShiftRight, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorLshrrevB32 { dst, src0, src1 } => (
|
||||
Some(dst),
|
||||
Op::Binary(Binary::ShiftRight, read(src1)?, read(src0)?),
|
||||
),
|
||||
Instruction::VectorAndB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::And, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::VectorOrB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::Or, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::VectorXorB32 { dst, src0, src1 } => {
|
||||
(Some(dst), Op::Binary(Binary::Xor, read(src0)?, read(src1)?))
|
||||
}
|
||||
Instruction::ScalarMoveB32 { dst, src } => {
|
||||
let value = read_scalar(src)?;
|
||||
if dst < 8 {
|
||||
@@ -1084,9 +1060,9 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
};
|
||||
let value_bits = match operation {
|
||||
Op::Constant(bits) => KnownBits::constant(bits),
|
||||
Op::Binary(Binary::And, left, right) => facts[left.0].and(facts[right.0]),
|
||||
Op::Binary(Binary::Or, left, right) => facts[left.0].or(facts[right.0]),
|
||||
Op::Binary(Binary::Xor, left, right) => facts[left.0].xor(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::And), left, right) => facts[left.0].and(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::Or), left, right) => facts[left.0].or(facts[right.0]),
|
||||
Op::Binary(Binary::Vector(VectorBinary::Xor), left, right) => facts[left.0].xor(facts[right.0]),
|
||||
Op::Binary(operator @ (Binary::FloatAdd | Binary::FloatMul), left, right) => {
|
||||
exact_float_result(operator, facts[left.0], facts[right.0])
|
||||
.ok_or_else(|| error("FP32 operation is not proven exact for positive normal operands and results"))?
|
||||
|
||||
@@ -31,12 +31,12 @@ acceptance remain outside the verified count. All results concern synthetic fixt
|
||||
| SOPP | 36 | 6 | 0 | 6 | 6 | 6 | 4 | 4 | 0 |
|
||||
| VINTRP | 3 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP1 | 81 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 |
|
||||
| VOP2 | 47 | 20 | 12 | 20 | 20 | 20 | 7 | 7 | 7 |
|
||||
| VOP2 | 47 | 20 | 18 | 20 | 20 | 20 | 7 | 7 | 11 |
|
||||
| VOP3 | 416 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 12 |
|
||||
| VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOPC | 190 | 16 | 16 | 16 | 16 | 16 | 0 | 0 | 7 |
|
||||
| **Total** | 1465 | 104 | 85 | 108 | 104 | 104 | 18 | 18 | 56 |
|
||||
| **Total** | 1465 | 104 | 91 | 108 | 104 | 104 | 18 | 18 | 60 |
|
||||
|
||||
## Unsupported operand variants
|
||||
|
||||
@@ -48,5 +48,6 @@ The table counts distinct variant names per family across registry operand rules
|
||||
| SOP2 | `sop2_sgpr` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc`, `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` |
|
||||
| SOPC | `sopc_scalar` | `src_exec`, `src_float_inline`, `src_m0`, `src_special`, `src_ttmp`, `src_vcc`, `two_literals` |
|
||||
| VOP2 | `vop2_vgpr` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOP2 | `vop2_vgpr2` | `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOP3 | `vop3_vgpr2` | `modifiers`, `src2`, `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOPC | `vopc_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
@@ -90,12 +90,13 @@ The root file holds:
|
||||
`guide` (the AMD RDNA 2 ISA reference guide) and `xml` (the AMD
|
||||
machine-readable ISA) are allowed, and each must match the title and file
|
||||
pinned in the generator, so a citation cannot point at another file.
|
||||
- `[operand_rules.<name>]`: an operand rule shared by a whole family. The
|
||||
decoder implements each rule once, and the generator only accepts a rule
|
||||
whose declaration matches the decoder's implementation exactly. Today there
|
||||
is one rule, `sop2_sgpr`: an SGPR destination `s0`-`s105`, two scalar sources
|
||||
- `[operand_rules.<name>]`: an operand rule of one family, shared by its forms.
|
||||
The decoder implements each rule once, and the generator only accepts a rule
|
||||
whose declaration matches the decoder's implementation exactly. A family may
|
||||
have several rules (VOP2 has `vop2_vgpr` and the VGPR-only `vop2_vgpr2`). For
|
||||
example `sop2_sgpr` is an SGPR destination `s0`-`s105`, two scalar sources
|
||||
(an SGPR, an inline integer -16 to 64, or a literal word) and at most one
|
||||
literal. Its `unsupported` list names the encodings the rule rejects, which
|
||||
literal. A rule's `unsupported` list names the encodings it rejects, which
|
||||
stay unsupported instead of being guessed. The list must name exactly the
|
||||
encodings the decoder rejects.
|
||||
|
||||
@@ -116,7 +117,7 @@ error.
|
||||
| `relation` | Compares only: the relation tested with S0 on the left | `eq`, `lg` (not equal), `gt`, `ge`, `lt`, `le`; required for `compare`, rejected elsewhere |
|
||||
| `source_order` | Vector forms only: `reversed` when the guide computes `op(S1, S0)` (the XML records no operand order); absent otherwise | `reversed` |
|
||||
| `shift_amount` | `lshl_add` only: the fixed left shift of S0 before the add | `1` to `4`; required for `lshl_add`, rejected elsewhere |
|
||||
| `shift_count_bits` | Shifts only: the low bits of S1 used as the count. The generator masks S1 with it, and the XML must list S1 as unsigned | `5` (log2 of `width`); required for shifts, rejected elsewhere |
|
||||
| `shift_count_bits` | Shifts only: the low bits of the count source used as the count: S1, or S0 for a vector form with `source_order = "reversed"`. Scalar forms mask it in the generated evaluation, vector forms in their MSL template; the XML must list the count source as unsigned | `5` (log2 of `width`); required for shifts, rejected elsewhere |
|
||||
| `scc` | What the form writes to SCC | `carry_out`, `borrow`, `signed_overflow`, `nonzero`, `relation` (SOPC compares only), `selected_src0` (min and max: S0 won the strict compare, so a tie gives 0), `unchanged` |
|
||||
| `vcc`, `exec` | Effect on VCC and EXEC, stated rather than implied | `unchanged`; `vcc` is `lane_mask` exactly for the VOPC compares (VCC_LO bit n = EXEC[n] & test, fully written; VCC_HI unknown afterwards, see [vector-compare.md](vector-compare.md)); `exec` must be `unchanged` (no EXEC-writing contract yet) |
|
||||
| `wave` | Wave sizes the form is valid in | `wave32` exactly for the VOPC compares (their one entry point is the Wave32 compute fixture ABI, vector-compare.md section 2), `any` for everything else; the decoder has no wave-size input, so no other form may claim `wave32` |
|
||||
@@ -151,7 +152,9 @@ fixes the `scc` value:
|
||||
| `lshl_add` / `unsigned` | `carry_out` | `lshl_add_carry_u32` (with `shift_amount`) | no |
|
||||
| `compare` / `signed` or `unsigned` | `relation` | `eq_b32`, `ne_b32` (for both signednesses), `gt_i32`/`gt_u32`, `ge_*`, `lt_*`, `le_*` | no |
|
||||
|
||||
Vector forms (operand rule `vop2_vgpr`, kind `vector`) use a separate table:
|
||||
Vector forms (operand rules `vop2_vgpr` and `vop2_vgpr2`, kind `vector`; both
|
||||
generate the one `VectorAluOp` enum, whose `operand_rule()` tells the decoder
|
||||
which rule a form uses) use a separate table:
|
||||
the pair picks the per-lane `VectorBinary` the MSL lowering uses, and `scc`
|
||||
must be `unchanged` (VOP2 integer forms write no SCC, VCC or EXEC):
|
||||
|
||||
@@ -161,6 +164,15 @@ must be `unchanged` (VOP2 integer forms write no SCC, VCC or EXEC):
|
||||
| `xnor` / `bitwise` | `Xnor` |
|
||||
| `min`, `max` / `signed` or `unsigned` | `MinSigned`, `MinUnsigned`, `MaxSigned`, `MaxUnsigned` |
|
||||
| `mul24`, `mul_hi24` / `signed` or `unsigned` | `Mul24Signed`, `Mul24Unsigned`, `MulHi24Signed`, `MulHi24Unsigned` |
|
||||
| `and`, `or`, `xor` / `bitwise` | `And`, `Or`, `Xor` |
|
||||
| `lshl`, `lshr` / `bitwise`, `ashr` / `signed` (with `shift_count_bits = 5`) | `ShiftLeft`, `ShiftRight`, `ArithmeticShiftRight` |
|
||||
|
||||
`vop2_vgpr2` is the VGPR-only subset (SRC0 256-511) that the hand-written decoder
|
||||
accepted for `v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`
|
||||
and `v_ashrrev_i32` before they moved into the registry (#215 M27); widening them
|
||||
to `vop2_vgpr` would be a behaviour change and needs its own oracle. The three
|
||||
shifts declare `source_order = "reversed"` (D = S1 shifted by S0[4:0]), so the
|
||||
generator checks the XML's unsigned count format on SRC0, not VSRC1.
|
||||
|
||||
VOPC compares (operand rule `vopc_vcc`, kind `vector_compare`: SRC0 a
|
||||
`vector_source` as for VOP2, VSRC1 a VGPR, destination implicitly `vcc_lo`)
|
||||
|
||||
@@ -371,6 +371,25 @@ class Validate(unittest.TestCase):
|
||||
def test_accepts_the_real_registry(self):
|
||||
self.assertEqual(gen.validate(gen.load_registry(), gen.load_snapshot()), [])
|
||||
|
||||
def test_a_reversed_shift_takes_its_count_from_src0(self):
|
||||
# V_ASHRREV_I32: D = S1 >> S0[4:0]; the XML gives SRC0 FMT_NUM_U32 (the
|
||||
# count) and VSRC1 FMT_NUM_I32. Without the declared reversed order the
|
||||
# count check lands on VSRC1 and must fail.
|
||||
reg = gen.load_registry()
|
||||
form = next(f for f in reg["form"] if f["name"] == "V_ASHRREV_I32")
|
||||
del form["source_order"]
|
||||
errors = gen.validate(reg, gen.load_snapshot())
|
||||
self.assertIn(
|
||||
"V_ASHRREV_I32: control operand VSRC1 has XML format FMT_NUM_I32, not FMT_NUM_U32",
|
||||
errors,
|
||||
)
|
||||
|
||||
def test_rules_sharing_an_enum_render_it_once_with_each_forms_rule(self):
|
||||
text = gen.render(gen.load_registry(), gen.load_snapshot())
|
||||
self.assertEqual(text.count("pub enum VectorAluOp {"), 1)
|
||||
self.assertIn("Self::AndB32 => OperandRule::Vop2Vgpr2,", text)
|
||||
self.assertIn("Self::MinI32 => OperandRule::Vop2Vgpr,", text)
|
||||
|
||||
# ---- top level ----
|
||||
|
||||
def test_rejects_wrong_schema(self):
|
||||
|
||||
Reference in new issue
Block a user