← Design Verification Interviews

Interview Question · Code Reading

Automatic Bins on an 8-Bit Value

L0 FresherL1 Juniorfunctional coveragebins

The Question

The interviewer asks

This coverpoint has no bins of its own. How many bins does it get, and what coverage does it print?

systemverilog
bit [7:0] len;
covergroup cg;
  cp: coverpoint len;           // no bins of its own
endgroup
cg c = new();
initial begin
  foreach (vals[i]) begin       // vals = '{0, 1, 2, 3, 100}
    len = vals[i];
    c.sample();
  end
  $display("coverage=%0.2f", c.get_coverage());
end
Reveal the Model Answer

It gets 64 automatic bins, not 256. When a coverpoint lists no bins, the tool makes at most auto_bin_max bins, and the default is 64. So each bin holds 4 values: 0 to 3, 4 to 7, and so on. The five samples land in only two bins, 0 to 3 and 100 to 103. It prints coverage=3.12, which is 2 of 64.

Five Samples Into 64 Automatic Bins
01234sample1st2nd3rd4th5thlen0123100bin hitauto[0:3]auto[100:103]bins covered1 of 642 of 64coverage=3.12, which is 2 of 64

One column per sample. The first four values all fall in the same bin of four values, so five samples hit only two bins.

Self-Check

Tick each key point you covered in your answer.

What Interviewers Listen For (Fresher)

A good fresher answer divides 256 values by 64 bins, so each bin holds 4 values. It finds the two bins that were hit and gets close to 3%.

Cross-Questions

Where the interviewer goes next. Open a node to practise that follow-up.

WhyWhat IfProve ItCompareScale It

  1. Automatic Bins on an 8-Bit Value
  2. What IfAutomatic Bins on an EnumL1 Junior

    Asked if they mention enums

    What if the coverpoint is on an enum with three named values, and auto_bin_max is set to 2?

    systemverilog
    module tb;
      typedef enum bit [3:0] {IDLE = 0, BUSY = 5, DONE = 9} st_t;
      st_t st;
      covergroup cg;
        cp: coverpoint st { option.auto_bin_max = 2; }
      endgroup
      cg c = new();
      initial begin
        st = IDLE; c.sample();
        st = BUSY; c.sample();
        $display("enum coverage=%0.2f", c.get_coverage());
      end
    endmodule
    
    Reveal the Model Answer

    An enum coverpoint gets one automatic bin per named value, and auto_bin_max does not apply. So there are three bins, and two samples give 66.67%. Values the enum type could hold but does not name get no bins.

    RUNVerilator (coverage build) · simulator service
    Edit the code, then run it
    Expected: enum coverage=66.67

    Self-Check

    Tick each key point you covered in your answer.

    Misconception

    "auto_bin_max = 2 squeezes the enum into two bins."

    For an enum, the number of automatic bins is the number of named values. The run shows three bins.

    Source IEEE 1800-2017 §19.5.3

  3. CompareAutomatic vs Explicit BinsL1 JuniorL2 Mid-Level

    Compare automatic bins with bins you write yourself. When is each the right choice?

    Reveal the Model Answer

    Automatic bins are fine when there are few values and every one matters, such as an enum or a 3-bit field. Write explicit bins when the value is wide or when only some values matter. Explicit bins follow the spec: corners, ranges where the design behaves differently, and values that must never appear. They also give the report readable names.

    Automatic binsExplicit bins
    Good forFew values that all matter: an enum, a 3-bit fieldWide values, or values where only some matter
    Bin edges come fromArithmeticThe spec: ranges, edges, forbidden values
    Report namesauto[...]Names you chose

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Mid-Level)

    A good mid-level answer links every explicit bin to a line in the spec or the plan. It also says which values were left out on purpose.

    Half-Truth

    "Automatic bins are safer because the tool cannot forget a value."

    The tool groups values without knowing the spec. A boundary such as 255 vs 256 can land inside one group and never be seen.

    Source Mehta, SystemVerilog Assertions and Functional Coverage (3rd ed.), §27.1 (PDF p502)

  4. Scale ItAutomatic Bins on a 32-Bit AddressL2 Mid-Level

    A teammate puts a coverpoint with automatic bins on a 32-bit address and reports 100%. What does that number tell you?

    Reveal the Model Answer

    Almost nothing. With 64 automatic bins, each bin spans 2 to the power 26 addresses, about 67 million. One access anywhere in each slice covers it. The model says nothing about alignment, region boundaries or the last address of a region. Replace it with bins for the address map. Cover each region, its first and last word, and unaligned accesses if the bus allows them.

    Self-Check

    Tick each key point you covered in your answer.

    Wrong Altitude

    "Raise auto_bin_max until the bins are small enough."

    More slices still ignore the address map. Region edges fall wherever the arithmetic puts them, and the model grows without becoming meaningful.

    Source Spear & Tumbush, SystemVerilog for Verification (3rd ed.), §9.10 (PDF p392)

  5. WhyWhy Automatic Bins Have a CapL1 Junior

    Why does the language cap automatic bins at all, instead of one bin per value?

    Reveal the Model Answer

    Without a cap, a 32-bit coverpoint would need over four billion bins. That costs memory, slows every sample and makes a report nobody can read. The cap keeps a forgotten coverpoint from exploding. You can change it per coverpoint or per covergroup with option.auto_bin_max.

    Self-Check

    Tick each key point you covered in your answer.

    Tool as Truth

    "The cap is a tool setting that differs between simulators."

    The cap and its default of 64 are in the standard's option table, so every compliant tool starts from the same number.

    Source Mehta, Introduction to SystemVerilog, Table 15.3 (PDF p614)

  6. Prove ItSolve 7.5.8: Two Coverpoints for the FIFOSimulator-graded

    Show it, don't just say it: this Silicon Lab problem is graded by the simulator.

    Open Problem 7.5.8

What People Get Wrong

Common wrong answers and why they fail. Run It shows the wrong belief failing on a real simulator.

Misconception

"Each value gets its own bin, so 5 of 256 is about 2%."

The default cap of 64 bins makes each bin a group of 4 values. The twin prints 3.12; raising the cap to 256 gives the 1.95 the candidate expected.

Run It

The interview code, checked against the one-bin-per-value belief.

RUNVerilator (coverage build) · simulator service
Edit the code, then run it
Expected: coverage=3.12 FAIL: automatic bins hold 4 values each, so 5 samples covered 2 of 64 bins, not 5 of 256
See the Fix
module tb;
  bit [7:0] len;
  bit [7:0] vals[5] = '{0, 1, 2, 3, 100};
  covergroup cg;
    cp: coverpoint len { option.auto_bin_max = 256; }   // the fix: allow one bin per value
  endgroup
  cg c = new();
  initial begin
    foreach (vals[i]) begin len = vals[i]; c.sample(); end
    $display("coverage=%0.2f", c.get_coverage());
    if ($rtoi(c.get_coverage() * 100) != 195) $display("FAIL: automatic bins hold 4 values each, so 5 samples covered 2 of 64 bins, not 5 of 256");
    else $display("PASS: with auto_bin_max = 256 each value has its own bin, so 5 of 256 bins are covered");
  end
endmodule

Prints: coverage=1.95 PASS: with auto_bin_max = 256 each value has its own bin, so 5 of 256 bins are covered

Half-Truth

"100% on automatic bins means every value was seen."

That holds only when the type has 64 values or fewer. For a wider type, one hit inside a group covers the whole group.

Source IEEE 1800-2017 §19.5.3

Delivery

Starts listing every bin type in the language before answering how many bins this one has.

The question is one number and one reason. Answer that first, then offer the wider picture if asked.

Learn It, Then Prove It