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 get_bool_input and get_bool_side #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions crates/redpiler/src/backend/direct/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ fn compile_node(
stats.default_link_count += default_input_count;
stats.side_link_count += side_input_count;

// Make sure signal strength buckets add up to 255 so we can easily check for all zeros in get_bool_input
default_inputs.ss_counts[0] += (MAX_INPUTS - default_input_count) as u8;
side_inputs.ss_counts[0] += (MAX_INPUTS - side_input_count) as u8;

use crate::compile_graph::NodeType as CNodeType;
let updates = if node.ty != CNodeType::Constant {
graph
Expand Down
10 changes: 4 additions & 6 deletions crates/redpiler/src/backend/direct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,14 @@ fn schedule_tick(
scheduler.schedule_tick(node_id, delay, priority);
}

const BOOL_INPUT_MASK: u128 = u128::from_ne_bytes([
0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
]);

fn get_bool_input(node: &Node) -> bool {
u128::from_le_bytes(node.default_inputs.ss_counts) & BOOL_INPUT_MASK != 0
// During compilation its ensured all signal strength buckets add up to 255
// So if and only if the zero bucket contains 255 is the input zero
node.default_inputs.ss_counts[0] != 255
}

fn get_bool_side(node: &Node) -> bool {
u128::from_le_bytes(node.side_inputs.ss_counts) & BOOL_INPUT_MASK != 0
node.side_inputs.ss_counts[0] != 255
}

fn last_index_positive(array: &[u8; 16]) -> u32 {
Expand Down
Loading