为什么我应该在 System Verilog 中使用解包向量?

发布于 2024-07-13 08:15:35 字数 376 浏览 8 评论 0原文

跟进 关于 SV 中打包向量和未打包向量之间差异的问题,为什么我要使用未打包向量?
压缩向量具有解压缩向量所没有的优点:

  • 您可以对它们执行按位运算
  • 您可以对它们执行算术运算
  • 您可以对它们进行切片
  • 您可以将它们复制为整个向量
  • 您可以使用它们做任何事情未打包的向量(据我所知)

未打包的向量相对于打包的向量有什么优势?

Following up on this question about the difference between packed and unpacked vectors in SV, why would I ever want to use unpacked vectors?
Packed vectors have these advantages that unpacked vectors don't have:

  • You can perform bit-wise operations on them
  • You can perform arithmetic operations on them
  • You can take slices of them
  • You can copy them as a whole vector
  • You can do anything you can with unpacked vectors (to the best of my knowledge)

What advantage do unpacked vectors have over packed vectors?

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

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

发布评论

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

评论(2

久夏青 2024-07-20 08:15:35

我喜欢使用 unpacked 还有一个原因。 通过解包,就不会出现将整个数组名称视为变量并进行错误赋值的诱惑(也不会出现意外的可能性)。 当您可能认为正在访问元素 N 的 B 位,但实际上您可能正在访问元素 N 的 K 位和元素 N+-1 的 BK 位时,也不存在从一个元素到另一个元素的位泄漏的可能性。 。

我的理念是只将属于在一起的事物作为“信息单元”保留在打包维度中 未压缩维度中的其他所有内容。 默认思维应该是解包,只打包你需要的东西。

例如,如果我有 9 个端口,每个端口有 21 位信息,我想将其声明为:

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

20:0 部分构成一个信息单元,一起分配和采样(名义上)。 将这些位分开会破坏协议或端口的特性。 另一方面,将端口数量从 9 个更改为 16 个,不会影响每个端口中信息的性质,因此在我看来,9 个端口确实属于未打包维度。

希望这能给你一个思考的范式......在这个范式中,你会惊讶地发现有多少你一直认为已经包装好的东西开始出现未包装的!!

There is another reason why I like to use unpacked. With unpacked, there is no temptation (and accidental possibility) of treating the whole array name as a variable, and make an erroneous assignment. There is also no possibility of bit-bleeding from one element to another, when you may be thinking you are accessing B bits of element N, but in reality you may be accessing K bits of element N and B-K bits of element N+-1..

My philosophy is to keep only the things that belong together as a "unit of information" in the packed dimension. Everything else in the unpacked dimension. The default thinking should be unpacked, and pack only what you need to.

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

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

The 20:0 part constitutes a unit of information, assigned and sampled together (nominally). Splitting those bits apart will destroy the protocol or the character of the port. On the other hand, changing the number of ports from 9 to, say, 16, is not going to affect the nature of the information in each port, so the 9 ports really belong in the unpacked dimension in my mind.

Hope that might give you a paradigm to think along... In this paradigm, you would be surprised how many things start to appear unpacked that you always thought were packed !!

儭儭莪哋寶赑 2024-07-20 08:15:35

解压数组的存在有几个原因。

1) 压缩数组作为连续的位序列存储在内存中。 解包数组可以独立存储每个元素,这可以产生更高的模拟性能。

2) 解包数组可以是非位向量的类型。 整数、字节、事件、结构、类等数组只能被解包。

3) 大多数数组操作方法仅适用于解包数组。

4)也许,只有解压缩的数组才能使用数组文字进行分配。 我不知道。

可能还有其他原因。

Unpacked arrays exist for several reasons.

1) Packed arrays are stored in memory as a continuous sequence of bits. Unpacked arrays can have each element stored independently which can yield greater simulation performance.

2) Unpacked arrays can be of types that aren't bit vectors. Arrays of ints, bytes, events, structs, classes, etc. can only be unpacked.

3) Most of the array manipulation methods only work on unpacked arrays.

4) Perhaps, only unpacked arrays can be assigned to using array literals. I'm not sure.

There may be other reasons.

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