Skip to content

Commit

Permalink
Merge pull request #2861 from o1-labs/sai/branch-gteu
Browse files Browse the repository at this point in the history
implementation for branch greater than equal unsigned
  • Loading branch information
svv232 authored Dec 24, 2024
2 parents 5b63f23 + e452a67 commit 997b51b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion o1vm/src/interpreters/riscv32im/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,27 @@ pub fn interpret_sbtype<Env: InterpreterEnv>(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);
}
};
}
Expand Down

0 comments on commit 997b51b

Please sign in to comment.