Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Detect duplicate valid cache tags

Q057·Free·Computer Architecture

Detect duplicate valid cache tags

Difficulty
Medium
Topic
RTL Datapaths
Language
SV
Interview prompt

Question

Design a checker for a small fully associative cache set that reports whether any two valid ways contain the same tag and returns the earliest matching way pair. Assume static WAYS >= 1 and TAG_W >= 1. A one-way bank has no distinct pair.

Cache-set tag entries highlighting the duplicate-valid-tag condition
Only valid ways participate in duplicate-tag detection for a selected set.
Candidate starting point

Implementation scaffold

module duplicate_tag_detector #(
  parameter int WAYS = 8,
  parameter int TAG_W = 12,
  localparam int WAY_W = (WAYS <= 1) ? 1 : $clog2(WAYS)
) (
  input  logic               clk,
  input  logic               rst_n,
  input  logic               check,
  input  logic [WAYS-1:0]    way_valid,
  input  logic [TAG_W-1:0]   tag [WAYS],
  output logic               check_ready,
  output logic               done,
  output logic               duplicate_found,
  output logic [WAY_W-1:0]   way_a,
  output logic [WAY_W-1:0]   way_b
);
  logic pending;
  logic [WAYS-1:0] valid_q;
  logic [TAG_W-1:0] tag_q [WAYS];
  logic duplicate_next;
  logic [WAY_W-1:0] way_a_next, way_b_next;

  assign check_ready = !pending;

  always_comb begin : select_duplicate_pair
    // TODO: Implement select_duplicate_pair using the supplied state and interface.
  end

  always_ff @(posedge clk) begin : capture_and_publish
    // TODO: Implement capture_and_publish using the supplied state and interface.
  end
endmodule
Reviewed example

Trace one case

Input
valid=4'b1111; tags by way=[A,B,A,A]
Expected output
duplicate_found=1; way_a=0; way_b=2

Pairs (0,2), (0,3), and (2,3) match. Lexicographic priority chooses (0,2); invalid ways do not participate.

What to cover

Requirements

  1. Compare only distinct valid ways and return way_a < way_b.
  2. Ignore equal tags in invalid ways.
  3. Use lowest-way lexicographic priority when several duplicate pairs exist.
  4. Capture check only when check_ready is high. Register duplicate_found and the pair on the following edge with a one-cycle done pulse; return zero indices for a miss.
Exact question handoffPractice Q057

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessEach time you open this Solution, one Practice Credit is used; it is not permanently unlocked. Premium Solution content also uses one credit per opening.
Continue learning

RTL Synthesis and Proof

Review widths, parameterization, memory inference, pipelining, implementation pressure, and proof evidence.

  • RTL Datapaths
  • Associative compare
  • Priority encoder
  • Valid bits
RTL Synthesis and Proof →
Continue practicing

Related questions

Q050 · RTL DatapathsCompact valid cache-line words in placeMedium→Q041 · RTL DesignControl a tiny exact-LRU associative cacheMedium→Q025 · RTL DesignStably sort records in a local cache-line bufferMedium→Q636 · Waveform DebuggingTwo Same-Set Cache Misses Are Merged Despite Different TagsMediumP→Q298 · ArbitersSelect round-robin winners with rotate and isolateHardP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi