---
title: FPGA architecture
heading: Lookup tables, carry chains, block RAM, DSP slices and routing
eyebrow: S3 · Lesson 27 · FPGA architecture
xp: 50
---

::: hook
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.
:::

::: play
- 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.
:::
:::

```sim plot
view: graph
x: n = 2..64 step 1
y: c = 0..32
slider: k = 2..8 step 1 = 6
plot: ceil((n - 1)/(k - 1) - 0.001) | samples: 400 | label: LUTs
plot: ceil(log(n)/log(k) - 0.0001) | samples: 400 | dashed | color: ch2 | label: LUT levels
readout: configuration bits per LUT = 2^k
```

::: predict
## How many different logic functions can one 4-input lookup table implement?

- [ ] 4
- [ ] 16
- [ ] 256
- [x] 65,536

::: reveal
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 $2^{16}$ = 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 $2^{64}$ functions.
:::
:::

::: nameit
## Lookup tables and logic blocks

A k-input LUT is a $2^k$-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

$$\left\lceil \frac{n - 1}{k - 1} \right\rceil \text{ LUTs in } \lceil \log_kn \rceil \text{ levels}$$

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 $\lceil D/d \rceil \cdot \lceil W/w \rceil$ 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.
:::

::: 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?

::: solution
1. **LUTs.**
   $$\lceil 31/5 \rceil = 7$$
   Six LUTs on the first level take all 32 inputs (five full, one with two), and a seventh combines their six outputs.
2. **Levels.**
   $$\lceil \log_6 32 \rceil = 2$$
3. **Path delay.**
   $$\begin{aligned} t &= 2 \times (0.12 + 0.45) \\ &\quad + 0.25 + 0.05 \\ &= 1.44\ \text{ns} \end{aligned}$$
   which is 694 MHz.
4. **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).
:::
:::

::: 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?

::: solution
1. **1K × 36.**
   $$\begin{aligned} N &= \lceil 4096/1024 \rceil \cdot \lceil 32/36 \rceil \\ &= 4 \times 1 \\ &= 4 \end{aligned}$$
2. **2K × 18.** $2 \times 2 = 4$.
3. **4K × 9.** $1 \times 4 = 4$.
4. **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.
:::
:::

::: 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?

::: solution
1. **On the carry chain.**
   $$\begin{aligned} t &= 32 \times 0.03 + 0.12 \\ &\quad + 0.9 + 0.3 \\ &= 2.28\ \text{ns} \end{aligned}$$
   about 440 MHz.
2. **Through general routing.**
   $$\begin{aligned} t &= 32 \times (0.12 + 0.45) + 0.3 \\ &= 18.5\ \text{ns} \end{aligned}$$
   eight times slower.
3. **What it means.** The hard carry chain is why FPGA adders are written as plain `a + b` and left to the tools.

**Answer:** 2.28 ns (about 440 MHz) on the carry chain, against 18.5 ns through general routing.
:::
:::

::: check
given: k = 4 | 5 | 6 | 8
answer: 2^k
tolerance: 0

## How many configuration bits does a {k}-input LUT store?

::: right
Right. $2^k$ = {answer}: one per row of the truth table.
:::

::: misses
- [k] The LUT stores a truth table, one bit per input combination.
- [any] Not yet. Count the input combinations.
:::
:::

::: check
given: k = 2 | 3 | 4
answer: 2^(2^k)
tolerance: 0

## How many distinct functions can a {k}-input LUT implement?

::: right
Right. $2^{2^k}$ = {answer}.
:::

::: misses
- [2^k] That's the number of truth-table rows; each row can be 0 or 1.
- [any] Not yet. Count the possible truth tables.
:::
:::

::: check
given: n = 12 | 24 | 50 | 100; k = 4 | 6
answer: ceil((n - 1)/(k - 1) - 0.001)
tolerance: 0

## An {n}-input AND is built from {k}-input LUTs. How many LUTs does it take?

::: right
Right. $\lceil (n - 1)/(k - 1) \rceil$ = {answer}.
:::

::: misses
- [ceil(n/k - 0.001)] The first level's outputs still need combining.
- [any] Not yet. Each LUT takes k signals and passes one on.
:::
:::

::: check
given: n = 12 | 24 | 50 | 100; k = 4 | 6
answer: ceil(log(n)/log(k) - 0.0001)
tolerance: 0

## How many levels of {k}-input LUTs does an {n}-input AND tree need?

::: right
Right. $\lceil \log_kn \rceil$ = {answer}.
:::

::: misses
- [ceil(log(n)/log(2) - 0.0001)] Each level combines k signals, not two.
- [any] Not yet. Each level divides the signal count by k.
:::
:::

::: check
given: D = 1100 | 2100 | 4200; W = 20 | 40 | 76; m = 1 | 2; let d = 1024*m; let w = 36/m
answer: ceil(D/d - 0.0001)*ceil(W/w - 0.0001)
tolerance: 0

## A {D} × {W} memory is built from block RAMs configured as {d} × {w}. How many blocks does it take?

::: right
Right. $\lceil D/d \rceil \cdot \lceil W/w \rceil$ = {answer}.
:::

::: misses
- [ceil(D*W/(d*w) - 0.0001)] Blocks come whole in each direction: round depth and width up separately.
- [any] Not yet. Round the depth and the width up separately.
:::
:::

::: check
given: M = 24 | 32 | 48; N = 16 | 32; a = 27; b = 18
answer: ceil(M/a - 0.0001)*ceil(N/b - 0.0001)
tolerance: 0

## A {M} × {N}-bit multiply is built from DSP slices that each multiply {a} bits by {b} bits. How many slices does it take?

::: right
Right. $\lceil M/a \rceil \cdot \lceil N/b \rceil$ = {answer} partial products, each one slice.
:::

::: misses
- [any] Not yet. Split each operand into pieces that fit, and multiply every pair of pieces.
:::
:::

::: check
given: L = 2 | 4 | 6; t = 0.1 | 0.15; r = 0.3 | 0.5; c = 0.3; s = 0.05
answer: 1/(L*(t + r) + c + s)*1000
unit: MHz
tolerance: 0.5%

## A path passes through {L} LUT levels, each {t} ns plus {r} ns of routing, with {c} ns clock-to-Q and {s} ns setup. What's its maximum clock?

::: right
Right. $1/(L(t_\text{LUT} + t_\text{route}) + t_{cq} + t_\text{su})$ = {answer} MHz.
:::

::: misses
- [1/(L*t + c + s)*1000] Count the routing: it's usually the larger part.
- [any] Not yet. Add each level's LUT and routing delay.
:::
:::

::: check
kind: parts
given: n = 16 | 32 | 64 | 100; k = 4 | 6; D = 3000 | 5000; W = 24 | 40

## An {n}-input AND is built from {k}-input LUTs, and a {D} × {W} memory goes into block RAMs set up as 2K × 18.

::: part
answer: ceil((n - 1)/(k - 1))
tolerance: 0

### How many LUTs does the AND take?

::: misses
- [any] $\lceil(n - 1)/(k - 1)\rceil$.
:::
:::

::: part
answer: ceil(log(n)/log(k) - 1e-9)
tolerance: 0

### How many levels deep is it?

::: misses
- [any] $\lceil\log_kn\rceil$.
:::
:::

::: part
answer: ceil(D/2048)*ceil(W/18)
tolerance: 0

### How many block RAMs does the memory take?

::: misses
- [any] $\lceil D/d\rceil\cdot\lceil W/w\rceil$.
:::
:::
:::

::: check
kind: derivation
vars: n = 1..12, l = 0.05..0.5, r = 0.1..1, q = 0.1..0.5, s = 0.02..0.2

## 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
answer: n*(l + r) + q + s

### What is its delay?
:::

::: step
answer: 1/(n*(l + r) + q + s)

### What is its maximum clock frequency?
:::

::: step
answer: n*r/(n*(l + r) + q + s)

### What fraction of the period is routing?
:::

::: right
Right. Routing usually dominates FPGA paths, which is why placement matters so much there.
:::
:::

::: explain
## Why do FPGA designs use lots of pipeline registers, even when an ASIC version of the same design would use few?

::: model
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

::: check
given: k = 3 | 6 | 7
answer: 2^k
tolerance: 0

## Configuration bits in a {k}-LUT?

::: misses
- [any] $2^k$.
:::
:::

::: check
given: n = 16 | 40 | 90; k = 4 | 6
answer: ceil((n - 1)/(k - 1) - 0.001)
tolerance: 0

## {k}-LUTs for an {n}-input AND?

::: misses
- [any] $\lceil (n - 1)/(k - 1) \rceil$.
:::
:::

::: check
given: D = 2500 | 5000; W = 24 | 64; m = 1 | 4; let d = 1024*m; let w = 36/m
answer: ceil(D/d - 0.0001)*ceil(W/w - 0.0001)
tolerance: 0

## Block RAMs for {D} × {W} in a {d} × {w} shape?

::: misses
- [any] Round depth and width up separately.
:::
:::
:::
