Programmable Logic Fundamentals
FPGA & Programmable Logic · Hardware Foundations track
10 min read
In this module
Hardware You Can Rewrite
Every module so far has dealt with fixed digital logic. An AND gate is always an AND gate. A CPU's datapath gets etched into silicon at the factory, and that's that. So what if the logic itself were rewritable? You could reconfigure hardware to implement any digital circuit you wanted, as often as you wanted, without spinning a new mask set.
That's the Field-Programmable Gate Array (FPGA). It's an integrated circuit packed with generic logic resources and programmable interconnect. After the chip is manufactured, you load a configuration (a bitstream) that defines what logic each block implements and how the blocks are wired together. Load a different bitstream and the same physical chip becomes an entirely different circuit.
FPGAs live between two poles. At one end sits the general-purpose CPU, executing software instructions sequentially: flexible but sluggish for massively parallel work. At the other sits the Application-Specific Integrated Circuit (ASIC), custom silicon shaped to a single job — blistering fast but permanently fixed and ruinously expensive to develop. An FPGA hands you hardware-level parallelism with software-like reconfigurability.
FPGAs are everywhere in security-critical systems: network firewalls, hardware security modules, cryptographic accelerators, and military communications. Understanding how they work - and how they can be attacked - is essential for hardware security research. FPGAs are also the primary platform for building side-channel analysis tools like ChipWhisperer.
A Brief History of Programmable Logic
The path to modern FPGAs passed through several earlier technologies:
Programmable Array Logic (PAL) — Introduced by Monolithic Memories in 1978. A PAL contains a programmable AND plane feeding a fixed OR plane. You blow fuses to wire up which AND terms drive each OR gate, implementing sum-of-products Boolean expressions. PALs are one-time programmable. Blow a fuse and there's no going back.
Generic Array Logic (GAL) — Lattice Semiconductor's 1985 upgrade to PALs. GALs swapped fuses for EEPROM cells, so the device became electrically erasable and reprogrammable. The architecture stayed programmable-AND/fixed-OR, but now you could reconfigure the same chip.
Complex Programmable Logic Devices (CPLDs) — CPLDs cram several PAL-like blocks (macrocells) on one die with a programmable interconnect matrix. They offer tens to hundreds of macrocells and rely on non-volatile storage (EEPROM or flash), so they keep their configuration without external memory. They're still around today for glue logic and power-on sequencing.
FPGAs — Xilinx (now AMD) shipped the first commercial FPGA, the XC2064, in 1985. Instead of PAL's AND/OR structure, FPGAs use an array of small look-up tables connected by a programmable routing fabric. The approach scales to millions of logic elements and can implement nearly any digital circuit.
Look-Up Tables: The Core Primitive
The fundamental logic element in an FPGA is the Look-Up Table (LUT). A LUT implements any Boolean function of its inputs by storing the complete truth table in SRAM.
How a LUT Works
Consider a 3-input LUT implementing the function F = (A AND B) OR C:
The truth table has 2^3 = 8 entries:
A B C | F---------+----0 0 0 | 00 0 1 | 10 1 0 | 00 1 1 | 11 0 0 | 01 0 1 | 11 1 0 | 11 1 1 | 1The LUT stashes those 8 output values (01010111) in an 8-entry SRAM. The three inputs A, B, C form a 3-bit address that picks which SRAM entry drives the output through an 8:1 multiplexer.
The trick to grasp: the LUT doesn't "compute" the Boolean function with gates. It looks up the pre-computed answer. One LUT can therefore implement any Boolean function of K inputs, whether that's a plain AND or a sprawling expression with dozens of terms. The only ceiling is the input count.
In C, a LUT is a shift and a mask. "Synthesis" below just runs the function for all eight input combinations and stores the answers, which is exactly the 01010111 above. Reprogramming is writing different bits:
A K-input LUT can implement any of the 2^(2^K) possible Boolean functions of K variables. A 6-input LUT (the standard in modern FPGAs) stores 64 bits of SRAM and can implement any of the 2^64 possible 6-input functions. This universality is what makes FPGAs general-purpose: the same physical structure implements any logic by changing only the SRAM contents.
The builder below starts on the (A AND B) OR C LUT from earlier, INIT 8'hEA. Flip output bits and watch the minimal expression and INIT change, toggle the inputs to see which path through the mux tree lights up, then switch to the challenge and wire a full adder out of two 3-LUTs.
Look-up table builder
A LUT stores one configuration bit per truth-table row. The inputs form an address, and a tree of 2:1 multiplexers picks the stored bit at that address.
Click any output bit to change it.
| bit | A | B | C | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 1 | 0 | 0 | 1 | |
| 2 | 0 | 1 | 0 | |
| 3 | 0 | 1 | 1 | |
| 4 | 1 | 0 | 0 | |
| 5 | 1 | 0 | 1 | |
| 6 | 1 | 1 | 0 | |
| 7 | 1 | 1 | 1 |
C drives the first stage and A the last. Each mux passes its upper input when its select is 0.
A = 0, B = 0, C = 0 is address 000 (row 0), so the mux tree passes stored bit 0: F = 0
Minimal sum of products: F = A·B + C
As gates: (A AND B) OR C
INIT: 8'hEA = 1110 1010
How the INIT value is ordered
Bit i of INIT is the output for row i, where i is the inputs read as a binary number with A as the most significant bit. So the rightmost INIT bit is row 000 and the leftmost is row 111: read the output column from the bottom row up to get INIT. This is the order Xilinx LUT primitives use, with A on pin I2 and C on pin I0, as in LUT3 #(.INIT(8'hEA)).
Build a full adder from two 3-input LUTs. Both see the same inputs A, B and Cin. The pair must output A + B + Cin as a two-bit number: Sum is the low bit and Cout (carry out) the high bit. Set each LUT's configuration bits.
Hint
Sum is 1 when an odd number of inputs are 1. Cout is 1 when at least two of them are.
| bit | A | B | Cin | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 1 | 0 | 0 | 1 | |
| 2 | 0 | 1 | 0 | |
| 3 | 0 | 1 | 1 | |
| 4 | 1 | 0 | 0 | |
| 5 | 1 | 0 | 1 | |
| 6 | 1 | 1 | 0 | |
| 7 | 1 | 1 | 1 |
4 of 8 rows right
| bit | A | B | Cin | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | |
| 1 | 0 | 0 | 1 | |
| 2 | 0 | 1 | 0 | |
| 3 | 0 | 1 | 1 | |
| 4 | 1 | 0 | 0 | |
| 5 | 1 | 0 | 1 | |
| 6 | 1 | 1 | 0 | |
| 7 | 1 | 1 | 1 |
4 of 8 rows right
Not solved yet.
LUT Sizing
Modern FPGAs use 6-input LUTs (6-LUTs). Why not 4-input or 8-input?
- 4-LUT: Only 16 SRAM bits per LUT. Complex functions then need many LUTs cascaded together, which inflates routing demand and delay.
- 6-LUT: 64 SRAM bits per LUT. Most practical logic fits in one or two 6-LUTs. The sweet spot for area efficiency and performance.
- 8-LUT: 256 SRAM bits per LUT. SRAM area balloons exponentially with input count, and few functions actually need 8 inputs. Silicon area gets squandered.
The 6-LUT settled into the industry standard with Xilinx Virtex-5 (2006) and Altera Stratix III (2006). Both AMD/Xilinx and Altera (an Intel division from 2015 until it was spun back out as a standalone company in 2024-25) have stuck with 6-LUTs in their current product lines.
Try sizing something. How many 6-LUTs does a 16-bit equality comparator (a == b, 32 inputs, one output) need, and how many LUTs deep is it?
Show the answer
Each 6-LUT can compare three bit pairs (six inputs) and output "these three match". Sixteen bits need ⌈16/3⌉ = 6 of those, and one more 6-LUT ANDs their six outputs: 7 LUTs, two levels deep. With 4-LUTs you'd need eight first-level LUTs comparing two pairs each, then three more to combine them: 11 LUTs and three levels deep. Synthesis tools sometimes push the final AND into the carry chain instead, so a real report may differ by a LUT or so.
Configurable Logic Blocks
LUTs are grouped with other resources into Configurable Logic Blocks (CLBs) - the fundamental tile that repeats across the FPGA fabric.
What a CLB Contains
A typical CLB (Xilinx/AMD terminology) contains:
- Multiple LUTs (8 six-input LUTs per CLB: on 7-series parts organised as 2 slices of 4 LUTs each, on UltraScale and UltraScale+ as a single slice of 8)
- Flip-flops paired with each LUT output for registered (sequential) logic
- Carry chains for efficient arithmetic (addition, subtraction, comparison) without consuming LUT resources
- Wide-function multiplexers to combine multiple LUT outputs for functions wider than 6 inputs
Flip-flops let CLBs handle sequential logic — state machines, registers, pipelines — alongside the combinational stuff. The carry chains give arithmetic a dedicated fast-propagation path, so adders and counters don't burn LUTs on carry logic.
Xilinx/AMD vs Altera Terminology
The two major FPGA vendors use different names for the same concepts:
| Concept | Xilinx/AMD | Altera |
|---|---|---|
| Basic logic tile | CLB (Configurable Logic Block) | LAB (Logic Array Block) |
| Sub-unit within a tile | Slice | ALM (Adaptive Logic Module) |
| Look-up table | 6-input LUT | 8-input fracturable LUT (two adaptive LUTs) |
| Smallest addressable logic | Slice (4 LUTs + 8 FFs on 7-series; 8 LUTs + 16 FFs on UltraScale) | ALM (2 adaptive LUTs + 4 FFs on recent families) |
Altera's ALM packs a fracturable LUT with eight inputs split between two adaptive LUTs. It can run as one 6-input function, as two independent 4-input functions, or in several mixed combinations (a 5-input and a 3-input, say) that share some inputs. Finer granularity for cramming small logic functions into the fabric.
Nearly all modern FPGAs store their configuration in SRAM cells. This means the FPGA loses its configuration when power is removed and must reload the bitstream from an external source (typically SPI flash) on every power-up. The SRAM-based approach allows unlimited reprogramming but requires external non-volatile storage. Flash-based FPGAs (like Microchip/Microsemi devices) store the configuration in on-chip flash, retaining it through power cycles but with limited write endurance. Anti-fuse FPGAs (also Microchip's, mainly for space and defence) go further: programming permanently blows connections, so the device can be configured exactly once, and there's no bitstream to read out or tamper with afterwards.
From Configuration to Circuit
When an FPGA powers on, it reads the bitstream from external flash memory. The bitstream contains millions of configuration bits that set:
- LUT contents - The truth table stored in each LUT's SRAM
- Flip-flop settings - Initial values, clock enable, set/reset configuration
- Routing switches - Which wire segments are connected through the programmable interconnect
- Hard block configuration - BRAM contents, DSP modes, I/O standards, clock management settings
Configuration takes milliseconds. Once it's done, the FPGA behaves exactly like a custom ASIC implementing the loaded design. Configuration bits stay static during operation. The SRAM cells controlling routing and LUT contents don't sit on the user's data path.
That separation between configuration memory and user logic is foundational. SRAM configuration bits define the circuit's shape. User data flows through the circuit that shape describes. Change the configuration and the circuit changes; in an ordinary design, the data path can't touch the configuration. The exceptions are deliberate: LUTs configured as distributed RAM or shift registers are configuration cells that user logic writes, and partial reconfiguration lets a design rewrite regions of its own fabric through an internal configuration port. The accidental exception is radiation: a single-event upset can flip a configuration bit and silently change the circuit, which is why space and safety designs run configuration scrubbers (Xilinx's SEM IP, for example) that read back and repair the configuration memory.