Skip to content

Commit

Permalink
par stuff (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclecticGriffin authored May 16, 2024
1 parent 3db8a0c commit 9f55a12
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
32 changes: 31 additions & 1 deletion interp/src/flatten/structures/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ impl<'a> Simulator<'a> {
// program counter as the size
let mut leaf_nodes = vec![];

let mut par_map = std::mem::take(self.env.pc.par_map_mut());
let mut new_nodes = vec![];

self.env.pc.vec_mut().retain_mut(|node| {
// just considering a single node case for the moment
match &self.env.ctx.primary[node.control_node_idx] {
Expand All @@ -590,7 +593,29 @@ impl<'a> Simulator<'a> {
node.mutate_into_next(self.env.ctx)
}
}
ControlNode::Par(_par) => todo!("not ready for par yet"),
ControlNode::Par(par) => {
if par_map.contains_key(node) {
let count = par_map.get_mut(node).unwrap();
*count -= 1;
if *count == 0 {
par_map.remove(node);
node.mutate_into_next(self.env.ctx)
} else {
false
}
} else {
par_map.insert(
node.clone(),
par.stms().len().try_into().expect(
"More than (2^16 - 1 threads) in a par block. Are you sure this is a good idea?",
),
);
new_nodes.extend(
par.stms().iter().map(|x| node.new_retain_comp(*x)),
);
false
}
}
ControlNode::If(i) => {
if i.cond_group().is_some() {
todo!("if statement has a with clause")
Expand Down Expand Up @@ -675,6 +700,11 @@ impl<'a> Simulator<'a> {
}
});

// insert all the new nodes from the par into the program counter
self.env.pc.vec_mut().extend(new_nodes);
// return the par map to the program counter
*self.env.pc.par_map_mut() = par_map;

self.undef_all_ports();

for node in &leaf_nodes {
Expand Down
16 changes: 12 additions & 4 deletions interp/src/flatten/structures/environment/program_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl SearchPath {
// par's child count should be decremented. The latter
// seems more promising but I need to think on it more

todo!("need to deal with par")
return Some(*node);
}
ControlNode::If(_) => {
// there is nothing to do when ascending to an if as it
Expand Down Expand Up @@ -322,7 +322,7 @@ pub type ChildCount = u16;
#[derive(Debug, Default)]
pub(crate) struct ProgramCounter {
vec: Vec<ControlPoint>,
_par_map: HashMap<ControlPoint, ChildCount>,
par_map: HashMap<ControlPoint, ChildCount>,
}

// we need a few things from the program counter
Expand All @@ -349,7 +349,7 @@ impl ProgramCounter {

Self {
vec,
_par_map: HashMap::new(),
par_map: HashMap::new(),
}
}

Expand All @@ -365,9 +365,17 @@ impl ProgramCounter {
self.vec.iter_mut()
}

pub(crate) fn vec_mut(&mut self) -> &mut Vec<ControlPoint> {
pub fn vec_mut(&mut self) -> &mut Vec<ControlPoint> {
&mut self.vec
}

pub fn par_map_mut(&mut self) -> &mut HashMap<ControlPoint, ChildCount> {
&mut self.par_map
}

pub fn _par_map(&self) -> &HashMap<ControlPoint, ChildCount> {
&self.par_map
}
}

impl<'a> IntoIterator for &'a ProgramCounter {
Expand Down

0 comments on commit 9f55a12

Please sign in to comment.