Files
Odin/core/rexcode/isa/rsp/operands.odin
Brendan Punsky 95df04fbe1 rexcode: re-house ISA packages under core:rexcode/isa/<arch>
Move all ten ISA packages (x86, arm32, arm64, mips, riscv, ppc, ppc_vle,
rsp, mos6502, mos65816) from core/rexcode/<arch> to core/rexcode/isa/<arch>,
so the import pattern is now `import "core:rexcode/isa/x86"`. The shared
core stays at core:rexcode/isa.

Mechanical: relative `import "../isa"` / "../../isa" -> absolute
"core:rexcode/isa" (the only path that survives the move; the "../" and
"../.." self/generated imports move with their packages). build.lua now
builds paths as <root>/isa/<name>; stale `cd <arch>` hints in the verify
tools and the doc.odin paths updated.

WASM stays at core/rexcode/wasm for now -- it is an IR, not an ISA, and
will move under the forthcoming core:rexcode/ir once that layer lands.

All 10 arches gen/builders/check/test green; import core:rexcode/isa/x86
verified working; wasm still compiles.
2026-06-18 19:03:27 -04:00

93 lines
2.7 KiB
Odin

// rexcode · Brendan Punsky (dotbmp@github), original author
package rexcode_rsp
// =============================================================================
// RSP OPERANDS
// =============================================================================
//
// Same shape as mips/operands.odin; the addition for the RSP is that
// vector operands carry an element selector. Memory comes in two
// flavours: scalar (base + 16-bit signed disp; standard MIPS) and
// vector (base + 7-bit element-scaled offset + element selector).
Operand_Kind :: enum u8 {
NONE,
REGISTER,
VECTOR_REG, // vector register with element selector
MEMORY,
VECTOR_MEM, // vector memory: base + 7-bit offset + element selector
IMMEDIATE,
RELATIVE,
}
Memory :: struct #packed {
base: Register, // GPR base
_: u16,
disp: i32,
}
#assert(size_of(Memory) == 8)
Vector_Mem :: struct #packed {
base: Register, // GPR base
element: u8, // element selector (0-15; restricted by op)
_: u8,
offset: i32, // -64..63 after element-size scaling
}
#assert(size_of(Vector_Mem) == 8)
@(require_results)
mem :: #force_inline proc "contextless" (base: Register, disp: i32) -> Memory {
return Memory{base = base, disp = disp}
}
@(require_results)
vmem :: #force_inline proc "contextless" (base: Register, element: u8, offset: i32) -> Vector_Mem {
return Vector_Mem{base = base, element = element, offset = offset}
}
Operand :: struct #packed {
using _: struct #raw_union {
reg: Register, // for REGISTER and VECTOR_REG
mem: Memory,
vmem: Vector_Mem,
immediate: i64,
relative: i64,
},
kind: Operand_Kind, // 1 byte
size: u8, // 1 byte
element: u8, // 1 byte — for VECTOR_REG
_: [1]u8,
}
#assert(size_of(Operand) == 12)
@(require_results)
op_reg :: #force_inline proc "contextless" (r: Register) -> Operand {
return Operand{reg = r, kind = .REGISTER, size = 4}
}
@(require_results)
op_vr :: #force_inline proc "contextless" (r: Register, element: u8 = 0) -> Operand {
return Operand{reg = r, kind = .VECTOR_REG, size = 16, element = element}
}
@(require_results)
op_mem :: #force_inline proc "contextless" (m: Memory, size: u8) -> Operand {
return Operand{mem = m, kind = .MEMORY, size = size}
}
@(require_results)
op_vmem :: #force_inline proc "contextless" (m: Vector_Mem, size: u8) -> Operand {
return Operand{vmem = m, kind = .VECTOR_MEM, size = size}
}
@(require_results)
op_imm :: #force_inline proc "contextless" (v: i64, size: u8) -> Operand {
return Operand{immediate = v, kind = .IMMEDIATE, size = size}
}
@(require_results)
op_label :: #force_inline proc "contextless" (label_id: u32) -> Operand {
return Operand{relative = i64(label_id), kind = .RELATIVE, size = 4}
}