-
|
Is there any way to peek a channel to see if there is data, but not consume it? In RTL, this would correspond to just reading the I imagine this is in-theory simple for codegen, but wonder if this will interact negatively with other optimization passes. The component I have in mind looks like the following bit of pseudocode. struct State {
rng_state : u32;
}
proc arbiter {
input_ch0: chan<u32> in;
input_ch1: chan<u32> in;
output_ch: chan<u32> out;
init {
State { rng_state = 0 }
}
next (state : State) {
let input_ch0_is_valid = peek_is_valid(input_ch0);
let input_ch1_is_valid = peek_is_valid(input_ch1);
let at_least_one_valid = input_ch0_is_valid || input_ch1_is_valid;
let chosen = if input_ch0_is_valid && input_ch1_is_valid {
// is both valid, pick one at random
state.rng_state[0]
} else if input_ch1_is_valid {
1:u1
} else {
0:u1
};
let (tok0, input_data_0) = recv_if_true(join(), input_ch0, at_least_one_valid & chosen ==0 , u32:0);
let (tok1, input_data_1) = recv_if_true(join(), input_ch1, at_least_one_valid & chosen ==1, u32:0);
send_if(join(tok0, tok1), output_ch, at_least_one_valid, if chosen == 1:u1 { input_data_0 } { input_data_1 });
// update_rng_state is defined somewhere else, not too important how it works exactly.
State { rng_state = update_rng_state (state) }
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
proppy
Dec 8, 2025
Replies: 1 comment
-
|
related #1383 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fyquah
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related #1383