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

S3 · Lesson 15 · Arithmetic lab

Prefix adders, Booth recoding, Dadda trees and Newton–Raphson, bit-exact in Python

Arithmetic hardware is easiest to trust when it has been modeled bit for bit and compared against plain integer arithmetic on thousands of inputs. This lab builds the models that hardware designers keep beside their RTL: a Kogge–Stone adder that counts its own levels, a radix-4 Booth recoder, a Dadda-tree stage counter, and a Newton–Raphson reciprocal whose correct bits double each step. Each one checks a formula from lessons 8 to 11 against the thing itself.

  • The stems are the correct bits of a Newton–Raphson reciprocal after k iterations, starting from a seed accurate to the slider's number of bits.
  • Each iteration squares the error, so the correct bits double: an 8-bit table seed reaches 64 bits in three steps.
  • The dashed line marks the 53 bits of a double's significand.

Predict

Radix-4 Booth recoding turns each pair of multiplier bits, with the bit below them, into a digit −2y2i+1+y2i+y2i−1. What digits does the 8-bit multiplier 0x5D (93) give, least significant first?

Name it

What the lab builds

  • Kogge–Stone: bitwise gi=aibi, pi=ai⊕bi; then log2⁡N levels of the prefix operator (G,P)∘(G′,P′)=(G+PG′,PP′) at spans 1, 2, 4, …; the carry into bit i is the group generate Gi−1:0, and si=pi⊕ci.
  • Booth radix 4: digits di=−2y2i+1+y2i+y2i−1 with y=∑di4i for two's complement y.
  • Dadda: the heights 2, 3, 4, 6, 9, 13, 19, … (each ⌊1.5×⌋ the last); h rows need as many stages as there are heights below h.
  • Newton–Raphson: xk+1=xk(2−dxk), with 1−dxk+1=(1−dxk)2.

Check

Write ks_add(a, b, n): add two n-bit unsigned numbers (n a power of two) with a Kogge–Stone prefix network, returning (sum mod 2n, number of prefix levels). Build it from g, p and the prefix operator; don't use a + b.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write booth4(y, n): the radix-4 Booth digits of the n-bit two's complement number y (n even), least significant first.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write dadda_stages(h): the number of reduction stages a Dadda tree needs to bring h rows down to 2.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Write nr_bits(d, x0, k): run k Newton–Raphson steps for 1/d from x0 and return the number of correct bits, −log2⁡|1−dxk|. Then check that the bits double.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

Why is radix-4 Booth recoding worth its extra logic in a multiplier?