Files
Odin/core/rexcode/ppc/operands.odin
Flāvius a4f08f8307 Load rexcode encode/decode tables from committed binary blobs
Each ISA's hand-written ENCODING_TABLE (the single source of truth) now lives
in a per-arch tablegen/ metaprogram that flattens it and serializes committed
binary blobs; the library #loads those into @(rodata) at compile time rather
than compiling a table body. No arch keeps encoding_table.odin or
decoding_tables.odin -- only a generated tables.odin loader and tables/*.bin.

* Two-stage, type-checked pipeline: tablegen Stage A emits human-readable
  generated Odin, which compiles and serializes the blobs in Stage B.
* encode() goes through encoding_forms(m); decoders are unchanged apart from
  x86's flattened 2-D index. Decode tables are byte-identical to the old ones.
* build.lua: a LuaJIT driver for the metaprograms, validations, and tests,
  with cross-platform gating and a clear report.
* Docs refreshed; the obsolete forward-looking plan in cross_arch_design.md
  trimmed to what was actually built.
* Attribution headers added to all rexcode source files; the generators emit
  them so generated files keep them.
2026-06-15 07:43:29 -04:00

81 lines
2.7 KiB
Odin

// rexcode · Brendan Punsky (dotbmp@github), original author
package rexcode_ppc
// =============================================================================
// PowerPC OPERANDS
// =============================================================================
//
// Kind-tagged operand, same shape as other arches. PowerPC-specific notes:
//
// * Memory operands cover D-form (RA + signed 16-bit displacement), DS-form
// (RA + signed 14-bit displacement, scaled by 4), DQ-form (12-bit scaled
// by 16), X-form (RA + RB indexed), and prefixed (34-bit signed offset).
//
// * REGISTER operands carry a single Register; the encoder routes by
// register class (GPR/FPR/VR/VSR/CR/SPR).
//
// * IMMEDIATE i64 is wide enough for 34-bit prefixed immediates and the
// signed branch displacements.
//
// * RELATIVE = label id (pre-resolution) or signed byte offset (post).
Operand_Kind :: enum u8 {
NONE,
REGISTER,
IMMEDIATE,
MEMORY,
RELATIVE,
}
// PowerPC memory operand. Covers all D / DS / DQ / X / prefixed forms.
Memory :: struct #packed {
base: Register, // RA — base register (R0 may be literal zero in D-form)
index: Register, // RB for X-form indexed; NONE for D/DS/DQ-form
disp: i64, // signed displacement (16/14/12 or 34-bit prefixed)
}
#assert(size_of(Memory) == 12)
@(require_results)
mem_d :: #force_inline proc "contextless" (base: Register, disp: i64) -> Memory {
return Memory{base = base, index = NONE, disp = disp}
}
@(require_results)
mem_x :: #force_inline proc "contextless" (base, index: Register) -> Memory {
return Memory{base = base, index = index, disp = 0}
}
Operand :: struct #packed {
using _: struct #raw_union {
reg: Register,
mem: Memory,
immediate: i64,
relative: i64, // label id (pre) or signed byte offset (post)
},
kind: Operand_Kind,
size: u8, // operand size in bytes (4 = word, 8 = dword)
_: [2]u8,
}
// raw_union size = max(2, 12, 8, 8) = 12; + 1 kind + 1 size + 2 pad = 16 bytes
@(require_results)
op_reg :: #force_inline proc "contextless" (r: Register) -> Operand {
return Operand{reg = r, kind = .REGISTER}
}
@(require_results)
op_imm :: #force_inline proc "contextless" (v: i64) -> Operand {
return Operand{immediate = v, kind = .IMMEDIATE}
}
@(require_results)
op_mem :: #force_inline proc "contextless" (m: Memory) -> Operand {
return Operand{mem = m, kind = .MEMORY}
}
@(require_results)
op_label :: #force_inline proc "contextless" (label_id: u32) -> Operand {
return Operand{relative = i64(label_id), kind = .RELATIVE}
}
@(require_results)
op_rel_offset :: #force_inline proc "contextless" (off: i64) -> Operand {
return Operand{relative = off, kind = .RELATIVE}
}