Skip to content

Commit

Permalink
Changing reference point of current/next rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
lvella committed Oct 26, 2023
1 parent 1bedc67 commit 883d55e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions riscv_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 },
Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 883d55e

Please sign in to comment.