Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tjjfvi committed Mar 25, 2024
1 parent fefb44e commit 3e1ca16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/run/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ impl RedexQueue {
self.fast.is_empty() && self.slow.is_empty()
}
#[inline(always)]
pub fn take(&mut self) -> impl Iterator<Item = (Port, Port)> {
std::mem::take(&mut self.fast).into_iter().chain(std::mem::take(&mut self.slow))
pub fn drain(&mut self) -> impl Iterator<Item = (Port, Port)> + '_ {
self.fast.drain(..).chain(self.slow.drain(..))
}
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = &(Port, Port)> {
Expand All @@ -392,7 +392,6 @@ impl RedexQueue {
// Returns whether a redex does not allocate memory
fn redex_would_shrink(a: &Port, b: &Port) -> bool {
(*a == Port::ERA || *b == Port::ERA)
|| (!(a.tag() == Tag::Ref || b.tag() == Tag::Ref)
&& (((a.tag() == Tag::Ctr && b.tag() == Tag::Ctr) || a.lab() == b.lab())
|| (a.tag() == Tag::Num || b.tag() == Tag::Num)))
|| (a.tag() == Tag::Ctr && b.tag() == Tag::Ctr && a.lab() == b.lab())
|| (!(a.tag() == Tag::Ref || b.tag() == Tag::Ref) && (a.tag() == Tag::Num || b.tag() == Tag::Num))
}
2 changes: 1 addition & 1 deletion src/run/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

/// An interaction combinator net.
pub struct Net<'a, M: Mode> {
linker: Linker<'a, M>,
pub(super) linker: Linker<'a, M>,
pub tid: usize, // thread id
pub tids: usize, // thread count
pub trgs: Box<[MaybeUninit<Trg>]>,
Expand Down
16 changes: 9 additions & 7 deletions src/run/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ use super::*;
impl<'h, M: Mode> Net<'h, M> {
/// Forks the net into `tids` child nets, for parallel operation.
pub fn fork(&mut self, tids: usize) -> impl Iterator<Item = Self> + '_ {
let redexes_len = self.redexes.len();
let mut redexes = self.redexes.take();
let redexes_len = self.linker.redexes.len();
let mut redexes = self.linker.redexes.drain();
let heap = &self.linker.allocator.heap;
let next = &self.linker.allocator.next;
let root = &self.root;
(0 .. tids).map(move |tid| {
let heap_size = (self.heap.0.len() / tids) & !63; // round down to needed alignment
let heap_size = (heap.0.len() / tids) & !63; // round down to needed alignment
let heap_start = heap_size * tid;
let area = unsafe { std::mem::transmute(&self.heap.0[heap_start .. heap_start + heap_size]) };
let mut net = Net::new_with_root(area, self.root.clone());
net.next = self.next.saturating_sub(heap_start);
let area = unsafe { std::mem::transmute(&heap.0[heap_start .. heap_start + heap_size]) };
let mut net = Net::new_with_root(area, root.clone());
net.next = next.saturating_sub(heap_start);
net.head = if tid == 0 { net.head } else { Addr::NULL };
net.tid = tid;
net.tids = tids;
Expand Down Expand Up @@ -71,7 +74,6 @@ impl<'h, M: Mode> Net<'h, M> {
}
});

// Clear redexes and sum stats
delta.add_to(&mut self.rwts);

// Main reduction loop
Expand Down

0 comments on commit 3e1ca16

Please sign in to comment.