D102 of 13
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

D10 · Lesson 2 · Inside an FPGA

How a field-programmable gate array becomes any circuit, the lookup table that implements any small function from a few memory bits, how many functions a LUT can hold, flip-flops beside every LUT, programmable routing and its delay, hard blocks for arithmetic and memory, and how FPGAs compare with custom chips

An FPGA is a chip that doesn't know what it is until it's configured. Inside are hundreds of thousands of tiny lookup tables, each a scrap of memory that can act as any logic function of its few inputs, every one paired with a flip-flop, all sitting in a sea of programmable switches that can wire them together in nearly any pattern. Loading a configuration file turns this blank fabric into a CPU, a video processor or a radio, and loading another turns it into something else. Verilog's job is to describe the circuit; the tools' job is to map it onto that fabric.

  • A 2-input lookup table: four configuration bits C0 to C3 hold the function's truth table, and the inputs A and B select one of them through a tree of multiplexers.
  • Set C0 to C3 to 0, 0, 0, 1 and the LUT is an AND gate; 0, 1, 1, 1 makes OR; 0, 1, 1, 0 makes XOR. Any of the 16 functions of two inputs is just a different pattern.
  • Real FPGAs use 6-input LUTs: 64 configuration bits each.

Predict

How many different logic functions can a single 4-input LUT implement?

Name it

Lookup tables

A k-input LUT is a 2k-bit memory addressed by its inputs. Any function of k inputs fits in one LUT, so the number of gates in the original logic doesn't matter, only the number of inputs. Functions of more inputs are split across several LUTs: a wide AND of n inputs takes about ⌈(n−1)/(k−1)⌉ k-input LUTs in a tree.

Logic blocks

Each LUT sits next to a flip-flop (or two), and groups of them form a logic block (a slice or CLB), with a dedicated fast carry chain for adders and counters running between neighbors.

Routing

LUTs connect through a mesh of wires and programmable switches. Routing takes most of an FPGA's area and often most of a signal's delay, so a design's speed depends heavily on how the tools place its logic.

Hard blocks

Common functions are built in as fixed silicon: DSP blocks (multiply-accumulate units), block RAMs (tens of kilobits each), clock managers (PLLs, D5), high-speed serial transceivers, and sometimes whole processor cores.

FPGA or ASIC

The flexibility costs area, speed and power: a design typically takes 10 to 40 times the area of a custom chip (D7), runs 3 to 4 times slower and uses several times the power. But there are no masks and no NRE, and a mistake costs a recompile instead of a new chip.

Worked example

How many 6-input LUTs does a 16-input AND need? How many LUT configuration bits does a device with 100,000 6-LUTs hold?

Show the solution
  1. LUTs for the AND. ⌈16−16−1⌉=3 Two LUTs each AND six inputs, and a third combines their outputs with the remaining four.
  2. Configuration bits. Each 6-input LUT holds 64 bits: 100000×64=6.4million bits=0.8MB
  3. Routing. That's before counting the routing switches, which need many more.

Answer the 16-input AND takes 3 LUTs, and the device's LUTs hold 6.4 million configuration bits, about 0.8 MB.

Worked example

What are the configuration bits of a 2-input LUT that computes A AND NOT B?

Show the solution
  1. Find where the output is 1. A AND NOT B is 1 only for A = 1, B = 0.
  2. Find the bit that input selects. A = 1, B = 0 selects C1 in the multiplexer tree.
  3. Fill in the bits. C1 holds the 1 and the rest hold 0: C0 = 0, C1 = 1, C2 = 0, C3 = 0.

Answer C0 = 0, C1 = 1, C2 = 0 and C3 = 0.

Worked example

How many 6-input LUTs does a 16-bit equality comparator need?

Show the solution
  1. Compare the bit pairs. Each LUT can compare three bit pairs (six inputs) and output whether all three match: ⌈163⌉=6LUTs
  2. Combine the results. One more LUT ANDs their six outputs: 6+1=7LUTs in two levels of logic.

Answer 7 LUTs, in two levels of logic.

Check

How many configuration bits does a 4-input LUT hold?

Check

How many different functions can a 3-input LUT implement?

Check

About how many 3-input LUTs does a 16-input AND gate need?

Check

A device has 100 thousand 4-input LUTs. How many million configuration bits do the LUTs alone hold?

Check

An n-input AND, n = 24, is built from 4-input LUTs.

(a)

How many LUTs does it need?

(b)

How many configuration bits does each LUT hold?

Check

A 16-bit equality comparator is built from 6-input LUTs, three bit pairs per LUT, then the results are ANDed.

(a)

How many LUTs compare the bit pairs?

(b)

How many LUTs in all, counting those that AND the results (6 inputs each)?

Explain why

Why can one lookup table implement any function of its inputs?

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.