D10 · Lesson 1 · Concurrency in hardware
Why a hardware description is not a program, every assignment as its own circuit running all the time, signals settling through levels of gates, the order of statements not mattering, and the throughput that comes from doing thousands of operations in every clock cycle
Verilog looks like a programming language, which is the first trap it sets. A program runs one statement after another on one processor. A Verilog description has no "after": each assign describes a separate piece of circuitry, and all of them work at once, continuously, from the moment power is applied. Change an input and every gate that depends on it starts changing within picoseconds, in parallel. That's what lets an FPGA do a thousand multiplications in the time a processor does one, and it's why thinking in hardware feels so different from thinking in software.
- Three assignments: A = X & Y, B = X | Y and C = A ^ B, each gate with a delay of one tick. Flip X and Y, or watch the scripted changes in the timing diagram.
- A and B respond together, one tick after the inputs change; C responds one tick after that, because it depends on them. The order the lines are written in makes no difference.
- The time for C to settle is set by the number of gate levels between it and the inputs: the critical path.
Predict
A processor at 3 GHz does one addition per cycle. An FPGA at 300 MHz has 1000 adders working side by side. How many additions per second does each manage?
The processor: 3 × 10⁹ additions per second. The FPGA: 1000 adders × 3 × 10⁸ cycles = 3 × 10¹¹, a hundred times more despite a ten times slower clock. Hardware wins by doing many things at once, as long as the work can be split up.
Name it
Concurrent statements
In Verilog, each assign and each always block describes hardware that exists and operates independently. Their textual order is irrelevant: assign C = A ^ B; can come before the lines that define A and B. Simulators model this with events: when a signal changes, every statement that reads it is scheduled to update after its delay.
Settling time
A combinational output settles after the delay of the slowest path from the inputs to it. With levels of gates of delay each, that's , and a clocked design can run no faster than about plus the flip-flops' overhead (lesson 8). Until it settles, an output may show glitches: brief wrong values as faster paths arrive before slower ones.
Throughput from parallelism
Hardware throughput is the number of operations done per cycle times the clock rate. A processor executes a few operations per cycle at gigahertz rates; an FPGA or ASIC can lay down thousands of operators side by side at hundreds of megahertz. Hardware design is the art of finding that parallelism in a problem and laying it out in space.
Worked example
A path passes through 6 levels of gates, each taking 80 ps. How long does it take to settle, and what clock rate does that allow?
Show the solution
- Settling time. Each of the 6 levels takes 80 ps:
- Clock rate. The clock period must be at least 480 ps plus flip-flop overhead, so the clock must stay below about
- Fewer levels. Halving the levels would double the rate.
Answer the path settles in 480 ps, which allows a clock below about 2.08 GHz.
Worked example
A video filter must process 1920 × 1080 pixels at 60 frames per second, with 25 multiplications per pixel. How many multipliers does it need at 150 MHz?
Show the solution
- Multiplications per second.
- Divide by one multiplier's rate. Each multiplier does a second:
- Round up. 20.7 rounds up to 21 multipliers working in parallel.
Answer 21 multipliers working in parallel.
Worked example
1024 numbers must be summed. How many adder delays does a processor adding one at a time need, and how many does a tree of adders in hardware need?
Show the solution
- One at a time. A processor needs 1023 additions in sequence, so 1023 adder delays.
- A tree of adders. A tree adds pairs in parallel, halving the count at each level: using 1023 adders in all.
- Speed for area. Hardware buys speed with area, here a hundredfold.
Answer 1023 adder delays one at a time, against 10 for a tree of 1023 adders.
Check
An FPGA design has 256 operators each finishing one operation per clock at 100 MHz. How many billion operations per second does it perform?
Check
A logic path has 6 levels of gates, each with a delay of 50 ps. Ignoring flip-flop overhead, what's the fastest clock it allows?
Write units the way you normally would: 1.5 GHz, 1500 MHz and 0.0015 THz are the same answer.
Check
A filter needs 25 multiplications per pixel on 1920 × 480 video at 60 frames per second. How many multipliers running at 150 MHz does it need?
Check
In a timing simulation, an output sits 4 gate levels from the inputs, and each gate takes 2 ticks. How many ticks after an input changes does the output settle?
Check
A path passes through 8 levels of gates of 40 ps each.
(a)
How long does it take to settle?
Write units the way you normally would: 1.5 ps and 0.0015 ns are the same answer.
(b)
What clock rate does that allow, ignoring flip-flop overhead?
Check
1024 numbers are summed.
(a)
How many additions in sequence does one adder need?
(b)
How many levels does an adder tree need?
Explain why
Why doesn't the order of assign statements matter in Verilog?
Each assign statement describes a piece of circuitry, a gate or a network of gates wired from some signals to another, and all of that circuitry exists at the same time once it's built. There's no processor stepping through the statements: the gates continuously compute their outputs from whatever their inputs currently are. Writing the line for C before the lines that compute A and B just lists the same wires and gates in a different order on the page. The simulator mirrors this by updating every statement whose inputs change, in whatever order events happen, so the result depends only on how the signals are connected.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.