What you practice
Packed vs Unpacked arrays (1.2). See how packed and unpacked arrays differ in syntax, memory layout, and slicing behavior. It is in Aggregate Data Types — Part 1 · Design in SV of the SystemVerilog Masterclass. Synthesizable SystemVerilog that removes Verilog ambiguity and cuts boilerplate.
The same IDE is the SystemVerilog simulator. Slang lints the file, Verilator runs it, and the waveform viewer sits next to the source.
What you will learn
Today you will learn how SystemVerilog distinguishes between packed and unpacked arrays in memory layout and syntax, and how to correctly declare and slice them.
Learning objectives
- Differentiate packed arrays (dimensions before the name) from unpacked arrays (dimensions after the name).
- Understand how bit-slicing and indexing work for each type.
- Correctly declare 4×8-bit memory using both packed and unpacked syntax.
- Observe identical functional behavior despite different memory layouts.
Theory
Packed arrays store elements contiguously in a single vector, enabling bit-slicing on the entire array. Unpacked arrays are collections of independent elements, indexed but not bit-slicable as a whole.
| Type | Syntax Example | Memory Layout | Slicing Support |
|---|---|---|---|
| Packed | logic [3:0][7:0] arr | 32-bit contiguous | Yes: arr[31:24] |
| Unpacked | logic [7:0] arr [0:3] | 4 separate 8-bit slots | No: only element access |
Packed dimensions appear before the identifier name. Unpacked dimensions appear after the identifier name and use [...] for index ranges.
Practice
Open RtlStudio and select this chapter. Files appear in Explore — no project setup needed.
- Open
student/rtl/design.svin the editor. - Replace each
__TODO__with the correct bit-range:
- L10 wdata and L13 rdata: [7:0]. - L11 waddr: [3:0]. - L17 packed_flat: [31:0] (Yosys-friendly packed flat vector).
- Save the file.
- Run Simulation from the left sidebar.
- Read the Log panel to verify writes and reads match expectations.
- (Optional) Open the Waveform tab to inspect signal timing.
Summary
You practiced declaring and using both packed and unpacked arrays in SystemVerilog, observing how dimension ordering affects memory layout and bit-slicing behavior. You confirmed that packed arrays store elements contiguously in bits, enabling direct bit-slicing across dimensions, while unpacked arrays store elements as separate entities, requiring element selection before bit operations. This distinction is critical for predicting memory usage and ensuring correct data access in hardware implementations. Mastering these rules ensures precise control over data representation and efficient synthesis of logic circuits.
Run it in the Verilog IDE
- Open the lesson in the IDE. The SystemVerilog for this topic is already in the editor.
- Lint with Slang before you simulate. It covers both Verilog and SystemVerilog in this IDE.
- Run Verilator and inspect the VCD. Interfaces, classes, and assertions count only if the simulator agrees.
- Run Yosys when the lesson is synthesizable RTL, and keep testbench-only constructs out of that module.
The lesson is done when the simulation matches Packed vs Unpacked arrays. Change the source, run the Verilog simulator again, and read the waveform without leaving the IDE. Simulation guide · Yosys guide.