SystemVerilog foreach syntax for cycling through a lower dimensionality of a multidimensional array

What is the standard way to scroll through the lower dimension of a multidimensional array? With a larger fixed dimension.

In the following example:

  automatic int i = 2;
  foreach (my_req[i][j]) begin // <-- WARNING
    $display("i:%0d,j:%0d", i, j);
  end

I see a warning:

** Warning: testbench.sv(16): (vlog-LRM-2897) Using non-standard foreach loop variable list syntax.

Full sample EDA Playground code: http://www.edaplayground.com/x/nh

+4
source share
2 answers

You can do it:

$display("Loop through i=2");
begin
  automatic int i = 2;
  foreach (my_req[,j]) begin // notice the "," before j
    $display("i:%0d,j:%0d", i, j);
  end
end

Working code on the EDA playground: http://www.edaplayground.com/x/2Qn

+7
source

, , , . , - foreach (array[i][j]), i , foreach(array[i,j]), , .

foreach (my_req[,j])

+4

Source: https://habr.com/ru/post/1536967/


All Articles