Hardware interview practice
SystemVerilog Packed vs. Unpacked Arrays
How should this declaration be interpreted?
bit [7:0] bytes [4];Answer choices
- A. One packed 32-bit vector
- B. Eight unpacked arrays, each four bits wide
- C. Four unpacked elements, each an 8-bit packed vector
- D. A dynamic array whose current size is four
Concise answer
The answer and the key reason
Deeper explanation
Work through the implementation and tradeoffs
Packed dimensions appear to the left of the variable name and participate as part of each element’s integral bit representation. That makes bytes[i] an 8-bit value that can be sliced and used in arithmetic. Packed bit numbering here runs from 7 down to 0, so bytes[i][7] selects that element’s most significant bit.
Unpacked dimensions appear after the name and organize separate elements. In this declaration, the outer dimension supplies four byte-sized entries rather than flattening everything into one 32-bit packed vector. The total storage is still 32 bits, but assignment compatibility, indexing order, slicing, and layout semantics differ from a single packed [31:0] declaration.
What to remember
- Left dimensions are packed
- Right dimensions are unpacked
- Four elements, eight bits each
Practice the complete prompt
