Q021FreeSystemVerilog
Look up time-indexed register history
Interview prompt
Question
Store timestamped values for four register keys and answer queries with the value whose stored timestamp is the greatest one less than or equal to the requested time. A query miss returns rsp_hit=0, rsp_timestamp=0, and rsp_value=0. Accepted queries and writes use cmd_valid && cmd_ready.

Candidate starting point
Implementation scaffold
module register_history_lookup (
input logic clk,
input logic rst_n,
input logic cmd_valid,
input logic cmd_query,
input logic [1:0] cmd_key,
input logic [15:0] cmd_timestamp,
input logic [31:0] cmd_value,
input logic rsp_ready,
output logic cmd_ready,
output logic rsp_valid,
output logic rsp_hit,
output logic [15:0] rsp_timestamp,
output logic [31:0] rsp_value
);
typedef enum logic [2:0] {S_IDLE, S_READ, S_CHECK, S_RSP} state_t;
state_t state_q;
logic [15:0] timestamp_q [0:3][0:7];
logic [31:0] value_q [0:3][0:7];
logic [3:0] count_q [0:3];
logic [1:0] query_key_q;
logic [15:0] query_timestamp_q;
logic [2:0] scan_q;
logic [15:0] read_timestamp_q;
logic [31:0] read_value_q;
logic hit_q;
logic [15:0] response_timestamp_q;
logic [31:0] response_value_q;
assign cmd_ready = (state_q == S_IDLE);
assign rsp_valid = (state_q == S_RSP);
assign rsp_hit = hit_q;
assign rsp_timestamp = response_timestamp_q;
assign rsp_value = response_value_q;
always_ff @(posedge clk) begin : append_scan_and_respond
// TODO: Implement append_scan_and_respond using the supplied state and interface.
end
endmoduleReviewed example
Trace one case
Input
write key=2 (t=10,A), then (t=20,B); query key=2 at t=5,10,17,20Expected output
MISS, A, A, BThe backward search returns the newest timestamp less than or equal to the query and treats an exact timestamp as a hit.
What to cover
Requirements
- Support four keys and at most eight writes per key, with strictly increasing timestamps within each key.
- Serialize accepted commands and make every accepted write visible to every later accepted query.
- Return a miss before the first stored timestamp and use inclusive less-than-or-equal behavior for exact matches.
- Model a one-cycle local-memory read rather than comparing an entire history combinationally.
- A query response must remain stable until accepted; writes do not generate responses.
