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
    • Handle and Copy Puzzles
    • Virtual Method Puzzles
    • Parameterized Class Puzzles
      • Global Static vs Per-Specialization Static
      • Same Specialization via typedef Alias
      • $cast Between Specializations via a Common Base
      • Unrelated Specializations Cannot Be Assigned
      • Static Function Counters Per Specialization
      • Wrong UVM Macro for Parameterized Object
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • 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

←Parameterized Class Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Parameterized Class Puzzles
  5. Static Function Counters Per Specialization
On this page

    VLSI DV Interview PuzzlesAll levels

    Static Function Counters Per Specialization

    Predict call counters after mixed static-method invocations across different POLY values.

    Puzzle

    Difficulty: Medium · Puzzle 5 of 6 · Topic: Parameterized Class Puzzles

    Predict call counters after mixed static-method invocations across different POLY values.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    class crc #(int POLY = 1);
      static int calls = 0;
      static function int calc(int x);
        calls++;
        return x ^ POLY;
      endfunction
    endclass
    
    initial begin
      void'(crc#(1)::calc(7));
      void'(crc#(1)::calc(8));
      void'(crc#(3)::calc(9));
      $display("c1=%0d c3=%0d", crc#(1)::calls, crc#(3)::calls);
    end

    Hint

    Static storage belongs to specialization, even for static methods.

    Step-by-step solution

    Diagram
    1) Two calls are made on `crc#(1)` => `crc#(1)::calls` becomes 2.
    2) One call is made on `crc#(3)` => `crc#(3)::calls` becomes 1.
    3) No cross-specialization sharing occurs.

    Answer

    Answer: Output is `c1=2 c3=1`.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. The shown code run in Verilator: static methods and their counters are per specialization.

    Why candidates get it wrong

    Static methods are often mistaken as globally shared across all parameter values.

    Interviewer follow-up

    How would you accumulate one global call count while still keeping per-POLY counts? Model answer: put a second static counter in a non-parameterized base class (or package) and increment both in `calc`; the base-class counter is shared by every `POLY`, while `calls` stays per specialization.

    Say it out loud

    The output is c1 equals 2 and c3 equals 1. Each specialization has its own static calls counter, so two calls on the first specialization give 2, and one call on the other gives 1. The trap is assuming the counter is shared across parameter values, so I would check which specialization each call actually uses.

    Related topics

    • Static Properties & Methods

    • Parameterized Classes

    • Back to Parameterized Class Puzzles

    • OOP & Testbench Puzzles section

    Previous

    52 / 293

    Next: Wrong UVM Macro for Parameterized Object

    Up next

    Up nextWrong UVM Macro for Parameterized Object

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Global Static vs Per-Specialization Static
    • Same Specialization via typedef Alias
    • $cast Between Specializations via a Common Base