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

F

fl

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,
 
R

Rob Gaddi

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

GaborSzakacs

Rob said:
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
 
A

Andy

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
 
T

Tricky

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

Andy

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
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top