# The instruction set Sources, in the order they are trusted for each question (validation.md): pspautotests' `.expected` outputs recorded on real PSPs (TEST ROM, tier 3) > the MIPS32 manuals for the semantics of shared instructions (DOC, tier 2: MD00086 rev 2.50 for Release 2, rev 0.95 for Release 1) > the VFPU documentation's Allegrex chapter and YAPSPD 4.6-4.9 (DOC, community) > ghidra-allegrex's Sleigh description (tier 5: a disassembler's reading). Nothing here is from PPSSPP, JPCSP or binutils' Allegrex patches (GPL, closed). ## Encoding Every instruction is one 32-bit little-endian word, aligned. The MIPS I-, J- and R-type formats (YAPSPD 4.6). The primary opcode (bits 31-26) selects the row; SPECIAL (0x00), REGIMM (0x01), COP0 (0x10), COP1 (0x11), COP2 (0x12), SPECIAL2 (0x1C), SPECIAL3 (0x1F) and the VFPU's own primary opcodes (0x18-0x1B, 0x32, 0x34-0x37, 0x3A, 0x3C-0x3F: vfpu-docs encoding figures) are tables. ## The integer set, by origin | Group | Instructions | Encoding | Evidence | | --- | --- | --- | --- | | MIPS I/II integer | ADD(U), SUB(U), AND, OR, XOR, NOR, SLT(U), ADDI(U), SLTI(U), ANDI, ORI, XORI, LUI, SLL, SRL, SRA, SLLV, SRLV, SRAV, MULT(U), DIV(U), MFHI/MTHI/MFLO/MTLO, J, JAL, JR, JALR, BEQ, BNE, BLEZ, BGTZ, BLTZ, BGEZ, BLTZAL, BGEZAL, loads and stores incl. LWL/LWR/SWL/SWR, SYSCALL, BREAK, SYNC | MIPS | DOC (MD00086); pspautotests `cpu_alu`, `lsu`, `delayslot/branch` (TEST ROM) | | MIPS II additions | BEQL, BNEL, BLEZL, BGTZL, BLTZL, BGEZL, BLTZALL, BGEZALL, LL, SC, CACHE | MIPS | DOC; `delayslot/branch` (likely branches nullify), `lsu/llsc`, `lsu/cacheop` | | MIPS IV / MIPS32 | MOVZ, MOVN | SPECIAL 0x0A/0x0B, as MIPS32 | DOC (vfpu-docs "Arithmetic-Logical instructions") | | MIPS32 R2, **same encodings** | EXT (SPECIAL3 fn 0), INS (fn 4), SEB, SEH, WSBH (SPECIAL3 fn 0x20 BSHFL, sa 0x10/0x18/0x02), ROTR (SRL with bit 21), ROTRV (SRLV with bit 6) | MIPS32 R2 | DOC (MD00086 2.50 marks each "Release 2 Only"; vfpu-docs) | | MIPS32, **different encodings** | CLZ (SPECIAL fn 0x16), CLO (fn 0x17), MADD (fn 0x1C), MADDU (0x1D), MSUB (0x2E), MSUBU (0x2F) | SPECIAL, not MIPS32's SPECIAL2 | DOC (vfpu-docs: "uses some unused SPECIAL encodings"); Sleigh `clz fct=22`, `madd fct=28` (tier 5) | | Sony's | MAX (SPECIAL fn 0x2C), MIN (0x2D), WSBW (BSHFL sa 0x03), BITREV (BSHFL sa 0x14) | | DOC (vfpu-docs); `allegrex_encodings` (TEST ROM) | | Sony's, SPECIAL2 (0x1C) | HALT (fn 0x00), MFIC (fn 0x24), MTIC (fn 0x26) | MIPS32's MUL/MADD/CLZ space | DOC (YAPSPD 4.8: HALT "used in the idle-thread of the kernel"; MFIC/MTIC save/restore the interrupt enable) | | Traps | TEQ, TNE, TGE(U), TLT(U) and the immediate forms | MIPS | **unknown on the part** (U3): the Sleigh lists them (inherited from Ghidra's MIPS module); no PSP test exercises them | | COP0 | MFC0, MTC0, CFC0, CTC0, ERET, (DERET?) | | DOC (YAPSPD 4.3: both mfc0 *and* cfc0 register spaces exist); `cop0/eret` (TEST ROM) | **Not on the part** (to be confirmed, U2): MIPS32's MUL (SPECIAL2 fn 2), the TLB instructions (no TLB; the Sleigh marks TLBR/TLBWI/TLBWR `unimpl`), WAIT, DI/EI, RDHWR, SYNCI, RDPGPR/WRPGPR, SDBBP, every 64-bit (D-) instruction, COP1's double and paired formats, COP3. Each is a row in the decode table that raises Reserved Instruction until a judge says otherwise (decision A6, provisional). ## Hardware facts from the tests (TEST ROM, tier 3) - **BSHFL is partly decoded.** `cpu/cpu_alu/allegrex_encodings.expected` runs SPECIAL3 function 0x20 with every `sa` value 0x00-0x1F and `rs` = 0 or 31. The results depend only on `sa` and never on `rs`: 0x00-0x0F alternate WSBH/WSBW on `sa` bit 0; 0x10-0x13 give SEB; 0x14-0x17 and 0x1C-0x1F give BITREV; 0x18-0x1B give SEH. Function 0x18 leaves the destination unchanged for every `sa` (the test's sentinel `deadbeef`). So the decode is `sa` bits 4, 3, 2 and 0, with `rs` ignored, and the Sleigh's `fct=32 | fct=24` alias is wrong for 0x18 (contradiction C3). - **Delay slots and likely branches**: `cpu/delayslot/branch.expected` tabulates a branch in the delay slot of every kind of branch and jump (J, JAL, JR, JALR, BEQ..BGEZALL, BC1T/F(L), BVT/F(L)), with which targets ran and the final `ra`. This is the judge for the "branch in a delay slot" behaviour that MIPS calls UNPREDICTABLE. - **Unaligned jump targets**: `cpu/jump/unaligned`. - **ERET**: `cpu/cop0/eret.expected`: with EXL set ERET returns to EPC and clears EXL; with ERL set it returns to ErrorEPC and clears ERL; with both, it returns to ErrorEPC and leaves EXL set; in every case "next instruction skipped" (ERET has no delay slot, as MIPS32). - **Cache operations**: `cpu/lsu/cacheop.expected` (Hit Writeback 0x1A, Hit Invalidate 0x19, Hit Writeback Invalidate 0x1B; 16-word line granularity; operations on an uncached alias). The PSP's CACHE op numbers differ from MIPS32's table (C5; cop0-and-caches.md). ## Semantics notes for the handler writer - Integer overflow on ADD/ADDI/SUB raises Overflow, as MIPS (DOC; `cpu_alu` covers it). - MULT/MULTU/MADD/MSUB write HI/LO; DIV by zero results: `cpu/cpu_alu/cpu_div.expected` (U4: the values are in the file; the rule behind them is to be read from them at rung 1). - MIN/MAX are signed (vfpu-docs). CLZ/CLO as MIPS32. - Loads are interlocked: no load-delay slot (MIPS II onwards). The latency still exists: the timing model charges it (timing in cop0-and-caches.md). - LL/SC: `lsu/llsc.expected` shows the cases that clear the link (U6: whether an exception or an ERET clears LLbit on this part). ## The VFPU's instructions 269 instruction forms (counted from the VFPU documentation's headings, 2026-11-26): see vfpu.md. They share the main decoder: the board's ME instance decodes them as Coprocessor Unusable or Reserved Instruction (U11: which).