Generate with 2-Dimensional array

V

Ved

Hi all,
I have problem in assigning 2 dimensional array column to an array in
generate statement.
I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
2-D array) and give it to a component which is to be generated 16
times.
I am confused in assigning a column array of 2D array to a 1D
array(simple array) inside a GENERATE statement.
I hope explanation is clear ?
I have tried to do something (please see codes below).
How to use a for loop inside generate.
Textbooks and internet resources are not very clear about.
Please correct me.
Thanks
Regards
Ved

------Data types---------
MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
---I am calling this Matrix

comp_caseSel --> array (0 to 7) of integer range 0 to 8;
---- I am calling this 1D array

countArray ---> array (0 to 15) of integer range 0 to 8 ;

-------------------------------

entity is
Matrix2D : in MatrixInt;
WordIndexCase: out countArray;
end entity

architecture......

component Comp_Metric is
port(
IndexCOL : in comp_caseSel;
WordIndexCase_c: out integer range 0 to 8
);
end component;
begin

gen: for i in 0 to 15 generate ---Generate 16 times
for j in 0 to M-1 loop
compx: Comp_Metric
port map(
IndexCOL => Matrix2D(j,i), ---What to do here ??
----1D array <=
clolumn of 2D
WordIndexCase_c => WordIndexCase(i)
);
end loop;
end generate;
 
D

David Ashley

Ved said:
Hi all,
I have problem in assigning 2 dimensional array column to an array in
generate statement.
I have to take out columns(array of 8 elements) from 8x16 matrix (i.e.
2-D array) and give it to a component which is to be generated 16
times.
I am confused in assigning a column array of 2D array to a 1D
array(simple array) inside a GENERATE statement.
I hope explanation is clear ?
I have tried to do something (please see codes below).
How to use a for loop inside generate.
Textbooks and internet resources are not very clear about.
Please correct me.
Thanks
Regards
Ved

------Data types---------
MatrixInt ---> array (0 to 7 , 0 to 15) of integer range 0 to 8;
---I am calling this Matrix

comp_caseSel --> array (0 to 7) of integer range 0 to 8;
---- I am calling this 1D array

countArray ---> array (0 to 15) of integer range 0 to 8 ;

-------------------------------

entity is
Matrix2D : in MatrixInt;
WordIndexCase: out countArray;
end entity

architecture......

component Comp_Metric is
port(
IndexCOL : in comp_caseSel;
WordIndexCase_c: out integer range 0 to 8
);
end component;
begin

gen: for i in 0 to 15 generate ---Generate 16 times
for j in 0 to M-1 loop
compx: Comp_Metric
port map(
IndexCOL => Matrix2D(j,i), ---What to do here ??
----1D array <=
clolumn of 2D
WordIndexCase_c => WordIndexCase(i)
);
end loop;
end generate;

Ved,

I've not used generate or loop myself yet, but it seems to me
the loop should also be a generate.

-Dave
 
N

Nicolas Matringe

David Ashley a écrit :
Ved,

I've not used generate or loop myself yet, but it seems to me
the loop should also be a generate.

Indeed.
You can't have a loop outside of a process.

Nicolas
 
A

Andy

In addition to fixing the generate vs loop issue, try an array of
arrays, instead of a two dimensional array. Two dimensional arrays are
not usually synthesizable, but arrays of arrays of... are. That way an
element of the outer array is an array itself, and can be assigned
to/from a single array. The only thing you cannot do is slice it the
other way (i.e. automatically create/reference an array consisting of
the nth element of all arrays).

Hope this helps.

Andy
 
D

David R Brooks

Andy said:
In addition to fixing the generate vs loop issue, try an array of
arrays, instead of a two dimensional array. Two dimensional arrays are
not usually synthesizable, but arrays of arrays of... are. That way an
element of the outer array is an array itself, and can be assigned
to/from a single array. The only thing you cannot do is slice it the
other way (i.e. automatically create/reference an array consisting of
the nth element of all arrays).

But you can easily write a function that does that :)
 
V

Ved

Hi,
Generate and process didn't help.

Andy, what is difference between 2d-array and Array of array ?

Ved
 
S

smithodude

Think you should use another nested 'generate'. I've done this in the
past and it works. I have also synthesised arbitrary sized 2
dimensional arrays of std_logic without a problem. Not sure about
integers though

begin

gen: for i in 0 to 15 generate ---Generate 16 times
gen2 : for j in 0 to M-1 generate
compx: Comp_Metric
port map(
IndexCOL => Matrix2D(j,i), ---What to do here ??
----1D array <=
clolumn of 2D
WordIndexCase_c => WordIndexCase(i)
);
end generate;
end generate;
 
A

Andy

An array of arrays is declared as follows:

type row_t is array (0 to 7) of integer range 0 to 8;
type matrix_t is array (0 to 15) of row_t;

signal matrix : matrix_t;

Then matrix(i) is ith row (of type row_t), matrix(i)(j) is jth element
of ith row.

You can assign, alias, or reference an entire row, or range of entire
rows:
matrix(3) or matrix(4 to 9)

You can assign, alias, or reference an element or range of elements
within one row:
matrix(11)(2) or matrix(11)(0 to 3).

But you can't do something like (without a function):
matrix(7 to 11)(14)

Andy
 
V

Ved

Thnaks Andy,
It worked.
An array of arrays is declared as follows:

type row_t is array (0 to 7) of integer range 0 to 8;
type matrix_t is array (0 to 15) of row_t;

signal matrix : matrix_t;

Then matrix(i) is ith row (of type row_t), matrix(i)(j) is jth element
of ith row.

You can assign, alias, or reference an entire row, or range of entire
rows:
matrix(3) or matrix(4 to 9)

You can assign, alias, or reference an element or range of elements
within one row:
matrix(11)(2) or matrix(11)(0 to 3).

But you can't do something like (without a function):
matrix(7 to 11)(14)

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top