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

D10 · Lesson 3 · Datapath and control

Splitting a digital design into a datapath of registers, multiplexers and arithmetic units that holds and transforms data, and a controller that tells it what to do each cycle, the select and enable signals between them, and timing a shift-and-add multiplier cycle by cycle

Every nontrivial digital design, from a calculator to a CPU, splits into two parts. The datapath is where the data lives and moves: registers that hold values, multiplexers that pick which value goes where, adders and shifters that compute. The controller is a state machine that decides, cycle by cycle, which multiplexer inputs to select and which registers to load. Drawing that split as a block diagram before writing any Verilog is the single most useful habit in hardware design: the diagram is the design, and the code just describes it.

  • A one-bit datapath: a register Q fed through a multiplexer. When EN is 1 at a clock edge, Q loads either the input D (when LOAD is 1) or Q XOR D; when EN is 0, Q holds.
  • EN and LOAD are the control signals: in a full design a state machine would drive them. Here you drive them, as the controller.
  • The timing diagram shows a scripted sequence: load a 1, then accumulate with XOR, then hold.

Predict

A 32-bit shift-and-add multiplier handles one bit of the multiplier each clock cycle at 100 MHz. How long does one multiplication take?

Name it

The datapath

  • Registers hold values between clock edges; an enable decides whether a register loads on a given edge.
  • Multiplexers choose among sources; selecting among N inputs takes ⌈log2⁡N⌉ select bits.
  • Functional units: adders, comparators, shifters, ALUs.
  • Register files hold several registers with read and write ports: R registers of W bits store RW bits.

The controller

A finite state machine (lesson 6) whose outputs are the datapath's select and enable signals, and whose inputs include status signals from the datapath, such as "the count is zero" or "A is less than B". Each state corresponds to what the datapath does in one cycle. With S states the controller needs ⌈log2⁡S⌉ flip-flops in binary encoding, or S in one-hot encoding, which uses more flip-flops but simpler logic.

Designing with diagrams

Draw the datapath first, with every register and multiplexer; then write down, for each step of the algorithm, which control signals must be set; those steps become the controller's states. The Verilog then follows the diagram line for line.

Worked example

A controller has 6 states. How many flip-flops does it need in binary and one-hot encoding? A datapath picks one of 5 sources for a register: how many select bits?

Show the solution
  1. Binary encoding. ⌈log2⁡6⌉=3flip-flops
  2. One-hot encoding. One flip-flop per state: 6.
  3. Select bits for 5 sources. ⌈log2⁡5⌉=3select bits Three bits make 8 codes, so three codes go unused.

Answer 3 flip-flops in binary and 6 in one-hot, and 3 select bits for the 5 sources.

Worked example

A register file has 32 registers of 32 bits with two read ports. How much does it store, and how wide are its read-address inputs?

Show the solution
  1. Storage. 32×32=1024bits
  2. Address bits for one port. Choosing one of 32 registers takes ⌈log2⁡32⌉=5bits
  3. Both read ports. Two ports need 10 address bits, as in the RISC-V register file of C8.

Answer it stores 1024 bits, and each read port takes a 5-bit address, 10 address bits for the two.

Worked example

Multiplying two 8-bit numbers by repeated addition takes up to how many cycles? And by shift-and-add?

Show the solution
  1. Repeated addition. It adds the multiplicand once per unit of the multiplier, and the largest 8-bit multiplier is 28−1=255 so it takes up to 255 cycles.
  2. Shift-and-add. It handles one bit of the multiplier per cycle: 8 cycles, with the same adder and a shifter.
  3. What makes the difference. The datapath barely changes; the controller's algorithm makes the difference.

Answer up to 255 cycles by repeated addition, and 8 by shift-and-add.

Check

A multiplexer chooses among 5 inputs. How many select bits does it need?

Check

A shift-and-add multiplier handles one bit of a 16-bit multiplier per cycle at 50 MHz. How long does a multiplication take?

Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.

Check

A state machine has 9 states. How many flip-flops does binary encoding need?

Check

A register file holds 16 registers of 8 bits. How many bits does it store?

Check

A controller has 9 states.

(a)

How many flip-flops does binary encoding need?

(b)

And one-hot?

Check

A register file has 32 registers of 16 bits and 3 read ports.

(a)

How much does it store?

(b)

How many read-address bits does it need in all?

Explain why

Why do designers separate a design into a datapath and a controller?

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.