8

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;
2
  • 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. Commented Oct 14, 2015 at 21:44
  • Thanks that a nice way to solve the problem. Commented Oct 15, 2015 at 14:02

3 Answers 3

16

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;
Sign up to request clarification or add additional context in comments.

1 Comment

VHDL-2008 also support aggregates comprised of slices of elements as well as elements of the array base type. There are corner cases where using an aggregate can overcome overload resolution ambiguity for the concatenation operator while aggregation is a basic operation.
2

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;

Comments

1

VHDL guide says that this one should work:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.