Q006FreeSystemVerilog
Vote across redundant state monitors
Interview prompt
Question
Sample five redundant multi-bit state codes and return the code that appears at least three times. If no strict majority exists, report an invalid result and return zero. Assume a positive static CODE_W.
Candidate starting point
Implementation scaffold
module redundant_state_voter #(
parameter int unsigned CODE_W = 4
) (
input logic clk,
input logic rst_n,
input logic check,
input logic [CODE_W-1:0] code [0:4],
output logic done,
output logic majority_valid,
output logic [CODE_W-1:0] majority_code
);
logic majority_valid_next;
logic [CODE_W-1:0] majority_code_next;
logic check_q;
always_comb begin : vote_whole_codes
// TODO: Initialize the majority outputs for the no-winner case.
for (int unsigned i = 0; i < 5; i++) begin
int unsigned match_count;
// TODO: Count complete-code matches for candidate i and select the first strict majority.
end
end
always_ff @(posedge clk) begin : sample_check_edge
// TODO: Implement sample_check_edge using the supplied state and interface.
end
endmoduleReviewed example
Trace one case
Input
five sampled state codes=[3,5,3,3,5]Expected output
majority_valid=1; majority_code=3Three complete codes equal 3, satisfying the strict majority without unsafe per-bit voting.
What to cover
Requirements
- Compare complete state codes rather than voting each bit independently.
- Require at least three identical entries out of five.
- Produce deterministic zero data when the sampled set has no strict majority.
- On a clock edge where check is high and was low at the previous sampled edge, sample all five entries together, register the result, and raise done for one cycle. Holding check high must not create another request.
