two-dimensional array, assign to zero, vhdl

Discussion in 'VHDL' started by --MMS--, May 13, 2007.

  1. --MMS--

    --MMS-- Guest

    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
    --MMS--, May 13, 2007
    #1
    1. Advertising

  2. --MMS--

    JK Guest

    On May 13, 10:58 pm, --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.
    >
    > 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
    JK, May 14, 2007
    #2
    1. Advertising

  3. --MMS-- <> posted:

    "How can I initialize[..]?

    [..]"

    N.B. a synthesis tool might not support initialization.
    Colin Paul Gloster, May 14, 2007
    #3
  4. --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.
    Paul Uiterlinden, May 14, 2007
    #4
  5. --MMS--

    Andy Guest

    On May 14, 4:55 am, Paul Uiterlinden <> 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
    Andy, May 14, 2007
    #5
  6. Andy wrote:

    > On May 14, 4:55 am, Paul Uiterlinden <> 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.
    Paul Uiterlinden, May 14, 2007
    #6
  7. --MMS--

    JK Guest

    On May 15, 2:57 am, Paul Uiterlinden <> 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
    JK, May 15, 2007
    #7
  8. --MMS--

    --MMS-- Guest

    THANKS!!! :)

    On May 14, 5:55 am, Paul Uiterlinden <> 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 -
    --MMS--, May 15, 2007
    #8
  9. --MMS--

    Andy Guest

    On May 14, 4:57 pm, Paul Uiterlinden <> 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
    Andy, May 15, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alf P. Steinbach
    Replies:
    0
    Views:
    422
    Alf P. Steinbach
    Aug 18, 2003
  2. John Harrison
    Replies:
    4
    Views:
    6,913
    Default User
    Aug 19, 2003
  3. Icosahedron
    Replies:
    8
    Views:
    638
    Vivek
    Aug 21, 2003
  4. Venkat
    Replies:
    4
    Views:
    961
    Venkat
    Dec 5, 2003
  5. Kenneth Brody

    Two-dimensional array to array of arrays

    Kenneth Brody, Dec 21, 2006, in forum: C Programming
    Replies:
    2
    Views:
    496
    Simon Biber
    Dec 21, 2006
Loading...

Share This Page