我是SystemVerilog的新手。我开始从该网站学习。我阅读了以下示例,但不了解结果。
//EXAMPLE: arrays
module arr;
bit [2:0][3:0] arr [4:0][5:0];
initial
begin
$display(" $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",$left(arr),$right(arr),$low(arr),$high(arr),$increment(arr),$size(arr),$dimensions(arr) );
end
endmodule
结果:
$ left 4 $ right 0 $ low 0 $ high 4 $ increment 1 $ size 5 $ dimensions 4
请说明结果。
SystemVerilog多维数组具有两种类型的维:packed和unpacked。可以有任意数量的打包尺寸(写在变量名之前)和任意数量的未打包尺寸(写在变量名之后)。尺寸从1(从左到右)编号,首先是未包装的尺寸。因此,在对数组的元素建立索引时,第一个未打包的维将成为最高有效索引(最先写入),而最后一个打包的维将成为最低有效索引(最后写入),从而导致奇怪的排序。这并不像它最初看起来那样愚蠢,因为可以将打包尺寸的索引留在列表的末尾。
因此,在您的示例中,尺寸的编号如下所示:
bit [2:0][3:0] arr [4:0][5:0];
3 4 1 2
System Verilog中具有以下阵列查询功能:
$left/$right(arrayname, dimension) – returns the left or right bound
$low/$high(arrayname, dimension) – returns the lowest or highest bound
$increment(arrayname, dimension) – returns 1 if $left >= $right and -1 otherwise
$size(arrayname, dimension) – returns the number of elements of the given dimension
$dimensions(arrayname) – returns the number of dimensions
$unpacked_dimensions(arrayname) – returns the number of unpacked dimensions
当您调用系统函数(例如$left
未指定您要表示的维数)时,它默认为维1。系统功能正在输出尺寸1的值,因为未指定尺寸。您也可以在这些系统功能中指定尺寸。因此,此代码:
module arr;
bit [2:0][3:0] arr [4:0][5:0];
initial begin
$display(" DIMENSION 1 (the default) : $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",
$left(arr),$right(arr),$low(arr),$high(arr),$increment(arr),$size(arr),$dimensions(arr) );
$display(" DIMENSION 1 (specified) : $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",
$left(arr,1),$right(arr,1),$low(arr,1),$high(arr,1),$increment(arr,1),$size(arr,1),$dimensions(arr) );
$display(" DIMENSION 2 (specified) : $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",
$left(arr,2),$right(arr,2),$low(arr,2),$high(arr,2),$increment(arr,2),$size(arr,2),$dimensions(arr) );
$display(" DIMENSION 3 (specified) : $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",
$left(arr,3),$right(arr,3),$low(arr,3),$high(arr,3),$increment(arr,3),$size(arr,3),$dimensions(arr) );
$display(" DIMENSION 4 (specified) : $left %0d $right %0d $low %0d $high %0d $increment %0d $size %0d $dimensions %0d",
$left(arr,4),$right(arr,4),$low(arr,4),$high(arr,4),$increment(arr,4),$size(arr,4),$dimensions(arr) );
end
endmodule
http://www.edaplayground.com/x/4NzY
输出此:
DIMENSION 1 (the default) : $left 4 $right 0 $low 0 $high 4 $increment 1 $size 5 $dimensions 4
DIMENSION 1 (specified) : $left 4 $right 0 $low 0 $high 4 $increment 1 $size 5 $dimensions 4
DIMENSION 2 (specified) : $left 5 $right 0 $low 0 $high 5 $increment 1 $size 6 $dimensions 4
DIMENSION 3 (specified) : $left 2 $right 0 $low 0 $high 2 $increment 1 $size 3 $dimensions 4
DIMENSION 4 (specified) : $left 3 $right 0 $low 0 $high 3 $increment 1 $size 4 $dimensions 4
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句