Concatenation operator (&) in VHDL - Time & Space Complexity
We want to understand how the time needed to join signals or vectors grows as their size increases in VHDL.
How does using the concatenation operator (&) affect execution time when combining data?
Analyze the time complexity of the following code snippet.
signal A : std_logic_vector(7 downto 0);
signal B : std_logic_vector(7 downto 0);
signal C : std_logic_vector(15 downto 0);
C <= A & B;
This code concatenates two 8-bit vectors A and B into one 16-bit vector C.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Copying each bit from A and B into C using concatenation.
- How many times: Once per bit in A and once per bit in B, so total bits copied equals the sum of their lengths.
As the size of the vectors grows, the number of bits copied grows proportionally.
| Input Size (bits) | Approx. Operations (bit copies) |
|---|---|
| 10 | 20 |
| 100 | 200 |
| 1000 | 2000 |
Pattern observation: Doubling the input size doubles the number of bit copy operations.
Time Complexity: O(n)
This means the time to concatenate grows linearly with the total number of bits being joined.
[X] Wrong: "Concatenation happens instantly no matter how big the vectors are."
[OK] Correct: Each bit must be copied to form the new vector, so larger vectors take more time.
Understanding how concatenation scales helps you reason about signal assignments and data handling in hardware design.
"What if we concatenate three vectors instead of two? How would the time complexity change?"