Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Forward bytes from a small pending-write queue

Hardware interview practice

Forward bytes from a small pending-write queue

MediumComputer ArchitectureSystemVerilog

A memory controller allows up to four pending masked writes. A read must see the newest pending byte for each lane before falling back to memory data. Implement the SystemVerilog reference model for enqueue, commit, and read prediction.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

class writeq_ref;
function bit enqueue(bit [15:0] addr, bit [31:0] data, bit [3:0] mask);
function bit commit();
function bit [31:0] predict_read(bit [15:0] addr, bit [31:0] mem_data);
endclass
Reviewed example

Work through one case

Input
enqueue(0x100, 0xAABBCCDD, 4'b0011), then predict_read(0x100, 0x11223344).
Expected output
predict_read returns 32'h1122CCDD.

The newest pending write forwards only masked byte lanes 0 and 1; lanes 2 and 3 remain from memory data.

What to cover

Requirements

  1. Construction starts with an empty queue. enqueue appends a write if fewer than four entries exist and mask is nonzero; return 1 on append, otherwise return 0 with the queue unchanged.
  2. commit removes the oldest entry and returns 1, or returns 0 without change when the queue is empty.
  3. predict_read starts with mem_data and, for each byte lane, uses the newest queued write at the exact same word address whose mask includes that lane.
  4. All addresses are byte addresses and must be four-byte aligned; an unaligned enqueue returns 0, while an unaligned predict_read returns 32'h0000_0000 and changes no queue state.
Continue practicing

Related questions

Computer ArchitectureMatch hit-under-miss responses by transaction ID→Computer ArchitecturePlace a dense neural-network kernel→Computer ArchitecturePause headroom at 400 Gb/s→
asic.fyi · Learn silicon end to end.info@asic.fyi