Draft preview. Lessons are being written and reviewed.

Digital Design / Module 8: Arithmetic and datapaths

45. Multipliers and Booth encoding

Understand the block behind every AI chip.

Lecture coming soon

See it move

The idea

Binary multiplication is shift and add, just as with long multiplication on paper. Each bit of B decides whether a shifted copy of A is added to the total. The product of N-bit and M-bit numbers needs N + M bits.

A sequential multiplier

With one adder and N cycles, area is small and is low.

always_ff @(posedge clk)
  if (start) begin
    acc <= '0;
    a_s <= a;
    b_s <= b;
    cnt <= N;
  end else if (cnt != 0) begin
    if (b_s[0]) acc <= acc + a_s;
    a_s <= a_s << 1;
    b_s <= b_s >> 1;
    cnt <= cnt - 1'b1;
  end

Parallel multipliers

To produce a result quickly, generate all partial products at once, then add them in a tree. Wallace and Dadda trees use carry-save adders, which reduce three numbers to two without waiting for carries. A fast adder then finishes the job. Depth grows roughly with log(N), rather than with N.

Booth recoding

Fewer partial products mean less hardware. Radix-4 Booth recoding looks at overlapping groups of three bits of B, and turns them into digits from -2 to +2. Each digit is easy to produce from A by shifting or inverting, so an N-bit multiplication needs only about N/2 partial products. It also handles signed numbers directly. Try several B values in the animation above to see the digits.

Why it matters

Multipliers are the most-repeated block in AI accelerators, DSPs and GPUs. A matrix engine can contain thousands, so small savings add up.

Common mistake

Writing a * b casually, as if it were cheap. It is a single line of RTL, and a large block of logic. Also mind the width: wire [7:0] p = a * b with 8-bit inputs silently discards the top half of the product.

Key ideas

  • Multiplication adds shifted partial products.
  • Booth recoding reduces the number of partial products.
  • Tree structures reduce depth.

Your exercise

Write a sequential shift-add multiplier.

Find the bug

This code has one deliberate bug. Read the symptom, then click the line you think is wrong.

What goes wrong: 10 x 10 is right, but 100 x 100 gives 16 instead of 10000.

Interview questions

coreProduct width of N x M bits?

basicMultiply 1011 by 1101 using shift-and-add, showing the partial products.

basicWith 8-bit a and b both equal to 20, what does p hold, and why?

input  [7:0] a, b;
wire   [7:0] p = a * b;

coreCompare a sequential shift-add multiplier with a fully parallel one.

coreGive the radix-4 Booth digits for the 8-bit value B = 00111100 (60). How many non-zero partial products result?

corea and b are 8-bit unsigned, both equal to 20. Why does p hold 144 here, even though p is 16 bits wide?

input  [7:0]  a, b;
wire   [15:0] p;
assign p = {a * b};

coresa is declared signed and holds -3, ub is unsigned and holds 5. Why does p show 1265 instead of -15?

reg signed [7:0]  sa;
reg        [7:0]  ub;
wire signed [15:0] p = sa * ub;

advancedWhy does radix-4 Booth recoding handle signed (two's complement) multipliers directly, and how is a negative digit applied?

advancedA carry-save tree reduces partial products 3 rows to 2 at each level. How many levels does it need to reduce 16 rows to 2?

Practise these 9 questions with animations