Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
    • Covergroup and Coverpoint Puzzles
    • Cross Coverage Puzzles
    • Coverage Options Puzzles
    • Coverage Closure and Sampling Timing Puzzles
      • Sampling region off-by-one on state bins
      • Unreachable bin from stimulus constraints
      • Sampling on a derived clock sees the updated value
      • Reset-time samples filtered by iff
      • Unreachable cross tuple from protocol rules
      • at_least threshold causes closure plateau
    • Functional Coverage Puzzles: Tricky Q&A
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Coverage Closure and Sampling Timing Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Functional Coverage Puzzles
  4. Coverage Closure and Sampling Timing Puzzles
  5. Sampling region off-by-one on state bins
On this page

    VLSI DV Interview PuzzlesAll levels

    Sampling region off-by-one on state bins

    The team expects bins 1,2,3 after three clocks but the report differs. clk starts at 0 and toggles every 5 time units; the covergroup is sampled manually by c.sample(state) from a posedge process. Options: none set (defaults). Compute the actual hits and explain.

    Puzzle

    Difficulty: Medium · Puzzle 1 of 6 · Topic: Coverage Closure and Sampling Timing Puzzles

    The team expects bins 1,2,3 after three clocks but the report differs. clk starts at 0 and toggles every 5 time units; the covergroup is sampled manually by c.sample(state) from a posedge process. Options: none set (defaults). Compute the actual hits and explain.

    Code

    tb.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    module tb;
      bit clk;
      bit [1:0] state;
    
      covergroup cg with function sample(bit [1:0] s);
        cp_state: coverpoint s {
          bins s0 = {0};
          bins s1 = {1};
          bins s2 = {2};
          bins s3 = {3};
        }
      endgroup
    
      cg c = new();
    
      always #5 clk = ~clk;
      always_ff @(posedge clk) state <= state + 1;
      always @(posedge clk) c.sample(state);
    
      initial begin
        repeat (3) @(posedge clk);
        #1 $finish;
      end
    endmodule

    Hint

    The always_ff update is a nonblocking assignment, so the sampler at the same posedge reads the old value.

    Step-by-step solution

    Diagram
    1) Posedges are at t = 5, 15, 25. At each one the sampling process runs in the active region and reads state; the nonblocking update from always_ff happens later in the NBA region.
    2) Sampled values are therefore 0, 1, 2 (state becomes 3 only after the third edge and is never sampled).
    3) Hit bins are s0, s1, s2 -> 3/4 = 75%.
    (The same sampling structure was run as plain RTL in Icarus and Verilator 5.048: both sampled 0, 1, 2.)

    Answer

    Answer: Actual coverage is 75% because the sampled states are 0,1,2 (not 1,2,3); s3 is never sampled.

    How this was checked

    Checked by running the code in Icarus Verilog 13 and Verilator 5; the printed output supports the answer above. Plain RTL with the same sampling structure: the sampler reads the pre-update state, so the sampled values are 0, 1, 2. Verilator 5 gives the same sampled values 0, 1, 2 (covergroups are not simulated, so the sample call is a $display).

    Why candidates get it wrong

    A waveform cursor just after the edge shows 1,2,3, but the sampler used the value from before the edge. state starts at 0 (bit is 2-state) and is written only by always_ff. A sampler on the negedge would see the post-update values 1 and 2 only, because $finish at t=26 comes before the third negedge at t=30; its coverage would be 2/4 = 50% (s1, s2), with s0 and s3 missing.

    Interviewer follow-up

    What monitor timing change would capture post-update states without modifying DUT logic? Model answer: Sample after the update instead of at the edge: for example in an always @(negedge clk) block or one cycle later, so the monitor reads the value the edge produced. A clocking-block input would not help, since it samples the pre-edge (preponed) value like the current code.

    Say it out loud

    I would first check which value the sampler sees at the edge. Sampling from a posedge process reads the value before the nonblocking update, so the hits are states 0, 1 and 2, not 1, 2 and 3, and coverage is 75 percent. State 3 is never sampled. The trap is trusting a waveform cursor just after the edge. Next I would move the sample to a defined point after the update.

    Related topics

    • Sampling: Clocked, Event & sample()

    • Hole Analysis and Triage

    • Back to Coverage Closure and Sampling Timing Puzzles

    • Functional Coverage Puzzles section

    Previous

    154 / 293

    Next: Unreachable bin from stimulus constraints

    Up next

    Up nextUnreachable bin from stimulus constraints

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Sampling on a derived clock sees the updated value
    • Reset-time samples filtered by iff
    • Unreachable cross tuple from protocol rules