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. Advertisements

  2. fl

    Rob Gaddi Guest

    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, Feb 26, 2013
    #2
    1. Advertisements

  3. fl

    GaborSzakacs Guest

    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

    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

    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

    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.