Skip to content

Commit

Permalink
Optimize get_bool_input and get_bool_side by making sure signal stren…
Browse files Browse the repository at this point in the history
…gth buckets add up to 255
  • Loading branch information
BramOtte committed Jan 21, 2025
1 parent 45d80d2 commit 17ae918
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 17ae918

Please sign in to comment.