Q039FreeSystemVerilog
Find the unpaired fault ID
Interview prompt
Question
Consume a framed stream in which every fault ID appears exactly twice except one ID that appears once, then return the unpaired ID. Assume ID_W >= 1 and that the producer satisfies this frame-content promise; the unit need not validate multiplicities.
Candidate starting point
Implementation scaffold
module unpaired_fault_finder #(
parameter int ID_W = 12
) (
input logic clk,
input logic rst_n,
input logic fault_valid,
input logic fault_last,
input logic [ID_W-1:0] fault_id,
output logic fault_ready,
output logic result_valid,
input logic result_ready,
output logic [ID_W-1:0] result_id
);
logic [ID_W-1:0] xor_accum;
assign fault_ready = !result_valid;
always_ff @(posedge clk) begin : accumulate_and_publish
// TODO: Implement accumulate_and_publish using the supplied state and interface.
end
endmoduleReviewed example
Trace one case
Input
accepted fault IDs=[5,2,5,2,7], last asserted with 7Expected output
result_id=7The two copies of 5 cancel, and the two copies of 2 cancel. Including the final accepted 7 leaves result_id=7, which remains valid until consumed. The same logic also supports an unpaired ID of zero.
What to cover
Requirements
- Change the accumulator only when fault_valid and fault_ready are both asserted.
- Include the accepted final item in the result when fault_last is asserted.
- Support an unpaired ID of zero.
- Hold result_id and result_valid stable during result backpressure.
