Arrays 索引操作对SystemVerilog中的整数类型执行什么操作?

Arrays 索引操作对SystemVerilog中的整数类型执行什么操作?,arrays,indexing,system-verilog,Arrays,Indexing,System Verilog,我正在尝试将一些SystemVerilog代码移植到C++/SystemC,但在几行代码中,我看到了奇怪的数组索引。这是我看到的一个简化版本 typedef enum bit [2:0] {enu_red, enu_blue, enu_green} typ_enum; typedef struct packed { bit [3:0] field1; bit [3:0] field2; } typ_struct; ... var int arr_ints[typ_stru

我正在尝试将一些SystemVerilog代码移植到C++/SystemC,但在几行代码中,我看到了奇怪的数组索引。这是我看到的一个简化版本

typedef enum bit [2:0] {enu_red, enu_blue, enu_green} typ_enum; 

typedef struct packed {
    bit [3:0] field1;
    bit [3:0] field2;
} typ_struct;

...

var int arr_ints[typ_struct];
var int que_ints[$];

typ_struct obj_struct;
typ_enum   obj_enum;

int i = 3;

// assume all the declared variables hold valid values at this point
// also assume que_ints[i] is valid

if ((!arr_ints[obj_struct][1]) // these two lines are the problem
    && (que_ints[i][obj_struct])
)
begin
    // do something
end

现在,在我移植了这段代码之后,我得到了一些我完全理解的编译器错误,因为原始代码在我看来并不完全正确。在if语句的第一行中,它看起来像是试图用布尔值索引整型。在第二种情况下,它看起来像是试图用枚举值索引一个整数类型。然而,这个代码显然是有效的。有人能解释一下它在做什么吗?

这是整数类型的位切片。您将访问底层
int
表示的实际位

如果
que_ints[5]
为整数
0xdeadbeef
,则:

  • que_ints[5][3]
    为1
  • que_ints[5][7:4]
    0xe

在SystemC中,函数是必然结果。

arr\u ints
是一个类型为
int
的关联数组,其中用作键的类型是
typ\u struct

因此,
arr\u ints[obj\u struct]
将为您提供一个整数

使用
[n]
索引整数类型将得到索引n处的位

因此,
arr\u ints[obj\u struct][1]
将在
arr\u ints[obj\u struct]
处给出整数的第1位
关于第二行:

que_ints
是类型为
int
的队列

因此,
que_ints[i]
将给出队列中位置
i
处的整数


que_ints[i][obj_struct]
中,它会隐式地将枚举类型转换为一个整数值(实际上是位[2:0]),并在此基础上为您提供位索引。

什么是
true
定义的?我将true替换为1。在实际代码中,它是一个用作真/假布尔值的函数,但它是作为位实现的。我与C++等价物混合了,实际上使用了布尔类型的感谢,我没有意识到int可以隐式地像BIT /逻辑数组那样索引。