Skip to question
SystemVerilogDesignVerificationFirmwareArchitectureASIC Interview Questions→
/Interview questions/Deduplicate a sorted register bank

Q073·Free·SystemVerilog

Deduplicate a sorted register bank

Difficulty
Medium
Topic
RTL Datapaths
Language
SV
Interview prompt

Question

Given a sorted active prefix of a bounded tag array, emit one copy of each adjacent run, report the unique count, and zero the unused output suffix. Assume static N >= 1 and TAG_W >= 1.

Candidate starting point

Implementation scaffold

module sorted_bank_deduplicator #(
  parameter int N = 8,
  parameter int TAG_W = 10,
  localparam int COUNT_W = (N < 1) ? 1 : $clog2(N + 1)
) (
  input  logic                   clk,
  input  logic                   rst_n,
  input  logic                   start,
  output logic                   start_ready,
  input  logic [COUNT_W-1:0]     in_count,
  input  logic [TAG_W-1:0]       tag_in [N],
  output logic                   done,
  output logic                   count_error,
  output logic [COUNT_W-1:0]     out_count,
  output logic [TAG_W-1:0]       tag_out [N]
);
  logic pending;
  logic [COUNT_W-1:0] count_q;
  logic count_valid_q;
  logic [TAG_W-1:0] tag_q [N];

  assign start_ready = !pending;

  always_ff @(posedge clk) begin : dedup_proc
    int unsigned unique_count;
    logic [TAG_W-1:0] previous;

    // TODO: Implement dedup_proc using the supplied state and interface.
  end
endmodule
Reviewed example

Trace one case

Input
in_count=6; sorted active prefix=[1,1,2,2,2,5]
Expected output
N=8; out_count=3; tag_out=[1,2,5,0,0,0,0,0]; count_error=0 when done=1.

One value is retained from each adjacent run and the unused bounded suffix is deterministically zeroed.

What to cover

Requirements

  1. Support an active count from zero through N, including both endpoints.
  2. Read only entries below in_count and preserve sorted order.
  3. Keep exactly one copy of each repeated run.
  4. Accept start only when start_ready is high; reject in_count greater than N with count_error.
  5. Capture inputs on an accepted start and publish the result on the following edge with a one-cycle done pulse. For an invalid count, assert count_error and return out_count=0 with every output slot zero.
Exact question handoffPractice Q073

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
  • Deduplication
  • Active prefix
  • Count width
RTL Synthesis and Proof →
Continue practicing

Related questions

Q168 · RTL DesignCount active lanes in a predicate maskEasy→Q240 · Reference ModelsCross-check a byte reverserMediumP→
ASIC.FYI · Learn silicon end to end.info@asic.fyi