Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > two-dimensional array, assign to zero, vhdl

Reply
Thread Tools

two-dimensional array, assign to zero, vhdl

 
 
--MMS--
Guest
Posts: n/a
 
      05-13-2007
How can I initialize/assign all the bits of a two-dimensional array to
zero?

Below is part of my code:
-----------------------------------------------------------------------
SUBTYPE tags IS std_logic_vector (16 DOWNTO 0);


TYPE entry IS RECORD
-- valid : BOOLEAN;
tag : tags;
data: std_logic_vector(31 downto 0);
END RECORD;


TYPE eachCache IS ARRAY (sets) OF entry;

Type elCache is array (INTEGER RANGE 0 TO 1) of eachCache;

TYPE ww IS ARRAY(ways) OF ways;

Signal cache : elCache;
-------------------------------------------------------------------------

Specifically, what I wish to know is how to set all bits of signal
"cache" to zero.
It apparently works if I do....

cache(w)(s).data <= (others => '0');

....but I would like to know if I can do something like that in the
same line were I declare the signal. I have tried many alternatives,
but have not get the solution yet.



Thanks in advance,
MMS

 
Reply With Quote
 
 
 
 
JK
Guest
Posts: n/a
 
      05-14-2007
On May 13, 10:58 pm, --MMS-- <(E-Mail Removed)> wrote:
> How can I initialize/assign all the bits of a two-dimensional array to
> zero?
>
> Below is part of my code:
> -----------------------------------------------------------------------
> SUBTYPE tags IS std_logic_vector (16 DOWNTO 0);
>
> TYPE entry IS RECORD
> -- valid : BOOLEAN;
> tag : tags;
> data: std_logic_vector(31 downto 0);
> END RECORD;
>
> TYPE eachCache IS ARRAY (sets) OF entry;
>
> Type elCache is array (INTEGER RANGE 0 TO 1) of eachCache;
>
> TYPE ww IS ARRAY(ways) OF ways;
>
> Signal cache : elCache;
> -------------------------------------------------------------------------
>
> Specifically, what I wish to know is how to set all bits of signal
> "cache" to zero.
> It apparently works if I do....
>
> cache(w)(s).data <= (others => '0');
>
> ...but I would like to know if I can do something like that in the
> same line were I declare the signal. I have tried many alternatives,
> but have not get the solution yet.
>
> Thanks in advance,
> MMS


type entry is record
tag : std_logic_vector(15 downto 0);
data : std_logic_vector(31 downto 0);
end record;
type eachCache is array(7 downto 0) of entry;
type elCache is array(1 downto 0) of eachCache;

signal cache : elCache;

process(reset, clock)
variable i, j : integer range 0 to 255;
begin
if reset='1' then
for i in elCache'range loop
for j in eachCache'range loop
cache(i)(j).tag <= (others => '0');
cache(i)(j).data <= (others => '0');
end loop;
end loop;
elsif rising_edge(clock) then
--bla bla bla
end if;
end process;

Regards,
JK

 
Reply With Quote
 
 
 
 
Colin Paul Gloster
Guest
Posts: n/a
 
      05-14-2007
--MMS-- <(E-Mail Removed)> posted:

"How can I initialize[..]?

[..]"

N.B. a synthesis tool might not support initialization.
 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      05-14-2007
--MMS-- wrote:

> How can I initialize/assign all the bits of a two-dimensional array to
> zero?
>
> Below is part of my code:
> -----------------------------------------------------------------------
> SUBTYPE tags IS std_logic_vector (16 DOWNTO 0);
>
>
> TYPE entry IS RECORD
> -- valid : BOOLEAN;
> tag : tags;
> data: std_logic_vector(31 downto 0);
> END RECORD;
>
>
> TYPE eachCache IS ARRAY (sets) OF entry;
>
> Type elCache is array (INTEGER RANGE 0 TO 1) of eachCache;
>
> TYPE ww IS ARRAY(ways) OF ways;
>
> Signal cache : elCache;
> -------------------------------------------------------------------------
>
> Specifically, what I wish to know is how to set all bits of signal
> "cache" to zero.
> It apparently works if I do....
>
> cache(w)(s).data <= (others => '0');
>
> ...but I would like to know if I can do something like that in the
> same line were I declare the signal. I have tried many alternatives,
> but have not get the solution yet.


Here is how it is done:

Signal cache : elCache :=
(
others =>
(
others =>
(
tag => (others => '0'),
data => (others => '0')
)
)
);

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.
 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      05-14-2007
On May 14, 4:55 am, Paul Uiterlinden <(E-Mail Removed)> wrote:
> --MMS-- wrote:
> > How can I initialize/assign all the bits of a two-dimensional array to
> > zero?

>
> > Below is part of my code:
> > -----------------------------------------------------------------------
> > SUBTYPE tags IS std_logic_vector (16 DOWNTO 0);

>
> > TYPE entry IS RECORD
> > -- valid : BOOLEAN;
> > tag : tags;
> > data: std_logic_vector(31 downto 0);
> > END RECORD;

>
> > TYPE eachCache IS ARRAY (sets) OF entry;

>
> > Type elCache is array (INTEGER RANGE 0 TO 1) of eachCache;

>
> > TYPE ww IS ARRAY(ways) OF ways;

>
> > Signal cache : elCache;
> > -------------------------------------------------------------------------

>
> > Specifically, what I wish to know is how to set all bits of signal
> > "cache" to zero.
> > It apparently works if I do....

>
> > cache(w)(s).data <= (others => '0');

>
> > ...but I would like to know if I can do something like that in the
> > same line were I declare the signal. I have tried many alternatives,
> > but have not get the solution yet.

>
> Here is how it is done:
>
> Signal cache : elCache :=
> (
> others =>
> (
> others =>
> (
> tag => (others => '0'),
> data => (others => '0')
> )
> )
> );
>
> --
> Paul Uiterlindenwww.aimvalley.nl
> e-mail addres: remove the not.


Is there some reason why (others => (others => (others => (others =>
'0')))) does not work?

Andy

 
Reply With Quote
 
Paul Uiterlinden
Guest
Posts: n/a
 
      05-14-2007
Andy wrote:

> On May 14, 4:55 am, Paul Uiterlinden <(E-Mail Removed)> wrote:
>> Here is how it is done:
>>
>> Signal cache : elCache :=
>> (
>> others =>
>> (
>> others =>
>> (
>> tag => (others => '0'),
>> data => (others => '0')
>> )
>> )
>> );
>>

>
> Is there some reason why (others => (others => (others => (others =>
> '0')))) does not work?


Because the lengths of tag and data differ. As far as I know, others can
only be used on arrays (array aggregates) and records (record aggregates).
The latter will only work if the type and length of the all record member
are the same. That is at least my understanding.

Indeed, modelsim reports an error on your code: 'Length of formal "data" is
32; length of actual is 17'. (tags was defined as slv(16 downto 0) and data
was defined as slv(31 downto 0)).

I can see the logic in that error message.

What would your code supposed to do if there was another record member with
type boolean, or even another record type?

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.
 
Reply With Quote
 
JK
Guest
Posts: n/a
 
      05-15-2007
On May 15, 2:57 am, Paul Uiterlinden <(E-Mail Removed)> wrote:
>
> > Is there some reason why (others => (others => (others => (others =>
> > '0')))) does not work?

>
> Because the lengths of tag and data differ. As far as I know, others can
> only be used on arrays (array aggregates) and records (record aggregates).
> The latter will only work if the type and length of the all record member
> are the same. That is at least my understanding.
>


Oh. Thanx Paul.

Regards,
JK

 
Reply With Quote
 
--MMS--
Guest
Posts: n/a
 
      05-15-2007
THANKS!!!

On May 14, 5:55 am, Paul Uiterlinden <(E-Mail Removed)> wrote:

>
> Here is how it is done:
>
> Signal cache : elCache :=
> (
> others =>
> (
> others =>
> (
> tag => (others => '0'),
> data => (others => '0')
> )
> )
> );
>
> --
> Paul Uiterlindenwww.aimvalley.nl
> e-mail addres: remove the not.- Hide quoted text -


 
Reply With Quote
 
Andy
Guest
Posts: n/a
 
      05-15-2007
On May 14, 4:57 pm, Paul Uiterlinden <(E-Mail Removed)> wrote:
> What would your code supposed to do if there was another record member with
> type boolean, or even another record type?


Well it would not work in that case. I assumed that if all record
elements were of the same type, they need not be the same length,
since each is statically determinable. Bad assumption apparently!

Thanks,

Andy

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign default values to generated VHDL signals sapiendesign Hardware 0 09-15-2011 10:13 PM
VHDL-2002 vs VHDL-93 vs VHDL-87? afd VHDL 1 03-23-2007 09:33 AM
VHDL assign multiple concatenated signals veevee1 VHDL 0 03-07-2007 11:26 AM
multiD-vhdl: Multi Dimensional Arrays (allowing generics on each dimension) for VHDL (including ports) albert.neu@gmail.com VHDL 2 03-21-2006 04:05 PM
what's the difference between VHDL 93 CONCATENATION and VHDL 87 CONCATENATION? walala VHDL 3 09-18-2003 04:17 AM



Advertisments