In this article of the Bridge Course: Verilog to SystemVerilog, we dive deep into two powerful SystemVerilog features: Dynamic Arrays and Associative Arrays.
The important topics we will cover in this article are :
- Why Dynamic Arrays are essential for variable-length stimulus generation in verification?
- How to use Dynamic Arrays to create Ethernet frame payloads with random sizes?
- The role of Associative Arrays in transaction tracking using transaction IDs as keys.
- Practical examples of mapping transaction responses for verification environments.
- A comparative study: Dynamic Arrays vs Associative Arrays in SystemVerilog.
Why Dynamic arrays & Associative arrays introduced ?
SystemVerilog improves upon Verilog’s fixed-size arrays by introducing dynamic and associative arrays, allowing data structures to grow, shrink, and adapt at runtime. These features provide greater flexibility and efficiency when handling varying amounts of data in designs.
- Verification environments often deal with data sets of unpredictable size, such as variable-length packets or transaction queues.
- Dynamic arrays allow efficient allocation and resizing of memory at runtime, eliminating the need for fixed, potentially wasteful array sizes.
- Dynamic arrays are particularly useful for generating stimuli like packets with varying payload lengths.
- Reusable and scalable nature of advanced verification environments, enabling modular testbenches and flexible stimulus generation.
- Often used in UVM sequences to generate random-length transactions dynamically. For instance, a `sequence` may generate packets of variable sizes and load them into a dynamic array for verification.
- The next example code mimics generating Ethernet frames with varying payload sizes, essential for verifying the robustness of MAC or PHY layers in handling diverse traffic patterns.
Dynamic and associative arrays solve real-world hardware design challenges by enabling flexible memory usage and handling of varying data sizes. They also make SystemVerilog code cleaner, more maintainable, and focused on functionality rather than rigid data structures.
Dynamic Arrays: Variable-Length Stimulus
Dynamic arrays provide flexibility for handling variable-sized data such as network packets and transaction queues.
They allow memory to be allocated and resized at runtime, making testbenches more adaptable and reusable.
For example, Ethernet frames can be modeled with different payload sizes to represent real-world traffic.
They allow memory to be allocated and resized at runtime, making testbenches more adaptable and reusable.
For example, Ethernet frames can be modeled with different payload sizes to represent real-world traffic.
This improves memory efficiency and scalability, especially in UVM-based verification environments.
Stimulus for Ethernet Frame Verification:
Dynamic arrays can generate Ethernet frames with random payload sizes, helping verify MAC/PHY designs under varied traffic conditions. They allow realistic testing of everything from small control packets to large data frames.
This avoids hardcoded test data and helps uncover edge cases and performance issues. As a result, verification becomes more thorough, flexible, and adaptable to real-world traffic.
Associative Arrays: Transaction Tracking
Associative arrays store data using meaningful keys such as transaction IDs or strings, making them ideal for tracking out-of-order transactions. They enable robust scoreboards and monitors for protocols like PCIe and AXI, improving accuracy, scalability, and clarity in verification.
- Protocol verification or mapping tasks often involve data that does not follow sequential or numerical indexing.
- Associative arrays provide a mechanism to efficiently acess data using meaningful keys like transaction IDs or strings, mimicking hash-table functionality.
- Associative arrays are ideal for tracking transactions where data needs to be indexed by identifiers like transaction IDs, which may not follow a sequential order.
- Reusable and scalable nature of advanced verification environments, enabling modular testbenches and flexible stimulus generation.
- Used in UVM scoreboards or monitors to store expected vs. actual responses. The ability to index data using transaction IDs ensures that mismatches are detected even for out-of-order operations.
- In next example associative arrays make it easy to track and validate responses for transactions processed out of order or dynamically, as seen in verification of protocols like PCIe or AXI where responses may not match the transaction order.
Mapping Transaction IDs to Responses:
Associative arrays map transaction IDs to their corresponding responses, enabling reliable tracking even when responses arrive out of order. They make it easy to store and retrieve transaction results using meaningful keys. This simplifies the implementation of scoreboards and monitors in protocol verification. Overall, they provide a clean, efficient, and scalable approach to transaction tracking.
Comparative Study : Dynamic Arrays Vs Associative Arrays
Dynamic arrays are ideal for variable-length, sequential data such as packets and queues.Associative arrays are better suited for mapping and tracking data using meaningful keys like transaction IDs or addresses. Choosing the right array type makes verification environments more flexible and efficient. Together, they help testbenches scale effectively with complex, real-world verification scenarios.
Watch the video lecture here:







