What is the difference of "array (63 downto 0) of ...." and "array (0to 63) of ...."

Discussion in 'VHDL' started by fl, Feb 26, 2013.

  1. fl

    fl Guest

    Hi,
    I know downto and to for one dimension array. I see the following definition in a file.
    But for two dimension array, what happens?

    ...................
    TYPE ram_type IS ARRAY (63 DOWNTO 0) of std_logic_vector(31 DOWNTO 0);
    ...................


    I want to know what is the difference between the above one with:

    ...................
    TYPE ram_type IS ARRAY (0 TO 63) of std_logic_vector(31 DOWNTO 0);
    ...................


    Thanks,
    fl, Feb 26, 2013
    #1
    1. Advertising

  2. fl

    Rob Gaddi Guest

    Re: What is the difference of "array (63 downto 0) of ...." and"array (0 to 63) of ...."

    On Tue, 26 Feb 2013 06:32:56 -0800 (PST)
    fl <> wrote:

    > Hi,
    > I know downto and to for one dimension array. I see the following definition in a file.
    > But for two dimension array, what happens?
    >
    > ..................
    > TYPE ram_type IS ARRAY (63 DOWNTO 0) of std_logic_vector(31 DOWNTO 0);
    > ..................
    >
    >
    > I want to know what is the difference between the above one with:
    >
    > ..................
    > TYPE ram_type IS ARRAY (0 TO 63) of std_logic_vector(31 DOWNTO 0);
    > ..................
    >
    >
    > Thanks,


    Probably nothing. Technically, this affects your ability to take
    slices of the RAM array, use shift operators, assign the array from
    concatenation results, etc. But practically, if you're using it as a
    RAM, you're only going to index one element of it at a time, and
    therefore you'll never notice any difference.

    --
    Rob Gaddi, Highland Technology -- www.highlandtechnology.com
    Email address domain is currently out of order. See above to fix.
    Rob Gaddi, Feb 26, 2013
    #2
    1. Advertising

  3. fl

    GaborSzakacs Guest

    Re: What is the difference of "array (63 downto 0) of ...." and "array(0 to 63) of ...."

    Rob Gaddi wrote:
    > On Tue, 26 Feb 2013 06:32:56 -0800 (PST)
    > fl <> wrote:
    >
    >> Hi,
    >> I know downto and to for one dimension array. I see the following definition in a file.
    >> But for two dimension array, what happens?
    >>
    >> ..................
    >> TYPE ram_type IS ARRAY (63 DOWNTO 0) of std_logic_vector(31 DOWNTO 0);
    >> ..................
    >>
    >>
    >> I want to know what is the difference between the above one with:
    >>
    >> ..................
    >> TYPE ram_type IS ARRAY (0 TO 63) of std_logic_vector(31 DOWNTO 0);
    >> ..................
    >>
    >>
    >> Thanks,

    >
    > Probably nothing. Technically, this affects your ability to take
    > slices of the RAM array, use shift operators, assign the array from
    > concatenation results, etc. But practically, if you're using it as a
    > RAM, you're only going to index one element of it at a time, and
    > therefore you'll never notice any difference.
    >

    Just one word of caution. If this is for synthesis, you should check
    with the tool providers for the suggested templates to infer RAM. I
    know that Xilinx XST is pretty finicky about how to infer block RAM
    for instance, and although it should make no difference, you may find
    that one works and another infers a lot of flip-flops.

    -- Gabor
    GaborSzakacs, Feb 26, 2013
    #3
  4. fl

    Andy Guest

    Re: What is the difference of "array (63 downto 0) of ...." and"array (0 to 63) of ...."

    On Tuesday, February 26, 2013 11:12:31 AM UTC-6, Rob Gaddi wrote:
    > On Tue, 26 Feb 2013 06:32:56 -0800 (PST) fl <> wrote: > Hi, > I know downto and to for one dimension array. I see the following definition in a file. > But for two dimension array, what happens? > > ................... > TYPE ram_type IS ARRAY (63 DOWNTO 0) of std_logic_vector(31 DOWNTO 0); > .................. > > > I want to know what is the difference between the above one with: > > .................. > TYPE ram_type IS ARRAY(0 TO 63) of std_logic_vector(31 DOWNTO 0); > .................. > > > Thanks, Probably nothing. Technically, this affects your ability to take slices of the RAM array, use shift operators, assign the array from concatenation results, etc. But practically, if you're using it as a RAM, you're only going to index one element of it at a time, and therefore you'll never notice any difference. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.


    Probably just semantics, but the index direction does not affect "whether" you can slice/shift/concatenate an array, but "how". Any reference to the range or subrange of an array must be in the same direction as the array's declaration.

    Just for my own preference, I use downto with SLV unless it is on an external interface that is explicitly declared with "to" direction. Note that when given a numeric interpretation (as in signed/unsigned types), the arithmetic MSB is the leftmost bit, not the highest numbered bit. If you are interfacing to a device bus that uses bit 0 as the MSB, then you would use "to" as the direction for that interface.

    You can assign between arrays (aka vectors) with different directions just fine. No matter what the direction, assignments are done left-right.

    Again, for my own preference, I usually use "to" direction for arrays of vectors or integers. This sometimes makes it easier to keep track of which index is which (for an array of SLV, etc.)

    Andy
    Andy, Feb 26, 2013
    #4
  5. fl

    Tricky Guest

    Re: What is the difference of "array (63 downto 0) of ...." and"array (0 to 63) of ...."

    Im going to be a little pedant.

    What you have is not a 2d array. Its a 1d array of 1d arrays. In the strong typing of VHDL, it can make a difference.
    Tricky, Feb 27, 2013
    #5
  6. fl

    Andy Guest

    Re: What is the difference of "array (63 downto 0) of ...." and"array (0 to 63) of ...."

    On Wednesday, February 27, 2013 9:38:08 AM UTC-6, Tricky wrote:
    > Im going to be a little pedant. What you have is not a 2d array. Its a 1d array of 1d arrays. In the strong typing of VHDL, it can make a difference.


    Even more pedantic, a true 2d array object can be assigned with an aggregate expression that describes an array of arrays. See the resolution_table constant in the reference package body for ieee.std_logic_1164.

    But you cannot assign a 2d array object to/from an object that is an array of arrays. Nor can you slice a 2d array.

    Go figure...

    Andy
    Andy, Feb 27, 2013
    #6
    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. jakk
    Replies:
    4
    Views:
    12,136
  2. Nick Timkovich
    Replies:
    0
    Views:
    68
    Nick Timkovich
    Feb 25, 2014
  3. Skip Montanaro
    Replies:
    0
    Views:
    64
    Skip Montanaro
    Feb 25, 2014
  4. Peter Otten
    Replies:
    1
    Views:
    73
    Mark Lawrence
    Feb 25, 2014
  5. Peter Otten
    Replies:
    0
    Views:
    64
    Peter Otten
    Feb 25, 2014
Loading...

Share This Page