返回介绍

23.7 数组查询系统函数

发布于 2020-09-09 22:55:57 字数 3514 浏览 986 评论 0 收藏 0

array_query_function ::=                  // not in Annex A
    array_dimension_function(array_identifier, dimension_expression)
  | array_dimension_function(type_identifier[, dimension_expression])
  | $dimensions(array_identifier)
  | $dimensions(type_identifier)

array_dimension_function ::=
    $left
  | $right
  | $low
  | $high
  | $increment
  | $size

dimension_expression ::= expression

Syntax 23-5—Array querying function syntax (not in Annex A)

SystemVerilog provides system functions to return information about a particular dimension of an array variable or type. The return type is integer, and the default for the optional dimension expression is 1. The array dimension can specify any fixed sized index (packed or unpacked), or any dynamically sized index (dynamic, associative, or queue).

  • $left shall return the left bound (msb) of the dimension
  • $right shall return the right bound (lsb) of the dimension
  • $low shall return the minimum of $left and $right of the dimension
  • $high shall return the maximum of $left and $right of the dimension
  • $increment shall return 1 if $left is greater than or equal to $right, and -1 if $left is less than $right
  • $size shall return the number of elements in the dimension, which is equivalent to $high - $low + 1
  • $dimensions shall return the number of dimensions in the array, or 0 for a singular object
The dimensions of an array shall be numbered as follows: The slowest varying dimension (packed or unpacked) is dimension 1. Successively faster varying dimensions have sequentially higher dimension numbers. Intermediate type definitions are expanded first before numbering the dimensions.

For example:

//     Dimension numbers
//    3    4       1    2
reg [3:0][2:1] n [1:5][2:8];
typedef reg [3:0][2:1] packed_reg;
packed_reg n[1:5][2:8]; // same dimensions as in the lines above

For a fixed sized integer type (integer, shortint, longint, and byte), dimension 1 is pre-defined. For an integer N declared without a range specifier, its bounds are assumed to be [$bits(N)-1:0].

If an out-of-range dimension is specified, these functions shall return a ’x.

When used on a dynamic array or queue dimension, these functions return information about the current state of the array. If the dimension is currently empty, these functions shall return a ’x. It is an error to use these functions directly on a dynamically sized type identifier.

Use on associative array dimensions is restricted to index types with integral values. With integral indexes, these functions shall return:

  • $left shall return 0
  • $right shall return the highest possible index value
  • $low shall return the lowest currently allocated index value
  • $high shall return the largest currently allocated index value
  • $increment shall return -1
  • $size shall return the number of elements currently allocated
If the array identifier is a fixed sized array, these query functions can be used as a constant function and passed as a parameter before elaboration. These query functions can also be used on fixed sized type identifiers in which case it is always treated as a constant function.

Given the declaration below:

typedef logic [16:1] Word;
Word Ram[0:9];

The following system functions return 16:

$size(Word)
$size(Ram,2)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文