Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor debug iterator #757

Open
Tracked by #866 ...
vlopes11 opened this issue Mar 7, 2023 · 0 comments
Open
Tracked by #866 ...

Refactor debug iterator #757

vlopes11 opened this issue Mar 7, 2023 · 0 comments
Labels
good first issue Good for newcomers
Milestone

Comments

@vlopes11
Copy link
Contributor

vlopes11 commented Mar 7, 2023

This code is not prepared for backward step as it assumes the clock always increases in order to reposition the decorator index

/// Returns the asm op info corresponding to this vm state and whether this is the start of
/// operation sequence corresponding to current assembly instruction.
fn get_asmop(&self) -> (Option<AsmOpInfo>, bool) {
let assembly_ops = self.decoder.debug_info().assembly_ops();
if self.clk == 0 || assembly_ops.is_empty() || self.asmop_idx > assembly_ops.len() {
return (None, false);
}
// keeps track of the next assembly op in the list. It's the same as the current asmop
// when the current asmop is last in the list
let next_asmop = if self.asmop_idx < assembly_ops.len() {
&assembly_ops[self.asmop_idx]
} else {
&assembly_ops[self.asmop_idx - 1]
};
// keeps track of the current assembly op in the list. It's the same as the next asmop
// when the clock cycle is less than the clock cycle of the first asmop.
let (curr_asmop, cycle_idx) = if self.asmop_idx > 0 {
(
&assembly_ops[self.asmop_idx - 1],
// difference between current clock cycle and start clock cycle of the current asmop
(self.clk - assembly_ops[self.asmop_idx - 1].0 as u32) as u8,
)
} else {
(next_asmop, 0) //dummy value, never used.
};
// if this is the first op in the sequence corresponding to the next asmop, returns a new
// instance of [AsmOp] instantiated with next asmop, num_cycles and cycle_idx of 1.
if next_asmop.0 as u32 == self.clk - 1 {
let asmop = Some(AsmOpInfo::new(
next_asmop.1.op().clone(),
next_asmop.1.num_cycles(),
1, // cycle_idx starts at 1 instead of 0 to remove ambiguity
));
(asmop, true)
}
// if this is not the first asmop in the list and if this op is part of current asmop,
// returns a new instance of [AsmOp] instantiated with current asmop, num_cycles and
// cycle_idx of current op.
else if self.asmop_idx > 0 && cycle_idx <= curr_asmop.1.num_cycles() {
let asmop = Some(AsmOpInfo::new(
curr_asmop.1.op().clone(),
curr_asmop.1.num_cycles(),
cycle_idx, /* diff between curr clock cycle and start clock cycle of the current asmop */
));
(asmop, false)
}
// if the next asmop is the first in the list and is at a greater than current clock cycle
// or if the current op is not a part of any asmop, return None.
else {
(None, false)
}
}

It should be simplified to point the asmop_idx to the right decorator, regardless of the direction.

The final implementation should be as simple/succinct as possible.

The outcome of this issue should probably simplify the DebugInfo struct to not have a complex relationship between decorators and operations. Right now, we have the operations, that will increase one per clock tick, and the decorators, that will be a tuple (clock, AsmOp). One alternative is to have a wrapper struct that will bind all of the three together with any eventual metadata we might need.

The debugger expects a max number of cycles related to a given instruction, and that is computed manually during the iteration cycles. Instead, it should probably be precomputed when the debug info is generated - the iterator should just consume the information that was compute, not have logic of its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants