S3 · Lesson 27 · FPGA architecture
Lookup tables, carry chains, block RAM, DSP slices and routing
An FPGA is a chip whose logic is decided after it's made. Its fabric is a grid of small lookup tables, each a tiny memory that can hold the truth table of any function of its inputs, joined by programmable routing, with flip-flops beside every table, dedicated carry chains for arithmetic, blocks of RAM and hard multipliers. Synthesis maps the RTL onto those pieces, placement assigns them to sites, and routing connects them through switches. Knowing what the fabric contains tells a designer what will be fast and small on an FPGA and what will sprawl: a 64-input AND costs a tree of tables, but a 64-bit adder rides a carry chain built for exactly that.
- How many k-input lookup tables (LUTs) an n-input AND, OR or XOR takes (solid), and how many levels of LUTs a signal passes through (dashed). Each LUT absorbs k inputs and passes one on.
- Larger LUTs cut both counts. Modern FPGAs use 6-input LUTs, often splittable into two 5-input functions sharing inputs.
- Delay on an FPGA goes with the number of LUT levels, because every level also costs a trip through the routing switches, usually more than the LUT itself.
Predict
How many different logic functions can one 4-input lookup table implement?
65,536. A 4-input LUT is a 16-bit memory addressed by the inputs, and its 16 stored bits are the function's truth table. Any of the = 65,536 possible truth tables can be loaded, so every function of four inputs costs the same: one LUT and one LUT delay. A 6-input LUT stores 64 bits and covers functions.
Name it
Lookup tables and logic blocks
A k-input LUT is a -bit memory with the inputs as its address. Any function of k or fewer inputs fits in one. A function of more inputs is split across several: an n-input AND, OR or XOR (any associative function) takes
LUTs are grouped with flip-flops and multiplexers into logic blocks (Xilinx calls them slices and CLBs, Intel ALMs and LABs). Every LUT output can be registered at no extra cost, which is why FPGA designs pipeline freely.
Carry chains
Each logic block contains a dedicated, hard-wired carry path. An N-bit adder uses one LUT per bit for the propagate signal and the chain for the carry, and the chain is many times faster per bit than going through general routing.
Hard blocks
- Block RAM: dual-port memories (36 Kb in many families) configurable in shape, such as 1K × 36, 2K × 18 or 4K × 9. A memory of D words by W bits takes blocks in a d × w shape. Small memories can live in LUTs instead (distributed RAM).
- DSP slices: hard multipliers (27 × 18 in recent Xilinx parts) with pre-adders and accumulators, for filters and arithmetic.
- Clock management, transceivers, and in some families whole processors.
Routing and timing
Most of an FPGA's area and delay is routing: wire segments of several lengths joined by programmable switches. A path's delay is roughly the number of LUT levels times (LUT delay + routing delay), plus clock-to-Q and setup. Compared with a standard-cell ASIC in the same process, an FPGA spends roughly 20 to 35 times the area, 3 to 4 times the delay and about 10 times the dynamic power for the same logic, and in exchange it can be changed after it's built.
Configuration
The LUT contents, routing switches and block settings are held in SRAM cells loaded from a bitstream at power-up (some families use flash). Partial reconfiguration changes part of the fabric while the rest runs.
Worked example
A 32-input AND is built from 6-input LUTs. How many LUTs and levels? And what's the path's maximum clock with 0.12 ns per LUT, 0.45 ns per routing hop, 0.25 ns clock-to-Q and 0.05 ns setup?
Show the solution
- LUTs. Six LUTs on the first level take all 32 inputs (five full, one with two), and a seventh combines their six outputs.
- Levels.
- Path delay. which is 694 MHz.
- Routing's share. The two hops, 0.9 ns, are 63% of it.
Answer 7 LUTs in 2 levels, and the path runs at 694 MHz (1.44 ns).
Worked example
A 4096 × 32 memory goes into 36 Kb block RAMs that can be 1K × 36, 2K × 18 or 4K × 9. How many blocks does each shape take?
Show the solution
- 1K × 36.
- 2K × 18. .
- 4K × 9. .
- Why 4 is the least. The memory holds 128 Kb and each block 36 Kb (with the parity bits unused here). A 4096 × 36 memory would also fit in 4, using those parity bits.
Answer every shape takes 4 blocks.
Worked example
A 32-bit adder's carry takes 30 ps per bit on the FPGA's carry chain. Entering and leaving the chain costs a LUT (0.12 ns) and two routing hops (0.45 ns each), plus 0.3 ns of clock-to-Q and setup. How fast is it, against a carry that went through a LUT and a routing hop per bit?
Show the solution
- On the carry chain. about 440 MHz.
- Through general routing. eight times slower.
- What it means. The hard carry chain is why FPGA adders are written as plain
a + band left to the tools.
Answer 2.28 ns (about 440 MHz) on the carry chain, against 18.5 ns through general routing.
Check
How many configuration bits does a 5-input LUT store?
Check
How many distinct functions can a 3-input LUT implement?
Check
A 24-input AND is built from 4-input LUTs. How many LUTs does it take?
Check
How many levels of 4-input LUTs does a 24-input AND tree need?
Check
A 2100 × 20 memory is built from block RAMs configured as 2048 × 18. How many blocks does it take?
Check
A 32 × 16-bit multiply is built from DSP slices that each multiply 27 bits by 18 bits. How many slices does it take?
Check
A path passes through 4 LUT levels, each 0.1 ns plus 0.5 ns of routing, with 0.3 ns clock-to-Q and 0.05 ns setup. What's its maximum clock?
Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.
Check
A 32-input AND is built from 4-input LUTs, and a 5000 × 40 memory goes into block RAMs set up as 2K × 18.
(a)
How many LUTs does the AND take?
(b)
How many levels deep is it?
(c)
How many block RAMs does the memory take?
Check
An FPGA path has n LUT levels, each costing a LUT delay l and a routing delay r, plus clock-to-Q q and setup s.
Step 1
What is its delay?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What is its maximum clock frequency?
Step 3
What fraction of the period is routing?
Explain why
Why do FPGA designs use lots of pipeline registers, even when an ASIC version of the same design would use few?
On an FPGA every LUT output already has a flip-flop sitting beside it in the logic block, so registering a signal uses a resource that would otherwise go to waste and costs almost no area. Meanwhile each level of logic is slow, because a signal has to leave the LUT and pass through programmable routing switches to reach the next one. Cutting a path with registers shortens the number of LUT-and-routing hops per clock, which raises the clock frequency a lot for nearly free. In an ASIC, flip-flops are real extra cells with area and power, and the gates between them are fast, so designers add fewer pipeline stages.
Practice
Keep practicing
11 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.