8
votes

I have four std_logic_vectors (15 downto 0) and want to stack them into a std_logic_vector (63 downt 0) so fare I have found one way of doing it but is it the correct way or is there a more optimal and correct way to do it?

signal slv16_1,slv16_2,slv16_3,slv16_4 : std_logic_vector(15 downto 0);
signal slv64 : std_logic_vector(63 downto 0);

slv64(15 downto 0) <= slv16_1;
slv64(31 downto 16) <= slv16_2;
slv64(47 downto 32) <= slv16_3;
slv64(63 downto 48) <= slv16_4;
3
Maybe VHDL aliases are an alternative to you. An alias can be used to give parts of your 64bit vector a new name, while all operations are performed on the original signal.Paebbels
Thanks that a nice way to solve the problem.Mathias

3 Answers

13
votes

An easy way to accomplish this is to use the concatenation operator &. It achieves the same thing you did above, but with less code required.

slv64 <= slv16_4 & slv16_3 & slv16_2 & slv16_1;
2
votes

Since the source vectors have unique names, I don't see a way to automate this. What you might be able to try is to never use the 16-bit vectors, and instead use slices of the larger 64 bit vector. So instead of an assignment like this:

slv16_1 <= "0101110000111010";

Use

slv64(15 downto 0) <= "0101110000111010";

Or instead of an entity instantiation where you connect slv16_2 like this:

output_port => slv16_2,

Use

output_port => slv64(31 downto 16),

I would really need to see more of your code to understand what might work best, but my basic answer is 'use the larger vector in the first place'.

If you can't do this for some reason, an alternative would be to declare your 16-bit vectors as an array of arrays:

type slv16_array_type is array (integer range <>) of std_logic_vector(15 downto 0);
signal slv16_array : slv16_array_type(3 downto 0);

You could then assign to the elements like this:

slv16_array(0) <= "0101";

You could combine the elements of this type with a generate loop:

slv16_combine : for i in 0 to 3 generate
  slv64((16*(i+1))-1 downto 16*i) <= slv16_array(i);
end generate;
1
votes

VHDL guide says that this one should work:

slv64 <= (slv16_4, slv16_3, slv16_2, slv16_1);