Skip to content

Commit 91e34d5

Browse files
authored
fix: update the ctx.instret_left in E1 from the register (#2276)
1 parent 6ff454e commit 91e34d5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

crates/vm/src/arch/aot/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use openvm_stark_backend::p3_field::PrimeField32;
77
use crate::{
88
arch::{
99
aot::common::{sync_gpr_to_xmm, sync_xmm_to_gpr, REG_AS2_PTR},
10+
execution_mode::ExecutionCtx,
1011
interpreter::{AlignedBuf, PreComputeInstruction},
1112
ExecutionCtxTrait, StaticProgramError, Streams, SystemConfig, VmExecState, VmState,
1213
},
@@ -300,6 +301,12 @@ unsafe extern "C" fn set_pc_shim<F, Ctx: ExecutionCtxTrait>(state_ptr: *mut c_vo
300301
state.vm_state.set_pc(pc);
301302
}
302303

304+
// only needed for pure execution
305+
unsafe extern "C" fn set_instret_left_shim<F>(state_ptr: *mut c_void, instret_left: u64) {
306+
let state = &mut *(state_ptr as *mut VmExecState<F, GuestMemory, ExecutionCtx>);
307+
state.ctx.instret_left = instret_left;
308+
}
309+
303310
pub(crate) extern "C" fn extern_handler<F, Ctx: ExecutionCtxTrait, const E1: bool>(
304311
state_ptr: *mut c_void,
305312
pre_compute_insns_ptr: *const c_void,

crates/vm/src/arch/aot/pure.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use openvm_stark_backend::p3_field::PrimeField32;
66
use super::{common::*, AotInstance, AsmRunFn};
77
use crate::{
88
arch::{
9-
aot::{asm_to_lib, extern_handler, get_vm_address_space_addr, get_vm_pc_ptr, set_pc_shim},
9+
aot::{
10+
asm_to_lib, extern_handler, get_vm_address_space_addr, get_vm_pc_ptr,
11+
set_instret_left_shim, set_pc_shim,
12+
},
1013
execution_mode::ExecutionCtx,
1114
interpreter::{
1215
alloc_pre_compute_buf, get_pre_compute_instructions, get_pre_compute_max_size,
@@ -112,6 +115,7 @@ where
112115
format!("{:p}", extern_handler::<F, ExecutionCtx, true> as *const ());
113116
let set_pc_ptr = format!("{:p}", set_pc_shim::<F, ExecutionCtx> as *const ());
114117
let pre_compute_insns_ptr = format!("{:p}", pre_compute_insns_ptr as *const ());
118+
let instret_left_ptr = format!("{:p}", set_instret_left_shim::<F> as *const ());
115119

116120
for (pc, instruction, _) in exe.program.enumerate_by_pc() {
117121
/* Preprocessing step, to check if we should suspend or not */
@@ -129,6 +133,11 @@ where
129133
asm_str += &Self::push_address_space_start();
130134
asm_str += &Self::push_internal_registers();
131135

136+
asm_str += &format!(" mov {REG_FIRST_ARG}, {REG_EXEC_STATE_PTR}\n");
137+
asm_str += &format!(" mov {REG_SECOND_ARG}, {REG_INSTRET_END}\n");
138+
asm_str += &format!(" mov {REG_D}, {instret_left_ptr}\n");
139+
asm_str += &format!(" call {REG_D}\n");
140+
132141
asm_str += &format!(" mov {REG_FIRST_ARG}, {REG_EXEC_STATE_PTR}\n");
133142
asm_str += &format!(" mov {REG_SECOND_ARG}, {pre_compute_insns_ptr}\n");
134143
asm_str += &format!(" mov {REG_THIRD_ARG}, {pc}\n");
@@ -199,6 +208,10 @@ where
199208
// asm_run_end part
200209
for (pc, _instruction, _) in exe.program.enumerate_by_pc() {
201210
asm_str += &format!("asm_run_end_{pc}:\n");
211+
asm_str += &format!(" mov {REG_FIRST_ARG}, {REG_EXEC_STATE_PTR}\n");
212+
asm_str += &format!(" mov {REG_SECOND_ARG}, {REG_INSTRET_END}\n");
213+
asm_str += &format!(" mov {REG_D}, {instret_left_ptr}\n");
214+
asm_str += &format!(" call {REG_D}\n");
202215
asm_str += &Self::xmm_to_rv32_regs();
203216
asm_str += &format!(" mov {REG_FIRST_ARG}, rbx\n");
204217
asm_str += &format!(" mov {REG_SECOND_ARG}, {pc}\n");

0 commit comments

Comments
 (0)