Files
xenia-rs/migration/project-root/ppc-manual/alu/addis.md
MechaCat02 e6d43a23ac chore: add migration/ bundle for cross-machine setup
Bundles state that lives OUTSIDE the xenia-rs repo so a fresh clone on
another machine can be brought up to identical configuration via
migration/setup.sh:

  - claude-memory/             ~/.claude/projects/-home-fabi-RE-Project-Sylpheed/memory/
                               (103 files, 1.1 MB - MEMORY.md + every
                                project_xenia_rs_*.md from audits
                                addis_signext through audit-058)
  - project-root/dot-claude/   <project-root>/.claude/settings.json
                               (Stop hook + permissions)
  - project-root/ppc-manual/   <project-root>/ppc-manual/
                               (PowerPC reference docs, 397 files, 3.7 MB)
  - project-root/run-canary.sh <project-root>/run-canary.sh
  - README.md                  Human-readable setup checklist
  - setup.sh                   Idempotent installer (also reclones
                               xenia-canary at pinned HEAD 6de80dffe)
  - MANIFEST.md                Per-file mapping + per-file-not-bundled
                               restoration recipe

Excluded from bundle (not shippable via git):
  - Sylpheed ISO (7.8 GB; copyright; manual copy required)
  - sylpheed.db (395 MB; regenerable from XEX via analysis tooling)
  - target/ build artifacts (rebuild on target)
  - audit-runs probe firehoses (.log/.stdout/.stderr ~11 GB; rerun if needed)
  - audit-runs memory dumps (.bin ~4.5 GB; rerun audit-026/027/029 if needed)
  - xenia-canary checkout (setup.sh reclones from
    git.mc02.dev/fabi/Xenia-Canary.git at HEAD 6de80dffe)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 21:38:38 +02:00

5.2 KiB
Raw Blame History

addis — Add Immediate Shifted

Category: Integer ALU · Form: D · Opcode: 0x3c000000

Assembler Mnemonics

Mnemonic XML entry Flags Description
addis addis Add Immediate Shifted

Syntax

addis [RD], [RA0], [SIMM]

Encoding

addis — form D

  • Opcode word: 0x3c000000
  • Primary opcode (bits 05): 15
  • Extended opcode:
  • Synchronising: no
Bits Field Meaning
05 OPCD primary opcode
610 RT destination GPR (or RS when storing)
1115 RA source GPR (0 ⇒ literal 0 for RA0 forms)
1631 D/SI/UI 16-bit signed or unsigned immediate

Operands

Field Role Description
RA0 addis: read Source GPR; when the encoded register number is 0 the operand is the literal 64-bit zero, not r0.
SIMM addis: read 16-bit signed immediate. Sign-extended to 64 bits before use.
RD addis: write Destination GPR.

Register Effects

addis

  • Reads (always): RA0, SIMM
  • Reads (conditional): none
  • Writes (always): RD
  • Writes (conditional): none

Status-Register Effects

No condition-register or status-register effects.

Operation (pseudocode)

if RA = 0 then RT <- EXTS(SIMM) << 16
else             RT <- (RA) + (EXTS(SIMM) << 16)

C Translation Example

/* addis RT, RA, SIMM  — RA=0 means literal 0                     */
uint64_t base = (insn.RA == 0) ? 0 : r[insn.RA];
r[insn.RT] = base + ((uint64_t)(int64_t)(int16_t)insn.SIMM << 16);

Implementation References

addis

xenia-rs interpreter body (frozen snapshot)
        PpcOpcode::addis => {
            // Xbox 360 user mode is 32-bit ABI (MSR.SF=0), so addis must
            // produce a value whose upper 32 bits don't pollute downstream
            // 64-bit arithmetic. The PPC ISA in 64-bit mode sign-extends
            // simm16 before the shift, producing 0xFFFFFFFF_xxxx0000 for
            // negative simm16 (high bit set). When this value flows into
            // a 64-bit subfc against a zero-extended lwz value, the unsigned
            // 64-bit comparison yields wrong CA. Truncate to 32 bits to
            // simulate 32-bit ABI behavior.
            let ra_val = if instr.ra() == 0 { 0u64 } else { ctx.gpr[instr.ra()] };
            let result = ra_val.wrapping_add((instr.simm16() as i64 as u64) << 16);
            ctx.gpr[instr.rd()] = result as u32 as u64;
            ctx.pc += 4;
        }

Special Cases & Edge Conditions

  • RA0 semantics. When the RA field encodes 0, the operand is the literal 64-bit zero, not r0. This makes addis RT, 0, hi16 the canonical "load high half" idiom. To use r0's actual value as a base, copy it via mr first or use a different opcode.
  • Immediate is sign-extended then shifted left 16. So addis r3, 0, 0x8000 writes 0xFFFFFFFF80000000, not 0x000000008000_0000. The 32-bit sign extension surprise is the most common bug in hand-written PPC assembly.
  • Forms the high half of a 32-bit immediate. The classic lis rT, hi; ori rT, rT, lo (or lis/addi) sequence builds a full 32-bit constant. lis rT, val is a simplified mnemonic for addis rT, 0, val.
  • No XER[CA], no XER[OV], no Rc. This instruction has no status side-effects whatsoever. Use addic or addcx if a carry is required.
  • 64-bit RA operand. The shift-and-add is 64-bit on the Xenon; the immediate's sign-extension fills the high 48 bits. So addis r3, r4, -1 adds 0xFFFFFFFFFFFF0000 to a 64-bit r4.
  • No overflow detection. lis r3, 0x7FFF; addis r3, r3, 0x7FFF happily wraps without comment.
  • addi — D-form add immediate, no shift; same RA0 rule.
  • addic, addicx — immediate adds that also write XER[CA].
  • oris, ori — pair with addis/lis to build 32-bit constants without affecting CR or XER.
  • addx, addcx — XO-form register adds.
  • lis (simplified) — assembler shorthand for addis RT, 0, value.

IBM Reference