Gate-level delay annotation in Verilog - Time & Space Complexity
When we add delays to gates in Verilog, it affects how long signals take to change.
We want to see how these delays impact the total time as the design grows.
Analyze the time complexity of this gate-level delay example.
module delay_example(input a, b, c, output y);
wire w1, w2;
and #2 (w1, a, b); // 2 time units delay
or #3 (w2, w1, c); // 3 time units delay
not #1 (y, w2); // 1 time unit delay
endmodule
This code models a small circuit where each gate has a fixed delay before output changes.
Look for parts that repeat or grow with input size.
- Primary operation: Each gate's delay adds up in sequence.
- How many times: Number of gates in the path determines total delay.
As you add more gates in a chain, delays add up one after another.
| Input Size (number of gates) | Approx. Total Delay (time units) |
|---|---|
| 3 | 6 (2+3+1) |
| 10 | About 20 (sum of delays of 10 gates) |
| 100 | About 200 (sum of delays of 100 gates) |
Pattern observation: Total delay grows roughly in a straight line as gates increase.
Time Complexity: O(n)
This means the total delay grows directly with the number of gates in the signal path.
[X] Wrong: "Adding more gates won't increase delay much because they work fast."
[OK] Correct: Each gate adds its delay one after another, so more gates mean more total delay.
Understanding how delays add up helps you design circuits that run efficiently and meet timing needs.
"What if some gates had zero delay? How would that change the total delay as the number of gates grows?"
Practice
Solution
Step 1: Understand gate-level delay annotation
Gate-level delay annotation is used to add timing delays to logic gates in simulation.Step 2: Identify its purpose
This delay models the real-world time it takes for signals to propagate through gates, helping verify timing correctness.Final Answer:
To specify the time delay for signal propagation through a gate -> Option CQuick Check:
Gate delay = specify propagation time [OK]
- Confusing delay annotation with variable declaration
- Thinking delay sets input/output ports
- Assuming delay initializes registers
Solution
Step 1: Recall Verilog gate delay syntax
The delay is specified immediately after the gate type using #delay without parentheses.Step 2: Match correct syntax
and #5 (out, in1, in2); uses 'and #5 (out, in1, in2);' which is the correct form.Final Answer:
and #5 (out, in1, in2); -> Option BQuick Check:
Delay after gate type with #number [OK]
- Using parentheses around delay value
- Placing delay after port list
- Writing delay as a function call
out changes after in1 or in2 changes?and #3 (out, in1, in2);
Solution
Step 1: Identify the delay annotation
The code uses '#3' after the 'and' gate, indicating a 3-time-unit delay.Step 2: Understand delay effect
This means output changes occur 3 time units after input changes.Final Answer:
3 time units -> Option DQuick Check:
Delay #3 means 3 time units [OK]
- Assuming delay is zero if not explicitly stated
- Confusing delay with input change time
- Choosing wrong delay value
or (out, in1, in2) #4;
Solution
Step 1: Check delay placement
Delay must come immediately after the gate type, not after the port list.Step 2: Analyze given code
The code places '#4' after the port list, which is incorrect syntax.Final Answer:
Delay must be specified immediately after gate type, not after port list -> Option AQuick Check:
Delay after gate type, not ports [OK]
- Putting delay after port list
- Using invalid gate names
- Wrong port list syntax
Solution
Step 1: Understand Verilog rise/fall delay syntax
Verilog allows specifying rise and fall delays as #(rise, fall) after the gate type.Step 2: Match delays to correct order
The first number is rise delay, second is fall delay, so #(2,4) means 2 units rise, 4 units fall.Final Answer:
and #(2,4) (out, in1, in2); -> Option AQuick Check:
Use #(rise, fall) for different delays [OK]
- Reversing rise and fall values
- Using multiple # delays separately
- Incorrect syntax with multiple #
Ready to prove it?
Pass the test and this pattern moves unknown
