From 27e11e67eb7ba5e6d7645081e881f01792db431b Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 13 Oct 2025 01:47:03 -0400 Subject: emux64: cpu: Seperate arithop core from add logic Signed-off-by: Ian Moffett --- emux64/src/cpu/cpu_cycle.c | 48 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'emux64/src/cpu') diff --git a/emux64/src/cpu/cpu_cycle.c b/emux64/src/cpu/cpu_cycle.c index cdbf87f..b3a8987 100644 --- a/emux64/src/cpu/cpu_cycle.c +++ b/emux64/src/cpu/cpu_cycle.c @@ -33,6 +33,19 @@ #include "rom.h" #include "cpu/cpu.h" +/* + * Represents arithmetic arguments + * + * @dest_reg: Destination register [R] + * @op1: Operand 1 [IMM] + * op2: Operand 2 [IMM] + */ +struct arithop { + uint8_t dest_reg; + uint64_t op1; + uint64_t op2; +}; + /* * Returns true if the register is an * X type register @@ -112,16 +125,27 @@ cpu_fetch32(struct osmx_core *core, uint64_t *res) return 0; } +/* + * Get arithmetic parameters + * + * @core: Core that is executing + * @res: Result written here + * + * Returns zero on success + */ static int -cpu_do_add(struct osmx_core *core) +cpu_arithop(struct osmx_core *core, struct arithop *res) { uint8_t dest, op1, op2; - uint64_t op1_val; uint64_t op2_val; bool op2_is_imm; bool op2_is_big; int error = 0; + if (core == NULL || res == NULL) { + return -EINVAL; + } + /* Grab the dest register */ error = cpu_fetch(core, &dest); if (error < 0) { @@ -161,8 +185,24 @@ cpu_do_add(struct osmx_core *core) return error; } - op1_val = core->xn[op1]; - core->xn[dest] = op1_val + op2_val; + res->dest_reg = dest; + res->op1 = core->xn[op1]; + res->op2 = op2_val; + return 0; +} + +static int +cpu_do_add(struct osmx_core *core) +{ + struct arithop ops; + int error; + + error = cpu_arithop(core, &ops); + if (error < 0) { + return error; + } + + core->xn[ops.dest_reg] = ops.op1 + ops.op2; return 0; } -- cgit v1.2.3