Hardware interview practice
Verify a dictionary-order permutation streamer
Verify a single-request block that accepts one to seven distinct bytes and streams every permutation in lexicographic order while requests and responses may stall independently.
Starting point
Question code
interface perm_if #(int N=7)(input logic clk);
logic rst_n, req_valid, req_ready;
logic [3:0] count;
logic [7:0] item[N];
logic out_valid, out_ready, out_last, out_error;
logic [7:0] permutation[N];
logic [3:0] out_count;
endinterfaceReviewed example
Work through one case
Input
accepted distinct bytes=[b,a,c]Expected output
[abc, acb, bac, bca, cab, cba]Sorting the captured frame establishes the first lexicographic permutation; successive next-permutation steps produce all 3! results.
What to cover
Requirements
- For a legal count, deep-copy and sort the accepted bytes, then expect exactly count-factorial permutations with unused lanes zero.
- A duplicate byte or count outside 1 through 7 produces one final zero-payload error beat and no successful permutations.
- Keep req_ready low until the final response handshake; bound the first beat, inter-beat gaps, and total completion when out_ready is high.
- Require stable stalled output, out_last only on the final item, and complete cancellation on reset.
