Why should I use decompressed vectors in System Verilog?

In response to this question about the difference between packed and decompressed vectors in SV, why would I ever want to use decompressed vectors?
Packed vectors have these advantages that unpacked vectors do not have:

  • You can perform bitwise operations on them.
  • You can perform arithmetic operations on them
  • You can take fragments from them.
  • You can copy them as a whole vector.
  • You can do everything you can with the help of unpacked vectors (as far as I know)

What are the advantages of unpacked vectors over packed vectors?

+7
system-verilog
source share
2 answers

There is another reason why I like to use unpacked ones. With unpacked, there is no temptation (and no chance) to process the entire array name as a variable and erroneously assigned. There is also no possibility of bit bleeding from one element to another when you might think that you are accessing bits B of element N, but in fact you can access K bits of element N and bits BK of element N + -1 ..

My philosophy is to preserve only that which belongs together as a “unit of information” in a packaged dimension. Everything else is in the unpacked dimension. By default, thinking should be unpacked and pack only what you need.

For example, if I have 9 ports, each of which contains 21 bits of information, I would like to declare it as:

input logic [20:0] p1 [9]; 

Part 20:0 is a unit of information assigned and selected together (nominally). Separating these bits will destroy the protocol or nature of the port. On the other hand, changing the number of ports from 9 to, say, 16, will not affect the nature of the information in each port, so 9 ports really belong to the unpacked dimension in my mind.

I hope this can give you a paradigm for reflection ... In this paradigm you will be surprised how many things begin to seem unpacked, which you always considered packed.

+9
source share

Unpacked arrays exist for several reasons.

1) Packed arrays are stored in memory as a continuous sequence of bits. Unpacked arrays can contain each element independently of each other, which can improve simulation performance.

2) Unpacked arrays can be of types that are not bit vectors. Arrays of ints, bytes, events, structures, classes, etc. Can only be unpacked.

3) Most array manipulation methods work only with unpacked arrays.

4) It is possible that only unpacked arrays can be assigned to use array literals. I'm not sure.

There may be other reasons.

+7
source share

All Articles