\$\begingroup\$
\$\endgroup\$
Suppose we have a 2d Systemverilog array declared as:
logic x [0:3][7:0] ;
- How can we use an attribute to get the width of the first dimension ?
- How can we use an attribute to get the width of the second dimension ?
- Is there an attribute equivalent to VHDL's "range" attribute ? I.E: one that'll return not the size but the actual range ( 0 to 3 ) or ( 7 down to 0 ) ?
asked May 30, 2020 at 10:31
1 Answer 1
\$\begingroup\$
\$\endgroup\$
2
The IEEE Std 1800-2017, section 20.7 Array query functions, describes all that you need:
module tb;
logic x [0:3][7:0] ;
initial begin
for (int i=1; i<=$dimensions(x); i++) begin
$display;
$display($size (x, i));
$display($left (x, i));
$display($right(x, i));
$display($low (x, i));
$display($high (x, i));
$display;
end
end
endmodule
Outputs:
4
0
3
0
3
8
7
0
0
7
See also System Tasks And Functions Part-II
answered May 30, 2020 at 16:21
-
\$\begingroup\$ Is IEEE Std 1800-2017 freely available ? If yes, where can it be download ? \$\endgroup\$shaiko– shaiko2020年05月30日 21:09:57 +00:00Commented May 30, 2020 at 21:09
-
1\$\begingroup\$ @shaiko Click on the IEEE Get Program \$\endgroup\$dave_59– dave_592020年05月31日 03:57:55 +00:00Commented May 31, 2020 at 3:57
lang-vhdl