# The instruction set as the Gekko implements it Sources: the Gekko user's manual (UM, IBM, v1.2, 2000-05-25; confidential, facts only), the PowerPC Programming Environments Manual for 32-bit implementations (PEM, Motorola MPCFPE32B rev 2, 2001), the 740/750 user's manual (Motorola/IBM, 1998) and the 750CL user's manual (IBM, v1.0, 2007). All DOC unless tagged otherwise. ## The three books The Gekko implements the 32-bit PowerPC architecture: the user instruction set (UISA), the virtual environment (VEA: caches, time base, `eieio`, `isync`) and the operating environment (OEA: MSR, SPRs, MMU, exceptions), as the 750 does (UM 1.5.1, 2.3). The PEM is the architecture's definition; the UM and the 740/750 manual say where the 750 family chooses within what the PEM allows, and the UM adds what the Gekko changes. The rule for the specification: the **PEM defines**, the **UM decides** wherever the PEM leaves a choice to the implementation (an "undefined" result, an optional instruction, an implementation-dependent SPR), and the UM's text wins over the 750 manual where they differ. Where the UM itself is silent, the item is an unknown (handoff-brief U-list), never silently borrowed from another implementation. Not implemented (UM 2.3.1.4-2.3.1.5): the 64-bit instructions, the optional `fsqrt[s]`, `tlbia`, the external control instructions are present but `eciwx`/`ecowx` matter only to a system with EAR (the GameCube does not use them: HYPOTHESIS). `tlbie` and `tlbsync` behave as the 750 manual says (tlbie invalidates both ways of the indexed set in both TLBs). ## Decode - 32-bit big-endian words, primary opcode in bits 0-5 (IBM bit numbering: bit 0 is the most significant). The specification uses IBM numbering in its comments and converts at one place, so that every field reads like the manual's figures. - **Gekko primary opcodes** (UM 2.3.1.5, appendix A tables A-30 to A-32): 4 (paired-single arithmetic, merges, compares, `psq_lx/lux/stx/stux` and `dcbz_l`), 56 `psq_l`, 57 `psq_lu`, 60 `psq_st`, 61 `psq_stu`. On a 750 these are illegal. - **Opcode 4's three extended-opcode widths** (from appendix A, our reading; HYPOTHESIS until rung 0's decode test runs every word against the manual's table): - a **5-bit** XO in bits 26-30 for the A-form arithmetic (`ps_div` 18, `ps_sub` 20, `ps_add` 21, `ps_sel` 23, `ps_res` 24, `ps_mul` 25, `ps_rsqrte` 26, `ps_msub` 28, `ps_madd` 29, `ps_nmsub` 30, `ps_nmadd` 31, `ps_sum0/1` 10/11, `ps_muls0/1` 12/13, `ps_madds0/1` 14/15); - a **6-bit** XO in bits 25-30 for the indexed quantized forms (`psq_lx` 6, `psq_stx` 7, `psq_lux` 38, `psq_stux` 39), with W in bit 21 and I in bits 22-24; - a **10-bit** XO in bits 21-30 for the rest (`ps_cmpu0` 0, `ps_cmpo0` 32, `ps_cmpu1` 64, `ps_cmpo1` 96, `ps_neg` 40, `ps_mr` 72, `ps_nabs` 136, `ps_abs` 264, `ps_merge00/01/10/11` 528/560/592/624, `dcbz_l` 1014). - The widths do not collide: every 10-bit value above has bits 26-30 equal to 0, 8, 16 or 22, and every 6-bit value has them equal to 6 or 7, none of which is a 5-bit XO. A decoder therefore tests the 5-bit field first, then the 6-bit, then the 10-bit. - powerpc-rs's `isa.yaml` (tier 5, a detector) encodes the same patterns, e.g. `dcbz_l` mask `0xffe007ff` pattern `0x100007ec`, `psq_lx` mask `0xfc00007f` pattern `0x1000000c`, `ps_merge00` pattern `0x10000420` (OBSERVED, pinned 4643ee0). - **The decode is generated**, as sh2-python's and vr4300-python's plans are: a script reads a transcription of the PEM's appendix A tables and the UM's tables A-30 to A-32, page cited per row, and writes `_decode.py`. The transcription is our own table of facts (mnemonic, form, fields, page), not a copy of the manual's layout. - **Illegal instructions.** "Gekko fully decodes the SPR field of the instruction" (UM 4.5.7): an `mtspr`/`mfspr` to an SPR the part does not have is an illegal-instruction program exception, not a no-op. The Gekko extensions are illegal while their enable is clear: paired singles and all quantized forms with HID2[PSE] = 0, the D-form quantized loads and stores with HID2[LSQE] = 0, `dcbz_l` with HID2[LCE] = 0 (UM 2.1.2.4, 9.2.2.2.1). - **The enable-then-invalidate rule.** "When using mtspr to set any of the three enable bits, LSQE, PSE and LCE, the i-cache must be invalidated before using any of the corresponding Gekko graphics extension instructions" (UM 2.1.2.4). This says legality is decided at a point that the I-cache can hold stale (HYPOTHESIS: predecode bits in the I-cache). The specification models legality at execute time from HID2's current value, and records the rule as unknown U3: what a program that does not invalidate actually sees. Only a hardware test would tell, and no correct program depends on it. ## Integer and system details the specification must state Each is DOC from the PEM unless the UM is cited; each becomes a rung-1 or rung-2 case. - `divw`/`divwu` by zero and `divw` of 0x80000000 by -1: the PEM leaves the quotient undefined and OV is set when OE = 1. The UM's instruction descriptions follow the PEM. The Gekko's actual quotient is unknown (U1); MAME gives one answer (tier 5, not a judge). - `mulhw`, `mulhwu`, `mullw` timing depends on the operands (UM table 6-6: early exit on small multipliers); results do not. - `lmw`, `stmw`, `lswi`, `lswx`, `stswi`, `stswx`: supported in big-endian mode; an alignment exception in little-endian mode (UM 4.5.6). - `lwarx`/`stwcx.`: one reservation, cleared by `stwcx.` and by an exception; the GameCube has one master on the 60x bus that snoops (HYPOTHESIS: Flipper issues no snoop transactions; the locked cache's "LCE shall be kept at 0 for systems which generate snoop transactions", UM 2.1.2.4, implies Nintendo's system does not). - `eieio`, `sync`, `isync`: ordering only, plus `sync`'s wait for the DMA queue when HID0[ABE] = 0 (UM 9.3.1). They have no effect on the write-gather pipe (UM 9.4.2). - `mftb` reads TBL/TBU (TBR 268/269); the time base and decrementer step at bus/4. - The UM's implementation-dependent SPRs: HID0 (1008), HID1 (1009), HID2 (920), IABR (1010), DABR (1013), L2CR (1017), ICTC (1019), THRM1-3 (1020-1022), the performance monitor's MMCR0/1, PMC1-4 and user copies (UM 2.1.2; figure 2-1). The GQRs (912-919), WPAR (921), DMAU (922), DMAL (923) are the Gekko's own. ## The floating-point unit (summary; detail in paired-singles.md) One FPU, 64 bits wide, pipelined for single precision and for most double-precision operations (UM table 6-7: `fadd`, `fmuls`, `fmadds` 1-1-1; `fmul`, `fmadd` 2-1-1; `fdivs` 17 cycles and `fdiv` 31, not pipelined). `fsqrt` is absent; `fres` and `frsqrte` give estimates whose exact bit patterns the PEM does not define (U5). FPSCR[NI] (bit 29) selects non-IEEE mode, in which denormals are flushed (UM 2.2.1, table 2-21).