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

optimize op2 with immediate num rhs #63

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Port {
/// Accesses the tag of this port; this is valid for all ports.
#[inline(always)]
pub fn tag(&self) -> Tag {
unsafe { ((self.0 & 0x7) as u8).try_into().unwrap_unchecked() }
unsafe { Tag::from_unchecked((self.0 & 0x7) as u8) }
}

/// Accesses the label of this port; this is valid for all non-`Num` ports.
Expand All @@ -225,7 +225,7 @@ impl Port {
/// ports.
#[inline(always)]
pub fn op(&self) -> Op {
unsafe { self.lab().try_into().unwrap_unchecked() }
unsafe { Op::from_unchecked(self.lab()) }
}

/// Accesses the numeric value of this port; this is valid for [`Num`] ports.
Expand Down Expand Up @@ -1704,11 +1704,19 @@ impl<'a, M: Mode> Net<'a, M> {
trace!(self.tracer, a, b);
self.rwts.oper += 1;
let a = a.consume_node();
let x = self.create_node(Op1, a.lab);
trace!(self.tracer, x.p0);
self.link_port_port(x.p1, b);
self.link_wire_port(a.p2, x.p2);
self.link_wire_port(a.p1, x.p0);
let a1 = a.p1.load_target();
if a1.tag() == Num {
// skip creating the Op1 node if it will instantly interact
self.rwts.oper += 1;
let out = unsafe { Op::from_unchecked(a.lab) }.op(b.num(), a1.num());
self.link_wire_port(a.p2, Port::new_num(out));
} else {
let x = self.create_node(Op1, a.lab);
trace!(self.tracer, x.p0);
self.link_port_port(x.p1, b);
self.link_wire_port(a.p2, x.p2);
self.link_wire_port(a.p1, x.p0);
}
}

/// Interacts a number and a unary numeric operation node.
Expand Down
7 changes: 7 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ macro_rules! bi_enum {
}
}

impl $Ty {
#[allow(unused)]
pub unsafe fn from_unchecked(value: $uN) -> $Ty {
Self::try_from(value).unwrap_unchecked()
}
}

impl From<$Ty> for $uN {
fn from(value: $Ty) -> Self { value as Self }
}
Expand Down
Loading