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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
    • Parameterization and Generate Hub
    • Top-Level Integration Hub
    • Synthesis Intent Hub
    • Style and Static Checks Hub
    • Assertions in RTL Hub
    • Formal Verification Basics Hub
    • Reusable SystemVerilog for RTL
      • Packages and Compile Order
      • Packed Structs and Unions
      • Parameter Types and Guards
      • Functions and Tasks
      • Interfaces, Modports, and Portability
      • Compile-Order and Package Errors, Decoded
      • Mini Project: a Reusable FIFO IP
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Advanced RTL
  1. Topics
  2. RTL Design
  3. Advanced RTL
  4. Reusable SystemVerilog for RTL

Part 8 · Advanced · Advanced

Reusable SystemVerilog for RTL

Packages, packed types, parameter types, synthesizable functions, interfaces, compile order, and portability boundaries.

  • 7topics
  • 7lessons

Topics in this section

  1. 1Packages and Compile Order1 lesson
  2. 2Packed Structs and Unions1 lesson
  3. 3Parameter Types and Guards1 lesson
  4. 4Functions and Tasks1 lesson
  5. 5Interfaces, Modports, and Portability1 lesson
  6. 6Compile-Order and Package Errors, Decoded1 lesson
  7. 7Mini Project: a Reusable FIFO IP1 lesson
On this page

    SystemVerilog can make RTL contracts explicit without pulling verification-only constructs into synthesis. The useful design subset packages shared types, groups related signals, checks parameters, and removes copy-pasted width logic.

    These independent patterns cover a shared-type package, packed request fields, a type-parameterized pipeline, width-scoped helper functions, and a stream-interface declaration. They are building blocks, not a connected packet-pipeline reference implementation. The interface-stage body is intentionally omitted; its handshake implementation must supply buffering, reset and backpressure behavior.

    Lessons in this topic

    7 lessons, about 42 min

    1. 1Packages and Compile OrderYou can replace duplicated type definitions with one package, order packages before their importers, and read a compile-order error.4 min
    2. 2Packed Structs and UnionsYou can compute a packed struct's width and field positions, decode a value by slice, and publish the layout with a conversion function at an IP boundary.3 min
    3. 3Parameter Types and GuardsYou can guard illegal parameter values with an elaboration check, pass a type as a parameter, and choose which configurations to test.4 min
    4. 4Functions and TasksYou can write pure helper functions for Gray conversion and byte merging, trace a Gray encode and decode by hand, and guard the widths they assume.5 min
    5. 5Interfaces, Modports, and PortabilityYou can use modports to document driver direction, decide where to flatten an interface, and check a pattern in every supported tool.2 min
    6. 6Compile-Order and Package Errors, DecodedYou can read the order, import, ambiguity, typo and width errors two compilers print, name the cause and the one-line fix, and check a file list for package order before building.9 min
    7. 7Mini Project: a Reusable FIFO IPYou can package a block with a type package, elaboration guards, an interface view, built-in SVA, a file list and a waiver file, and prove it with a self-checking bench, a seeded bug and a Yosys bounded check.15 min

    Tip

    This topic covers the synthesizable RTL subset. The complete language, testbench, OOP, randomization, coverage, and advanced compilation material remains in the SystemVerilog course.

    Check yourself What makes a SystemVerilog abstraction useful in RTL?

    It makes hardware intent and connectivity clearer while elaborating into predictable synthesizable structures supported by the target tool flow.

    Revision sheet

    The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.

    Packages and Compile Order

    • One definition in a package; every block imports it, so a layout change reaches all of them.

    • Compile packages before the modules that import them, and avoid circular imports.

    • Prefer explicit pkg::type in widely shared headers, because wildcard imports can collide.

    Rule of thumb: move common definitions into a lower-level package instead of importing in a circle.

    Packed Structs and Unions

    • The first declared field takes the most significant bits: 1 + 4 + 8 + 32 = 45 bits for request_t.

    • Packed positions describe the value; they do not set which byte goes on a bus first.

    • Union members are views of the same bits, so carry an explicit tag if the interpretation changes.

    Rule of thumb: publish the bit layout, and convert explicitly where an external standard defines byte order.

    Parameter Types and Guards

    • Guard zero and one values before $clog2, ranges or part-selects, and use a localparam for derived values.

    • A module-scope $error inside a generate-if stops the build at elaboration; an initial $fatal runs only at simulation time zero.

    • Test the minimum, a normal value and one more configuration.

    Rule of thumb: a parameterised module is not reusable until its legal range is documented and checked.

    Functions and Tasks

    • In RTL, a function computes one value from its inputs; keep waiting tasks in testbenches.

    • Gray encode is one XOR level, g = (b >> 1) ^ b; decode ripples from the top bit down.

    • W/8 truncates: W=4 gives [-1:0] and W=12 leaves four bits unmerged, so keep the legal-width guard.

    Rule of thumb: outputs depend only on inputs, so simulation, synthesis and formal agree.

    Interfaces, Modports, and Portability

    • Modports state source and sink ownership; assertions still have to check stability, transfer and reset.

    • Flatten interfaces at external IP boundaries when a tool or language needs plain ports.

    • Compile a small representative design in every supported simulator and synthesis tool before standardising.

    Rule of thumb: type safety does not enforce valid/ready stability; the assertions do.

    Compile-Order and Package Errors, Decoded

    • Before declaration with a second location means file order; Can't find means a missing import; Import package not found means a typo.

    • Two wildcard imports that export the same name are ambiguous; one tool may silently pick by import order. Qualify the name.

    • Keep imports inside module headers and the order in one file list, packages first, checked by a script before the compiler runs.

    Rule of thumb: when a package error is unclear in one tool, run the second one: the message that names a location or a package is the cause.

    Mini Project: a Reusable FIFO IP

    • Guard parameters at elaboration, then check the guard stops the build in every flow: Verilator reports $error as a warning, which -Wno-fatal lets through.

    • Put checks in the RTL behind macros each tool defines: FORMAL for Yosys, __ICARUS__ to skip SVA Icarus cannot parse, plain SVA for Verilator.

    • A bounded pass counts only if a cover shows the bound reaches the corner: full needs one reset step plus DEPTH pushes.

    Rule of thumb: an IP is done when a stranger can run one script and see every check pass, and a seeded bug fail.

    Practise it

    • Code lab: Package functions

    • Practice question: Packed versus unpacked structs in RTL datapaths

    • Code lab: Packed struct beat

    • Practice question: Synchronous FIFO with full and empty flags

    • Practice question: Synchronous FIFO blocking on full and empty

    • Interview: run a mock interview on this topic

    PreviousNext: Packages and Compile Order

    Up next

    Up nextPackages and Compile Order

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Parameterization and Generate Hub
    • Top-Level Integration Hub
    • Synthesis Intent Hub