It has been a while since we posted any puzzles or interview questions to tickle everyone's brains. The recession has hit us in a big way, and there seems to be a drought of originality in the interview questions asked nowadays. Even the ones shared on the various blogs that have cropped up these days are either copied outright or "massaged". Don't you think so? So, to keep the spirit of creativity and intelligence alive, and hoping that the recession passes without many casualties, here is the next one in our series of original interview questions.
The FPGA cell
Look at the following block. This is the most common building block in any FPGA. Altera calls it a Logic Element (LE) and Xilinx calls it a Configurable Logic Block (CLB). The structure may not be accurate, but it illustrates the idea behind it.
The generic cell has a small combinational block (comb) with four data inputs, a carry in and carry out, and one flip-flop with clock enable, set and reset. The comb output can leave the cell directly (comb_data_out), feed the flip-flop (flop_data_out), or both. The flip-flop can also be loaded directly from flop_data_in.
How to estimate the number of cells
We estimate the number of FPGA cells required for a design by counting the flip-flops and the primary inputs in the fanin of each flip-flop. Only flip-flops count, because combinational signals are collapsed into the circuitry within an FPGA cell. The circuitry for any flip-flop signal with up to four source flip-flops (or inputs) can be implemented in a single FPGA cell. If a flip-flop signal depends on five source flip-flops, then two FPGA cells are required.
This technique generally gives an overestimate, because a single cell can drive several other cells (common subexpression elimination).
The question
Map the combinational circuits below onto generic FPGA cells. You can explain in words how you would do it, or send me an email.
Appreciate your comments. Good luck!
The idea behind the answer, in short
Each cell can compute any logic function of up to four signals, and it can register that result. So the job is to group the gates into blobs, where each blob has at most four inputs and one combinational output, and count the blobs. Any internal signal that must leave the circuit, or feed both a flip-flop and some other logic, may need its own cell. The suggested answers below are worked in the deep dive.
Suggested counts: circuit 1 needs one cell, circuit 2 needs two cells, and circuit 3 needs three cells.
Deep dive: the numbers and details
This part holds the worked mapping for each circuit, the counting rule in detail and how real FPGA cells change the numbers. Skip it if the overview is all you need.
Circuit 1: one cell
The output z is built from three AND gates and an OR gate, but every gate is driven only by a, b, c and d. Whatever the internal structure, z is a Boolean function of four inputs. A four-input lookup table holds any such function: 24 = 16 entries, one bit each. So the whole circuit fits in the comb block of one cell, with z on comb_data_out and the flip-flop unused.
Circuit 2: two cells
- Cell 1: the gates e, f, g, h and i and the OR that makes z depend only on a, b, c and d, so z fits in the comb block of cell 1. The register after z is the flip-flop of the same cell, so y comes out on flop_data_out. Cell 1 also sends z out on comb_data_out.
- Cell 2: x = z XOR y needs z and y. Two inputs fit easily in the comb block of a second cell.
Why not one cell? The comb block of cell 1 already produces z. Computing x as well would need a second combinational output and a function of five sources (a, b, c, d and y), which is more than four inputs. With the counting rule from the post: y has four sources in its fanin (one cell), and the output x has five sources (a, b, c, d and y), which needs a second cell.
Circuit 3: three cells
- Cell 1: z and the flip-flop y, as in circuit 2.
- Cell 2: x = z XOR y.
- Cell 3: w is the internal AND gate i, now brought out as a primary output. Its inputs come only from b, c and d (through the OR gate f), so it fits in one comb block, but cell 1's comb block is already used for z and cell 2's for x. A third cell computes w on its own.
This shows the limit of the simple counting rule: it counts flip-flops, but an extra combinational output costs a cell even when no flip-flop is added.
The counting rule as a procedure
for each flip-flop F:
S = set of flip-flops and primary inputs in the combinational fanin of F
cells(F) = 1 if |S| <= 4, else more (see below)
for each combinational primary output O:
if O cannot share a cell already counted: add cells for O
total = sum of cells
For a function of n sources where n is larger than the LUT size k, a common rough estimate is to split it into a tree of k-input LUTs. For k = 4 the first LUT absorbs 4 sources and each extra LUT absorbs 3 new ones (one input is taken by the previous result), so the count is 1 + ceil((n - 4) / 3). For n = 5 that gives 2 cells, which matches the rule in the post. For n = 10 it gives 1 + ceil(6 / 3) = 3 cells. Functions with useful structure (such as wide AND gates) reach this count; arbitrary functions of many inputs can need far more.
How real FPGA cells change the numbers
- Xilinx (now AMD) 7 series: the 7 Series CLB user guide (UG474) describes six-input LUTs, each usable as one 6-input function or two 5-input functions with shared inputs. Four LUTs and eight flip-flops form a slice, and two slices form a CLB. With six-input LUTs, the five-source output x in circuit 2 fits in one LUT.
- Altera LE: the classic logic element built around a four-input LUT and one register is close to the generic cell in this post. The Cyclone IV handbook chapter on logic elements and logic array blocks describes how LEs are grouped into LABs.
Because cell structures differ, an estimate in "cells" only makes sense for one family. Vendor tools report LUTs and flip-flops separately for the same reason.
Common mistakes
- Counting gates instead of inputs. Five gates on four inputs still fit in one 4-input LUT.
- Forgetting outputs that tap an internal node, such as w in circuit 3.
- Assuming one cell can produce two unrelated combinational outputs. The generic cell here has one comb output.
- Ignoring the flip-flop inside the cell. A register right after a combinational function uses the same cell for free.
Interview angle
Interviewers use this question to see whether you think in LUT inputs rather than gates. A good answer states the cell model first (inputs per LUT, outputs per cell, one flip-flop), maps each circuit, and then mentions that the result changes with a six-input LUT architecture.

Correction: Xilinx CLB is Configurable Logic Block. The drawing is representing not CLB but a Slice.
ReplyDelete