From 7a13dc7a5907230f05ca6edd00113d277ed1f7f4 Mon Sep 17 00:00:00 2001 From: svv232 Date: Sun, 1 Dec 2024 17:32:40 -0500 Subject: [PATCH] implementation for branch greater than equal unsigned --- .../src/interpreters/riscv32im/interpreter.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/o1vm/src/interpreters/riscv32im/interpreter.rs b/o1vm/src/interpreters/riscv32im/interpreter.rs index 0f87fc448e..63b2269eaa 100644 --- a/o1vm/src/interpreters/riscv32im/interpreter.rs +++ b/o1vm/src/interpreters/riscv32im/interpreter.rs @@ -2289,7 +2289,27 @@ pub fn interpret_sbtype(env: &mut Env, instr: SBInstruction env.set_next_instruction_pointer(addr); } SBInstruction::BranchGreaterThanEqualUnsigned => { - unimplemented!("BranchGreaterThanEqualUnsigned") + // bgeu: if (x[rs1] >=u x[rs2]) pc += sext(offset) + let local_rs1 = env.read_register(&rs1); + let local_rs2 = env.read_register(&rs2); + + let rd_scratch = env.alloc_scratch(); + let less_than = unsafe { env.test_less_than(&local_rs1, &local_rs2, rd_scratch) }; + let offset = + less_than.clone() * Env::constant(4) + (Env::constant(1) - less_than) * imm0_12; + + // greater than equal is the negation of less than + let addr = { + let res_scratch = env.alloc_scratch(); + let overflow_scratch = env.alloc_scratch(); + let (res, _overflow) = unsafe { + env.add_witness(&instruction_pointer, &offset, res_scratch, overflow_scratch) + }; + res + }; + + env.set_instruction_pointer(next_instruction_pointer); + env.set_next_instruction_pointer(addr); } }; }