Audit Finding
Severity: Medium
File(s): opcodes.py (ICMP definition), VM execution engine
Problem
The ICMP (Integer Compare) instruction always writes its result to register R0, regardless of the operands:
# Current behavior (simplified):
def execute_icmp(rs1, rs2):
if REGS[rs1] < REGS[rs2]:
REGS[0] = 0x01 # always writes to R0
...
This means:
- You cannot use ICMP results in general computation without clobbering R0
- Chained comparisons are impossible without saving/restoring R0
- It violates the RISC principle that most ALU ops should support a destination register
Impact
- Any compiler or hand-written code that needs to compare values while preserving R0 will produce incorrect results
- Makes register allocation significantly harder for any FLUX compiler
Suggested Fix
Redesign ICMP to use a 3-register format (like ADD/SUB):
ICMP rd, rs1, rs2 ; rd = compare(rs1, rs2) → result flags in rd
If backward compatibility is required, introduce ICMP3 as the new variant and deprecate the old ICMP.
Alternatively, if the intent is to set global flags (like x86 FLAGS register), document this explicitly and provide a mechanism to read flags into an arbitrary register.
Audit Finding
Severity: Medium
File(s):
opcodes.py(ICMP definition), VM execution engineProblem
The ICMP (Integer Compare) instruction always writes its result to register R0, regardless of the operands:
This means:
Impact
Suggested Fix
Redesign ICMP to use a 3-register format (like ADD/SUB):
If backward compatibility is required, introduce ICMP3 as the new variant and deprecate the old ICMP.
Alternatively, if the intent is to set global flags (like x86 FLAGS register), document this explicitly and provide a mechanism to read flags into an arbitrary register.