系统verilog中的打包向量与未打包向量

发布于 2024-07-12 03:35:26 字数 407 浏览 13 评论 0原文

查看我在 System Verilog 中维护的一些代码,我看到一些信号的定义如下:

node [range_hi:range_lo]x;

以及其他信号的定义如下:

node y[range_hi:range_lo];

我知道 x 被定义为打包,而 y 被定义为未打包。 但是,我不知道这意味着什么。

System Verilog 中打包向量和未打包向量有什么区别?

编辑:回应@Empi的回答,为什么用SV编写的硬件设计师应该关心数组的内部表示? 有没有什么时候我不应该不能使用打包信号?

Looking at some code I'm maintaining in System Verilog I see some signals that are defined like this:

node [range_hi:range_lo]x;

and others that are defined like this:

node y[range_hi:range_lo];

I understand that x is defined as packed, while y is defined as unpacked. However, I have no idea what that means.

What is the difference between packed and unpacked vectors in System Verilog?

Edit: Responding to @Empi's answer, why should a hardware designer who's writing in SV care about the internal representation of the array? Are there any times when I shouldn't or can't use packed signals?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

趁微风不噪 2024-07-19 03:35:26

本文提供了有关此问题的更多详细信息:
http://electricsofts.c​​om/systemverilog/arrays.html,尤其是第 5.2 节。

压缩数组是一种将向量细分为子字段的机制,这些子字段可以作为数组元素方便地访问。 因此,打包数组保证被表示为一组连续的位。 解包数组可能会也可能不会这样表示。 打包数组与未打包数组的不同之处在于,当打包数组作为主数组出现时,它被视为单个向量。

This article gives more details about this issue:
http://electrosofts.com/systemverilog/arrays.html, especially section 5.2.

A packed array is a mechanism for subdividing a vector into subfields which can be conveniently accessed as array elements. Consequently, a packed array is guaranteed to be represented as a contiguous set of bits. An unpacked array may or may not be so represented. A packed array differs from an unpacked array in that, when a packed array appears as a primary, it is treated as a single vector.

浮生未歇 2024-07-19 03:35:26

在了解打包和解包数组到底是什么之前,我们还可以看看如何仅通过它们的声明来知道哪个数组是什么。
压缩数组有一个对象名称,位于大小声明之后。 例如:

bit [3][7] a;

其中 a 是细分为 3 个 7 位子字段的 28 位向量。

解压数组的对象名称位于大小声明之前。 例如:

bit b [3];

其中 b 是 3 位宽的向量。

打包数组会占用内存,而未打包数组则不会。
您也可以像这样访问/声明未打包的数组。

reg unpacked_array [7:0] = '{0,0,0,0,0,0,0,1};

您也可以混合打包和未打包的数组来创建多维数组。 例如:

bit [3:0][7:0] a [2:0].

它创建一个4(即4*8)字节的数组,深度为3。

Before knowing what exactly packed and unpacked arrays are, lets also see how you can know which array is what, just by their declaration.
Packed arrays have an object name which comes after the size declaration. For example:

bit [3][7] a;

where a is a 28-bit vector subdivided into 3 7-bit subfields.

Unpacked arrays have an object name which comes before the size declaration. For example:

bit b [3];

where b is a 3-bit wide vector.

Packed arrays make memory whereas Unpacked don't.
You can access/declare unpacked arrays like this also

reg unpacked_array [7:0] = '{0,0,0,0,0,0,0,1};

You can mix both packed and unpacked array to make a multidimensional array. For example:

bit [3:0][7:0] a [2:0].

It makes an array of 4 (i.e. 4*8) bytes with depth of 3.

娜些时光,永不杰束 2024-07-19 03:35:26

当我们写入 [3:0][7:0]A[4:0] 时,压缩数组主要用于有效的内存使用,这意味着在 32 位内存位置中,每个 8 位的 4 个切片被打包形成一个 32 位。 右侧的值表示有 5 个这样的切片。

Packed array are mainly used for effective memory usage when we are writing a [3:0][7:0]A[4:0] which means in 32 bit memory locations 4slices each of 8 bit are packed to form a 32 bit. The right side value means there are 5 such slices are there.

你对谁都笑 2024-07-19 03:35:26

位[3:0] a -> 压缩数组
打包数组可以用作完整数组 (a='d1) 或仅数组的一部分 (a[0]='b1)

bit a [3:0] -> 解包数组
解压后的数组不能用作 a[0]='b1,它必须用作完整的 a={8{'b1}}

bit[3:0] a -> packed array
The packed array can be used as a full array (a='d1) or just part of an array (a[0]='b1)

bit a [3:0] -> unpacked array
The unpacked array cannot be used as a[0]='b1, it has to be used as full a={8{'b1}}

原来是傀儡 2024-07-19 03:35:26

验证学院给出了很好的解释。

n 向量 的压缩数组可以想象为单行 n 列的数组。

“n”向量和“m”的解压缩数组解压缩维度可以想象为 >n 列 m 行的矩阵/二维数组

A good explanation is given at verification academy.

A packed array of n vectors can be imagined as an array of single row and n columns.

Whereas an unpacked array of "n" vectors and "m" unpacked dimensions can be imagined as a matrix/2D array of n columns and m rows.

耳根太软 2024-07-19 03:35:26

与打包数组相比,未打包数组将为您提供更多编译时错误检查。

由于这个原因,我在模块的端口定义上看到了未打包的数组。 如果信号的维度与解包数组的端口不完全相同,编译器将出错。 对于打包数组,它通常会继续并尽可能地连接事物,而不会发出错误。

Unpacked arrays will give you more compile time error checking than packed arrays.

I see unpacked arrays on the port definitions of modules for this reason. The compiler will error if the dimensions of the signal are not exactly the same as the port with unpacked arrays. With packed arrays it will normally just go ahead and wire things the best it can, not issuing an error.

撧情箌佬 2024-07-19 03:35:26

位a [3:0] -> 解压数组 解压数组不能用作 a[0]='b1,它必须用作完整的 a={8{'b1}}

---> 在上面的语句中 a[0] ='b1; 将适用于解压数组,它不适用于 unpkd arry[例如逻辑 unpkd [8];] 的某些部分,如 unpkd = 5'h7; 分配同样适用于 pkd 数组
--> 解开PKD = 解开PKD +2; 不适用于 unpkd 将适用于 pkd

bit a [3:0] -> unpacked array The unpacked array cannot be used as a[0]='b1, it has to be used as full a={8{'b1}}

---> in above statement a[0] ='b1; will work for unpacked array , it won't work where some portion of the unpkd arry[eg logic unpkd [8];] like unpkd = 5'h7; assignment same will work for pkd array
--> unpkd = unpkd +2; won't wok for unpkd will work for pkd

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文