Lectures 1 to 9 in about 60 minutes, questions included. Each lecture is one card: the idea, why it works, the move for its main exam problem, the usual trap, and three questions that make you apply it to something new.
L1The digital abstraction
Every device accepts a sloppy input and must produce a cleaner output, so noise never builds up.
Why it works
Wires add noise. If outputs were only as good as inputs, errors would grow through every stage.
So outputs are held to a stricter standard than inputs. That needs four thresholds, in the order VOL < VIL < VIH < VOH.
The gap between the output rule and the input rule is noise you can survive.
A device that restores signals needs gain. A plain wire has none, so it cannot be a digital device.
Low
Forbidden zone
High
Output must be
≤ VOL
never, once settled
≥ VOH
Input is accepted if
≤ VIL
no promise
≥ VIH
Noise margin
VIL − VOL
VOH − VIH
The move: check a device or pick thresholds
Check the order of the four thresholds. Wrong order means not a legal choice.
For every valid input (≤ VIL or ≥ VIH), check the output is valid (≤ VOL or ≥ VOH). This is the static discipline.
Compute both margins. Noise immunity is the smaller one.
TrapSubtracting the wrong pair. Margins pair an output threshold with the input threshold on the same side: OL with IL, OH with IH.
VOL = 0.4, VIL = 1.1, VIH = 2.6, VOH = 3.1. What is the noise immunity?
0.7 V
0.5 V
1.5 V
1.2 V
Low margin is 1.1 − 0.4 = 0.7. High margin is 3.1 − 2.6 = 0.5. Immunity is the smaller, 0.5. The 1.5 answer is the width of the forbidden zone.
Same thresholds. A buffer gets 1.0 V in and gives 0.6 V out. Does it obey the static discipline?
Yes, 0.6 is below VIL
Yes, the output is lower than the input
No, a valid low input needs an output at or below 0.4
1.0 V is a valid low input, so the output must meet the output rule, VOL = 0.4. Meeting the input rule is not enough.
Someone proposes VOL = VIL and VOH = VIH to make devices easier to build. What is lost?
All noise margin: any noise on a wire can make a valid output an invalid input
Nothing, the forbidden zone is still there
The ability to tell 0 from 1
Margins are the gaps between output and input thresholds. With equal thresholds both gaps are zero.
An Integer is a number the compiler uses while building the circuit, a Bit#(n) is a bundle of wires in the circuit, and faster adders buy speed with extra hardware.
Why it works
The circuit's shape must be fixed before it runs. Sizes and loop bounds are therefore compile-time Integer values.
One parametric function describes a whole family: an n-bit adder for any n.
In a ripple-carry adder each bit waits for the carry from the bit below, so delay grows with n.
Carry-select computes the upper half twice, once for carry 0 and once for carry 1, while the lower half is still working. A mux then picks.
Adder
Delay
Area
How
Ripple-carry
Grows with n
Smallest
Carry passes through every bit
Carry-select
About half, plus a mux
About 1.5×
Upper half precomputed for both carries
Carry-lookahead
Grows with log n
Largest
Carries computed by a tree
The move: estimate adder delay
Find the carry chain. It is the critical path.
Ripple: bits × carry delay per bit.
Carry-select: delay of the lower block, plus one mux. Both halves run at the same time.
State the price: count the duplicated hardware.
TrapUsing a wire value where a compile-time number is needed. A loop bound or a bit width cannot depend on a Bit#(n) input.
A 32-bit ripple-carry adder has 2 ns carry delay per bit. Rebuilt as carry-select with two 16-bit halves and a 1 ns mux, the delay is about:
33 ns
64 ns
65 ns
17 ns
Lower half: 16 × 2 = 32 ns. The upper halves finish in the same 32 ns. Add the mux: 33 ns. The ripple version was 64 ns.
Which inputs make an 8-bit ripple-carry adder take its worst-case time?
00000000 + 00000000
10000000 + 10000000
11111111 + 00000001
The carry created at bit 0 must travel through all eight bits. In option B the only carry is created at the top bit and goes nowhere.
for (Integer i = 0; i < n; i = i + 1) with n = 8. What hardware does the loop counter become?
A 3-bit counter register
None. The compiler unrolls the loop into 8 copies of the body
An 8-way mux
Integer values exist only while the circuit is being generated. Nothing of i remains in the circuit.
Registers sample only at the rising clock edge, and two inequalities guarantee that what they sample is stable: one for the slowest path and one for the fastest.
Why it works
A flip-flop needs its input steady for tSETUP before the edge and tHOLD after it.
Setup: the new value leaves FF1, crosses the logic, and must arrive early enough for the next edge. The slowest path sets the clock period.
Hold: the same edge that FF2 is sampling on also changes FF1. The old value must not vanish too soon. The fastest path decides this.
A state machine is this loop: logic computes next state from state and inputs, the edge makes it current. n flip-flops give up to 2n states.
Constraint
Inequality
Uses
Fix if violated
Setup
tCLK ≥ tPD,FF1 + tPD,CL + tSETUP,FF2
Slowest path
Slow the clock or shorten the logic
Hold
tCD,FF1 + tCD,CL ≥ tHOLD,FF2
Fastest path
Add delay to the short path. The clock cannot help
The move: timing problem
List every register-to-register path, including a register back to itself.
Hold first: for each path check tCD,FF1 + tCD,CL ≥ tHOLD,FF2. One failure means the circuit is broken at any clock speed.
Setup: compute tPD,FF1 + tPD,CL + tSETUP,FF2 per path. The largest is the minimum tCLK.
TrapTrying to fix a hold violation by slowing the clock. tCLK does not appear in the hold inequality.
tPD,FF = 2, tPD,CL = 6, tSETUP = 1, tCD,FF = 0.5, tCD,CL = 1 (ns). What is the minimum clock period?
9 ns
8 ns
10.5 ns
2.5 ns
2 + 6 + 1 = 9. Contamination delays belong to the hold check only.
tCD,FF = 0.3, tCD,CL = 0.2, tHOLD = 0.8 ns. What is true?
Fine, if the clock is slow enough
Fine, 0.3 + 0.2 is under 0.8
Hold is violated. Add at least 0.3 ns of delay on the path
The sum 0.5 must be at least 0.8. It is 0.3 short. Only extra contamination delay fixes it.
A controller needs 5 distinct states. What is the fewest flip-flops that can hold its state?
2
3
5
2 flip-flops give 4 states, which is too few. 3 give 8. Five would be needed only for a one-per-state encoding.
Registers between blocks let each block start on the next input while later blocks finish the current one: throughput rises, latency does not improve.
Why it works
The clock only has to cover the slowest stage, not the whole circuit.
One result comes out every cycle, so throughput is 1 / tCLK.
Each input still passes through all K stages, so latency is K × tCLK.
Values that meet at a block must come from the same input. So every input-to-output path must cross the same number of registers. That is a well-formed K-pipeline.
Blocks 4, 6, 2, 5 ns in a chain
tCLK
Latency
Throughput
No registers inside
17
17
1/17
2 stages: 4 6 | 2 5
10
20
1/10
4 stages: 4 | 6 | 2 | 5
6
24
1/6
The move: place pipeline registers
Draw a contour across the circuit so that every wire crosses it in the same direction. Put a register on every wire it crosses.
Repeat for each stage. Always put a contour at the output.
For best throughput, isolate the slowest block. No cut can beat its delay.
TrapSaying pipelining reduces latency. Stages are padded to the slowest one, so latency stays the same or grows.
Chain of 3, 7, 4, 4 ns blocks. With the best 2-stage pipeline, what are tCLK and latency?
9 and 18
10 and 20
7 and 14
11 and 22
Cuts give 3 | 15, 10 | 8 or 14 | 4. The best is 10 | 8, so tCLK = 10 and latency = 2 × 10 = 20.
Same chain. What is the fewest stages that reaches the best possible throughput?
2
4
3
The limit is the 7 ns block, so no stage may exceed 7. 3 + 7 is too long and so is 4 + 4 = 8, which forces 3 | 7 | 4 | 4. Three stages would leave a stage of 8 or more.
A two-input block receives input A through one register and input B through two registers. What is wrong?
It combines A from one input with B from an earlier input
Nothing, if the clock is slow enough
The block needs a third register
Paths with different register counts are not a well-formed pipeline. The two values belong to different cycles' inputs.
The same function can be built combinational, pipelined or folded, and each wins on a different measure, so always ask which measure the question cares about.
Why it works
Combinational: one big block. Lowest latency, because nothing waits for a clock edge inside.
Pipelined: the same hardware plus registers. Highest throughput.
Folded: one copy of the repeated step, a register and a counter. Smallest area, but one result takes many cycles.
A folded or multi-cycle unit finishes at varying times, so it tells its user when the result is real with a valid bit.
Design
Latency
Throughput
Area
Combinational
Best
Middle
Middle
Pipelined
Slightly worse
Best
Largest
Folded
Usually worst
Worst
Smallest
The move: compare designs
For each design write tCLK and the number of cycles per result.
Latency = cycles × tCLK.
Throughput = 1 / tCLK if a new input enters every cycle, otherwise 1 / latency.
Answer for the stated goal only.
TrapPicking the design with the shortest clock period. A 3 ns clock that needs 16 cycles is slower than a 40 ns single cycle.
A multiplier is built three ways: combinational, 40 ns. Folded, 16 cycles at 3 ns. Pipelined, 4 stages at 11 ns. Which has the lowest latency?
Combinational, 40 ns
Folded, 3 ns
Pipelined, 11 ns
Folded takes 16 × 3 = 48 ns and pipelined 4 × 11 = 44 ns. The clock period alone is not latency.
Same three designs. Which has the highest throughput?
Combinational, 1 per 40 ns
Folded, 1 per 3 ns
Pipelined, 1 per 11 ns
The pipeline accepts a new input every cycle. The folded design is busy for all 16 cycles, so it gives 1 per 48 ns.
A folded divider takes between 4 and 32 cycles depending on its inputs. How should the module that uses it know when to read the result?
Always wait 32 cycles
The divider marks its output valid only when done
Read every cycle and keep the last value
A valid bit, a Maybe in Minispec, travels with the data. Waiting the worst case works but wastes time, and reading early gives garbage.