diff --git a/riscv_executor/src/lib.rs b/riscv_executor/src/lib.rs index f15a46cb38..32b202708c 100644 --- a/riscv_executor/src/lib.rs +++ b/riscv_executor/src/lib.rs @@ -82,9 +82,9 @@ mod builder { pub struct TraceBuilder<'a, 'b> { trace: ExecutionTrace<'a>, - /// First register of current row. - /// Next row is reg_map.len() elems ahead. - curr_idx: usize, + /// First register of next row. + /// Curr row is reg_map.len() elems behind. + next_idx: usize, // index of special case registers to look after: x0_idx: usize, @@ -112,7 +112,7 @@ mod builder { let values = vec![Elem::zero(); 2 * reg_map.len()]; let mut ret = Self { - curr_idx: 0, + next_idx: reg_map.len(), x0_idx: reg_map["x0"], pc_idx: reg_map["pc"], trace: ExecutionTrace { reg_map, values }, @@ -132,7 +132,8 @@ mod builder { /// get current value of register by register index instead of name fn g_idx(&self, idx: usize) -> Elem { - self.trace.values[self.curr_idx + idx] + let final_idx = self.next_idx - self.reg_len() + idx; + self.trace.values[final_idx] } /// set next value of register, accounting to x0 or pc writes @@ -154,15 +155,14 @@ mod builder { /// raw set next value of register by register index instead of name fn s_idx(&mut self, idx: usize, value: Elem) { - let final_idx = self.curr_idx + self.reg_len() + idx; - self.trace.values[final_idx] = value; + self.trace.values[self.next_idx + idx] = value; } /// advance to next row, returns the index to the statement that must be /// executed now pub fn advance(&mut self) -> u32 { - self.curr_idx += self.reg_len(); - self.trace.values.extend_from_within(self.curr_idx..); + self.trace.values.extend_from_within(self.next_idx..); + self.next_idx += self.reg_len(); // advance the next statement let curr_line = self.next_statement_line;