Aggregate assignment in VHDL - Time & Space Complexity
We want to understand how the time it takes to run aggregate assignments changes as the size of the data grows.
Specifically, how does assigning many values at once affect execution time?
Analyze the time complexity of the following code snippet.
signal my_vector : std_logic_vector(7 downto 0);
-- Aggregate assignment
my_vector <= (7 => '1', others => '0');
This code assigns a value to each bit of an 8-bit vector using an aggregate assignment.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Assigning each element of the vector individually.
- How many times: Once for each element in the vector (8 times here).
When the vector size grows, the number of assignments grows the same way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 assignments |
| 100 | 100 assignments |
| 1000 | 1000 assignments |
Pattern observation: The work grows directly with the number of elements; doubling elements doubles the work.
Time Complexity: O(n)
This means the time to assign values grows in a straight line with the number of elements.
[X] Wrong: "Aggregate assignment happens instantly no matter the size."
[OK] Correct: Each element must be assigned, so bigger vectors take more time.
Understanding how aggregate assignments scale helps you reason about hardware design efficiency and timing.
"What if we used a smaller subset of the vector in the assignment? How would the time complexity change?"