gpt4 book ai didi

verilog - 分析 SystemVerilog 中的打包结构以确定它的大小?

转载 作者:行者123 更新时间:2023-12-05 01:36:12 26 4
gpt4 key购买 nike

在 SystemVerilog 中有没有一种方法可以分析压缩结构并确定它的整体大小(以位为单位)?

typedef struct packed unsigned {
logic [15:0] field_1;
logic [7:0] field_2;
logic [15:0] field_3;
logic [4:0] field_4;
} my_struct;

例如,我希望能够以编程方式确定上述结构的大小为 45。

我查看了 IEEE 1800-2012 SystemVerilog Language Reference Manual 的“聚合数据类型”部分(第 7 章)。 ,并没有看到类似的东西。

这可能吗?如果有,怎么做?

最佳答案

使用 IEEE 1800-2012 中的 $bits() § 20.6.2 表达式大小系统函数:

The $bits system function returns the number of bits required to hold an expression as a bit stream.

来自 LRM 的直接示例:

... Given the declaration:

typedef struct {
logic valid;
bit [8:1] data;
} MyType;

the expression $bits(MyType) shall return 9, the number of data bits needed by a variable of type MyType.

关于verilog - 分析 SystemVerilog 中的打包结构以确定它的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22411102/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com