PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
vsm_diff Namespace Reference

Functions

str _normalize_mnemonic (str tok)
 
str _extract_flag (str tok)
 
bool _is_mnemonic_token (str tok)
 
 parse_vsm (str path)
 
 _diff_counters (Counter a, Counter b)
 
int main (argv)
 

Variables

tuple _DIRECTIVE_PREFIXES = (".vu", ".align", ".global", ".name", ".end")
 
 _COMMENT_RE = re.compile(r"^\s*;.*")
 
 _LABEL_RE = re.compile(r"^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?:;.*)?$")
 
 _PIPE_SPLIT_RE = re.compile(r"\s{15,}")
 
 _FLAG_RE = re.compile(r"^([a-z0-9.]+?)(\[[A-Za-z]+\])?$")
 

Detailed Description

Compare two VU1 .vsm files at the semantic level.

Used as a CTest target in ps2gl to verify that openvcl produces the same
*set* of operations as Sony's proprietary vcl for each VU1 renderer.
Differences in pipe-pairing, register-allocator choices, and whitespace
are intentionally ignored -- the goal is to surface real divergences
(missing instructions, wrong opcodes, missing labels) and to track how
close openvcl is getting to the reference as the dual-pipe scheduler
matures.

Usage:
  vsm_diff.py <reference.vsm> <openvcl.vsm>

Exit codes:
  0 = histograms and labels match.
  1 = real divergence (different opcode set, different label set).
  2 = file read / parse error.

The script is intentionally permissive about pipe placement: only the
opcode mix matters.  A separate "instruction-count delta" line is printed
to track scheduler progress over time.

Function Documentation

◆ _normalize_mnemonic()

str vsm_diff._normalize_mnemonic ( str tok)
protected
Lowercase the mnemonic and strip any [E]/[I]/[D]/[T] flag suffix.

Keep dest fields (`.xyz`, `.w`) attached to the mnemonic so we can
distinguish `addi.xy` from `addi.xyz` -- they're semantically
different operations on different fields.

Definition at line 58 of file vsm_diff.py.

Referenced by parse_vsm().

◆ _extract_flag()

str vsm_diff._extract_flag ( str tok)
protected
Return the flag suffix (e.g. "[E]") if present, else "".

Definition at line 69 of file vsm_diff.py.

Referenced by parse_vsm().

◆ _is_mnemonic_token()

bool vsm_diff._is_mnemonic_token ( str tok)
protected
True iff `tok` looks like a VU1 mnemonic (as opposed to a register
or immediate operand).

Sony's reference output uses uppercase mnemonics with comma-joined
operands and no space between them; openvcl's output uses lowercase
mnemonics with space-separated operands.  A consistent classifier
over both is to bucket each whitespace-separated token by what it
looks like:

  mnemonic:  starts with a letter, is not a register name
  register:  V[FI]<digit>... or ACC[component] or single-letter I/Q/P/R
  immediate: starts with a digit (incl. 0x...)
  indirect:  contains '(' (e.g. 62(VI00))
  label-ref: trailing ':' -- handled before this function gets called

Definition at line 75 of file vsm_diff.py.

Referenced by parse_vsm().

◆ parse_vsm()

vsm_diff.parse_vsm ( str path)
Return (opcode_histogram, flag_histogram, label_set, instr_count).

instr_count is the total number of pipe slots filled with anything
other than `nop` -- a rough "work-per-cycle" signal for the scheduler.

Definition at line 116 of file vsm_diff.py.

References _extract_flag(), _is_mnemonic_token(), and _normalize_mnemonic().

Referenced by _diff_counters().

◆ _diff_counters()

vsm_diff._diff_counters ( Counter a,
Counter b )
protected
Return dict {key: (a, b)} for keys where a and b disagree.

Definition at line 167 of file vsm_diff.py.

References _diff_counters(), and parse_vsm().

Referenced by _diff_counters().

◆ main()

int vsm_diff.main ( argv)

Definition at line 176 of file vsm_diff.py.

Variable Documentation

◆ _DIRECTIVE_PREFIXES

tuple vsm_diff._DIRECTIVE_PREFIXES = (".vu", ".align", ".global", ".name", ".end")
protected

Definition at line 31 of file vsm_diff.py.

◆ _COMMENT_RE

vsm_diff._COMMENT_RE = re.compile(r"^\s*;.*")
protected

Definition at line 38 of file vsm_diff.py.

◆ _LABEL_RE

vsm_diff._LABEL_RE = re.compile(r"^\s*([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(?:;.*)?$")
protected

Definition at line 41 of file vsm_diff.py.

◆ _PIPE_SPLIT_RE

vsm_diff._PIPE_SPLIT_RE = re.compile(r"\s{15,}")
protected

Definition at line 50 of file vsm_diff.py.

◆ _FLAG_RE

vsm_diff._FLAG_RE = re.compile(r"^([a-z0-9.]+?)(\[[A-Za-z]+\])?$")
protected

Definition at line 55 of file vsm_diff.py.