1
\$\begingroup\$

Suppose we have a 2d Systemverilog array declared as:

logic x [0:3][7:0] ;
  1. How can we use an attribute to get the width of the first dimension ?
  2. How can we use an attribute to get the width of the second dimension ?
  3. 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
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ Is IEEE Std 1800-2017 freely available ? If yes, where can it be download ? \$\endgroup\$ Commented May 30, 2020 at 21:09
  • 1
    \$\begingroup\$ @shaiko Click on the IEEE Get Program \$\endgroup\$ Commented May 31, 2020 at 3:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.