এই বইটি এখনো বাংলা ভাষায় পাওয়া যায় না। সংস্করণ: English।
High School Computer Science · শ্রেণি 10–12
12From Gates to an Arithmetic Unit
Book 1 ended its tour of logic gates with a half adder: two bits in, their sum and their carry out. A processor adds two numbers of bits each, billions of times a second, and it has no other material than such gates. This chapter builds the missing steps one at a time: an adder for three bits, an adder for whole numbers, a circuit that chooses, an arithmetic and logic unit with its flags, and finally a circuit that remembers. Each one is simulated in Python, gate by gate, and checked on every input.
You already know
A gate computes one bit from one or two bits: NOT, AND, OR, XOR, and NOR, which is NOT OR. A half adder computes for two bits: the sum bit is and the carry is . De Morgan’s laws turn an AND into an OR of negations and back. A transistor works as a switch, which is how gates are built (Book 1, grade 9). On bits, two’s complement writes as (the chapter on numbers in binary).
The gates of the chapter are Python functions on the bits and , in the module gates.py: NOT(a) returns , AND, OR and XOR use Python’s bitwise operators, and NOR(a, b) is NOT(OR(a, b)). Every circuit below is written with these five functions only.
12.1 The full adder
To add two numbers written in binary, each column adds three bits: the two digits of the column, and the carry from the column on its right. The half adder takes only two.
Definition 12.1 (Full adder)
A full adder is a circuit with three input bits , , and two output bits and such that : is the sum bit, and the carry out.
A full adder is made of two half adders and an OR gate. The first half adder adds and , the second adds the carry to their sum bit, and since the two carries cannot both be , an OR combines them.
from gates import AND, OR, XOR
def half_adder(a, b):
"""Two bits in; their sum bit and their carry out."""
return XOR(a, b), AND(a, b)
def full_adder(a, b, c):
"""Three bits in (c is the carry from the column before); sum and carry out."""
s1, c1 = half_adder(a, b)
s, c2 = half_adder(s1, c)
return s, OR(c1, c2)
if __name__ == "__main__":
print("a b c | s carry | a+b+c")
for a in (0, 1):
for b in (0, 1):
for c in (0, 1):
s, carry = full_adder(a, b, c)
assert 2 * carry + s == a + b + c # checked on all 8 rows
print(f"{a} {b} {c} | {s} {carry} | {a + b + c}")
$ python full_adder.py
a b c | s carry | a+b+c
0 0 0 | 0 0 | 0
0 0 1 | 1 0 | 1
0 1 0 | 1 0 | 1
0 1 1 | 0 1 | 2
1 0 0 | 1 0 | 1
1 0 1 | 0 1 | 2
1 1 0 | 0 1 | 2
1 1 1 | 1 1 | 3
Eight rows are all the inputs there are, so the assert of line 22 proves the circuit correct: an exhaustive check. A circuit whose outputs depend only on its present inputs, as here, is called combinational.
Definition 12.2 (Combinational and sequential circuits)
A combinational circuit computes its outputs from its present inputs only: the same inputs always give the same outputs. A sequential circuit also depends on what happened before, because some of its outputs are fed back to its inputs: it has a memory.
12.2 Chaining adders
Definition 12.3 (Ripple-carry adder)
A ripple-carry adder on bits is a row of full adders, one per column: the adder of column adds , and the carry from column , and passes its carry out to column . The first carry is an input, usually ; the last, , is the carry out of the sum.
The simulation keeps the bits of a number in a list, least significant first, so that index is the column of weight .
from full_adder import full_adder
def to_bits(x, n):
"""The n bits of x, least significant first."""
return [(x >> i) & 1 for i in range(n)]
def from_bits(bits):
return sum(bit << i for i, bit in enumerate(bits))
def add_bits(a, b, carry=0):
"""Ripple-carry addition: one full adder per column, the carry passed along."""
out = []
carries = [carry]
for x, y in zip(a, b):
s, carry = full_adder(x, y, carry)
out.append(s)
carries.append(carry)
return out, carries
if __name__ == "__main__":
for x, y in [(100, 27), (200, 100), (100, 100)]:
bits, carries = add_bits(to_bits(x, 8), to_bits(y, 8))
result = from_bits(bits)
overflow = carries[7] != carries[8] # carry into bit 7 differs from carry out
print(f"{x:3} + {y:3} = {result:3} carry out {carries[8]}"
f" signed overflow {int(overflow)} carries {carries[::-1]}")
$ python ripple.py
100 + 27 = 127 carry out 0 signed overflow 0 carries [0, 0, 0, 0, 0, 0, 0, 0, 0]
200 + 100 = 44 carry out 1 signed overflow 0 carries [1, 1, 0, 0, 0, 0, 0, 0, 0]
100 + 100 = 200 carry out 0 signed overflow 1 carries [0, 1, 1, 0, 0, 1, 0, 0, 0]
The second sum, , does not fit in bits: the result is and the carry out is , which signals the overflow for numbers read without sign. The third sum fits without sign, , but read in two’s complement, gives , a sign change no correct sum of two positive numbers can have. A signed overflow happens exactly when the carry into the last column differs from the carry out of it, which is what line 28 computes.
The same adder subtracts. Flipping every bit of gives ; adding gives , the two’s complement of . So is , modulo , and the costs nothing: it enters as the first carry .
from gates import NOT
from ripple import add_bits, from_bits, to_bits
def sub_bits(a, b):
"""a - b with the same adder: a + (b with every bit flipped) + 1."""
return add_bits(a, [NOT(bit) for bit in b], carry=1)
for x, y in [(100, 27), (27, 100), (5, 5)]:
bits, carries = sub_bits(to_bits(x, 8), to_bits(y, 8))
r = from_bits(bits)
signed = r - 256 if bits[7] else r
print(f"{x:3} - {y:3} -> {r:3} (as a signed byte {signed:4})"
f" carry out {carries[8]}")
$ python subtract.py
100 - 27 -> 73 (as a signed byte 73) carry out 1
27 - 100 -> 183 (as a signed byte -73) carry out 0
5 - 5 -> 0 (as a signed byte 0) carry out 1
12.3 Choosing and decoding
A processor computes several things at once and keeps one; it also has to turn a number, such as the number of a register, into one wire among several. Two small circuits do these jobs.
Definition 12.4 (Multiplexer, decoder)
A multiplexer with select bits has data inputs and one output, equal to the data input whose number is written by the select bits. A decoder with input bits has outputs, of which exactly one is : the one whose number is written by the inputs.
The multiplexer is : when the first AND lets through and the second gives , and the reverse when . Three of them make a multiplexer.
from gates import AND, NOT, OR
def mux2(s, x0, x1):
"""x0 if s is 0, x1 if s is 1."""
return OR(AND(NOT(s), x0), AND(s, x1))
def mux4(s1, s0, x):
"""One of the four inputs x[0..3], chosen by the two bits s1 s0."""
return mux2(s1, mux2(s0, x[0], x[1]), mux2(s0, x[2], x[3]))
def decoder2(s1, s0):
"""Four outputs; exactly the one numbered s1 s0 is 1."""
n1, n0 = NOT(s1), NOT(s0)
return [AND(n1, n0), AND(n1, s0), AND(s1, n0), AND(s1, s0)]
if __name__ == "__main__":
x = [0, 1, 1, 0]
print("inputs x0..x3 =", x)
for s1 in (0, 1):
for s0 in (0, 1):
print(f"select {s1}{s0}: mux4 -> {mux4(s1, s0, x)}"
f" decoder -> {decoder2(s1, s0)}")
$ python mux.py
inputs x0..x3 = [0, 1, 1, 0]
select 00: mux4 -> 0 decoder -> [1, 0, 0, 0]
select 01: mux4 -> 1 decoder -> [0, 1, 0, 0]
select 10: mux4 -> 1 decoder -> [0, 0, 1, 0]
select 11: mux4 -> 0 decoder -> [0, 0, 0, 1]
12.4 An arithmetic and logic unit
Definition 12.5 (Arithmetic and logic unit)
An arithmetic and logic unit (ALU) is a combinational circuit with two numbers and as inputs and an operation code; it outputs the result of the chosen operation, and some flags about that result.
Definition 12.6 (Flag)
A flag is a bit that an operation sets to describe its result, for the instructions that follow to test. The toy machine of Book 1 has three: is when the result is ; is the last bit of the result, when it is negative in two’s complement; is the carry out of an addition, and for a subtraction, when it needed a borrow; logic operations set to .
The ALU below has four operations, coded on two bits: AND , OR , ADD , SUB . Each column computes the AND, the OR and the sum of its bits; a multiplexer per column keeps the one the code asks for. For SUB, both code bits are : an AND of them flips through an XOR, and the low code bit is the first carry, which adds the of the subtraction.
from full_adder import full_adder
from gates import AND, NOT, OR, XOR
from mux import mux4
from ripple import from_bits, to_bits
OPS = {"AND": (0, 0), "OR": (0, 1), "ADD": (1, 0), "SUB": (1, 1)}
def alu(op, a, b):
"""8-bit ALU: every column computes all four results, a multiplexer keeps one."""
s1, s0 = OPS[op]
carry = s0 # SUB adds 1 through the first carry
out = []
for x, y in zip(a, b):
y2 = XOR(y, AND(s1, s0)) # flip b only for SUB
s, carry = full_adder(x, y2, carry)
out.append(mux4(s1, s0, [AND(x, y), OR(x, y), s, s]))
zero = NOT(OR(OR(OR(out[0], out[1]), OR(out[2], out[3])),
OR(OR(out[4], out[5]), OR(out[6], out[7]))))
c = AND(s1, XOR(carry, s0)) # ADD: the carry; SUB: no carry means a borrow
return out, {"Z": zero, "N": out[7], "C": c}
if __name__ == "__main__":
for op, x, y in [("AND", 12, 10), ("OR", 12, 10), ("ADD", 250, 10),
("SUB", 5, 10), ("SUB", 10, 10)]:
bits, flags = alu(op, to_bits(x, 8), to_bits(y, 8))
print(f"{op:3} {x:3} {y:3} -> {from_bits(bits):3} {flags}")
$ python alu.py
AND 12 10 -> 8 {'Z': 0, 'N': 0, 'C': 0}
OR 12 10 -> 14 {'Z': 0, 'N': 0, 'C': 0}
ADD 250 10 -> 4 {'Z': 0, 'N': 0, 'C': 1}
SUB 5 10 -> 251 {'Z': 0, 'N': 1, 'C': 1}
SUB 10 10 -> 0 {'Z': 1, 'N': 0, 'C': 0}
The flag is a NOR of all eight result bits, built as a tree of ORs and one NOT. The flag inverts the carry out for a subtraction, so that it means “borrow” as on the toy machine, and is forced to by the AND with the high code bit for the logic operations. The chapter’s tests run every operation of this ALU on pairs of numbers and compare the result and the three flags with the toy machine’s own instructions: they agree on all of them.
In practice — Faster carries
A ripple-carry adder is small but slow, since the carry crosses every column. Real processors use adders that compute the carries of a group of columns at once, from the signals (the column generates a carry) and (it propagates one), at the price of more gates. The weekend problem measures one such idea.
12.5 A circuit that remembers
Everything so far forgets its inputs as soon as they change. A register must keep a number after the wires that brought it have moved on. The trick is to feed outputs back to inputs.
Definition 12.7 (Latch, flip-flop)
A latch is a sequential circuit that keeps one bit: the SR latch is set to by its input , reset to by its input , and keeps its bit while both are . A flip-flop keeps one bit too, but changes it only at a precise moment: the D flip-flop copies its input to its output at each rising edge of a clock signal, when the clock goes from to , and ignores the rest of the time.
The simulation updates both gates at once from their previous outputs, again and again, until nothing changes.
from gates import NOR
def settle(s, r, q, qbar, steps=4):
"""Update both NOR gates at once, again and again, until nothing changes."""
seen = [(q, qbar)]
for _ in range(steps):
q, qbar = NOR(r, qbar), NOR(s, q)
if (q, qbar) == seen[-1]:
return seen, True # stable: the latch holds this state
seen.append((q, qbar))
return seen, False
q, qbar = 0, 1
for s, r, what in [(1, 0, "set"), (0, 0, "hold"), (0, 1, "reset"), (0, 0, "hold"),
(1, 1, "both"), (0, 0, "release")]:
seen, stable = settle(s, r, q, qbar)
q, qbar = seen[-1]
end = f"Q={q}" if stable else "never settles"
print(f"S={s} R={r} {what:8} {seen} -> {end}")
$ python latch.py
S=1 R=0 set [(0, 1), (0, 0), (1, 0)] -> Q=1
S=0 R=0 hold [(1, 0)] -> Q=1
S=0 R=1 reset [(1, 0), (0, 0), (0, 1)] -> Q=0
S=0 R=0 hold [(0, 1)] -> Q=0
S=1 R=1 both [(0, 1), (0, 0)] -> Q=0
S=0 R=0 release [(0, 0), (1, 1), (0, 0), (1, 1), (0, 0)] -> never settles
With both outputs are , so is no longer the opposite of ; if both inputs then drop at once, both gates see two zeros and switch to , then both see a and switch back, and so on. A real circuit does not oscillate for ever: one gate is always slightly faster, and the latch ends in a state that cannot be predicted. This is why is forbidden.
A D flip-flop is built from latches, in a way this book does not need: its behaviour is what matters. A register of bits is flip-flops that share the same clock.
class DFlipFlop:
"""Copies its input D to its output Q at a rising edge of the clock, only then."""
def __init__(self):
self.q = 0
self.clock = 0
def update(self, d, clock):
if self.clock == 0 and clock == 1: # rising edge
self.q = d
self.clock = clock
register = [DFlipFlop() for _ in range(4)] # a 4-bit register
inputs = [0b0101, 0b0101, 0b1100, 0b1100, 0b1111, 0b0011, 0b0011, 0b1000]
clocks = [0, 1, 1, 0, 0, 1, 0, 1]
for t, (d, clock) in enumerate(zip(inputs, clocks)):
for i, ff in enumerate(register):
ff.update((d >> i) & 1, clock)
q = sum(ff.q << i for i, ff in enumerate(register))
print(f"t={t} D={d:04b} clock={clock} Q={q:04b}")
$ python dff_register.py
t=0 D=0101 clock=0 Q=0000
t=1 D=0101 clock=1 Q=0101
t=2 D=1100 clock=1 Q=0101
t=3 D=1100 clock=0 Q=0101
t=4 D=1111 clock=0 Q=0101
t=5 D=0011 clock=1 Q=0011
t=6 D=0011 clock=0 Q=0011
t=7 D=1000 clock=1 Q=1000
Remark 12.8
A processor is these pieces put together: registers of flip-flops hold the numbers, an ALU computes from two of them, multiplexers and decoders choose which, and the clock makes every flip-flop take its new value at the same moment, once the slowest path through the combinational circuits has settled. The length of that path fixes how fast the clock may beat; the next chapter assembles the whole machine.
12.6 Exercises
Exercise 12.1 ★
Give the outputs of the full adder for , , , and the values of and in the figure of the full adder.
Solution
Solution of Exercise 12.1.
and ; then and the second carry is , so . Indeed , written .
Exercise 12.2 ★
Add and through a -bit ripple-carry adder, column by column: list the carries to and the sum bits.
Solution
Solution of Exercise 12.2.
. Column : , so , . Column : , so , . Column : , so , . Column : , so , . The sum is , that is .
Exercise 12.3 ★
The inputs of a multiplexer are , , , . What is the output for each of the four values of ?
Solution
Solution of Exercise 12.3.
gives , gives , gives , gives .
Exercise 12.4 ★
A decoder has input bits. How many outputs does it have, and which one is when the inputs are ?
Solution
Solution of Exercise 12.4.
outputs, numbered to ; for the output number is and the seven others are .
Exercise 12.5 ★
Write half_adder(a, b) using only NOT, AND and OR, and check it on its four rows.
Solution
Solution of Exercise 12.5.
The carry is AND(a, b); the sum is when at least one input is but not both, so it is AND(OR(a, b), NOT(AND(a, b))). The file exercises/circuits.py has it, and the tests check the four rows.
Exercise 12.6 ★★
In a full adder, the first half adder was built with an AND gate where its XOR should be. On which of the eight rows is the result wrong? Which test of the chapter would find it?
Solution
Solution of Exercise 12.6.
Six rows are wrong: every row except and . With an AND, the first “sum” is only when , so it is wrong whenever exactly one of , is (four rows); and when , the first “sum” is instead of , so the sum bit becomes , the opposite of , wrong in both rows (the carry, , stays right). The assert of full_adder.py, which tries all eight rows, stops at the third, .
Exercise 12.7 ★★
Write mux4(sel, inputs), where sel is a whole number from to and inputs a list of four bits, using mux2 only.
Solution
Solution of Exercise 12.7.
Split sel into its two bits, then choose within each pair and between the pairs:
s1, s0 = (sel >> 1) & 1, sel & 1
low = mux2(s0, inputs[0], inputs[1])
high = mux2(s0, inputs[2], inputs[3])
and the result is mux2(s1, low, high). The file exercises/circuits.py writes the three calls as one expression.
Exercise 12.8 ★★
How many gates does an -bit ripple-carry adder have? How many if the first column, whose carry in is always , uses a half adder?
Solution
Solution of Exercise 12.8.
Five gates per full adder: . With a half adder (two gates) in the first column: .
Exercise 12.9 ★★
Count the gates a signal crosses from the carry to the carry in the figure of the full adder. Deduce the length of the longest chain of gates in an -bit ripple-carry adder, assuming all the inputs are ready at the start.
Solution
Solution of Exercise 12.9.
From to the signal crosses the AND of the second half adder and the OR: gates. In column , the carry needs the XOR, then an AND, then the OR: level . Each later column adds , so is ready at level , and that is the longest chain. For bits, gates.
Exercise 12.10 ★★
A subtraction circuit flips the bits of but leaves the first carry at . What does it compute for ? In general?
Solution
Solution of Exercise 12.10.
It computes , that is modulo : gives instead of . Every result is one too small.
Exercise 12.11 ★★
Write alu_reference(op, x, y), which computes the same result and flags as the ALU with Python’s integer operators instead of gates. Why is such a second version useful?
Solution
Solution of Exercise 12.11.
For ADD, the result is (x + y) % 256 and is int(x + y > 255); for SUB, (x - y) % 256 and int(x < y); is int(r == 0) and is r >> 7 (exercises/circuits.py). Two versions written in very different ways rarely make the same mistake: comparing them on many inputs finds the mistakes of either. The tests compare the gate ALU with this one and with the toy machine.
Exercise 12.12 ★★★
From the truth table of the full adder, prove that and that , then that is also : the carry is when at least two inputs are.
Solution
Solution of Exercise 12.12.
The table shows exactly on the rows with one or three ones, an odd number; is when is odd, and XOR with flips that when , so is exactly when is odd: . The table shows exactly on the rows , , , , those with at least two ones. The term is on and ; the term on and ; their OR is on these four rows and no other. The three terms , , say “these two are ”, and their OR is exactly when at least two inputs are: the same four rows.
Exercise 12.13 ★★★
Let be with its bits flipped. Prove that , then that , and that the carry out of this sum is exactly when .
Solution
Solution of Exercise 12.13.
Bit of is , so . Then , which is modulo . The adder keeps bits, and its carry out is exactly when the true sum is at least , that is when .
Exercise 12.14 ★★★
Write comparator(x, y), which returns "<", "=" or ">" for two numbers without sign, using only the result and the carry out of the subtraction circuit.
Solution
Solution of Exercise 12.14.
Subtract from . If the result is , "="; otherwise, a carry out of means a borrow, so and the answer is "<"; a carry out of means (exercises/circuits.py). These are the flags and of the instruction CMP of the toy machine.
Exercise 12.15 ★★★
Trace the SR latch by hand, both gates updated at once, from , : first until it settles, then . Then trace the same release when the gate of is faster, so that it updates first. Explain why the inputs are forbidden.
Solution
Solution of Exercise 12.15.
With , from : both NORs see a , so the next state is , and it stays. Releasing both at once, each gate sees two zeros: ; then each sees a : ; and so on for ever, as the output of latch.py shows. If the gate of is faster, it switches first to ; the other gate then sees and stays at : the latch ends at . If the other gate is faster, it ends at . The final state depends on which gate is faster, which nobody controls; and while , is not the opposite of . Both are reasons to forbid these inputs.
12.7 Problem: Building a 64-Bit Adder
Problem 12.1
Weekend problem — the size and the speed of an adder
A processor adds numbers of bits. How many gates does its adder need, and how long is the longest chain of gates a signal must cross before the sum is ready? The program gate_count.py answers by running the adders of the chapter on levels instead of bits: each signal carries the number of gates it has crossed since the inputs.
"""Count the gates of an adder, and the longest chain of gates a signal goes through."""
count = 0
def gate(*inputs):
"""A gate seen from outside: its output is ready one level after its last input."""
global count
count += 1
return max(inputs) + 1
def full_adder(a, b, c): # the same five gates as full_adder.py, on levels
p = gate(a, b) # XOR
s = gate(p, c) # XOR
carry = gate(gate(a, b), gate(p, c)) # OR of two ANDs
return s, carry
def ripple(n, carry=0):
sums = []
for _ in range(n):
s, carry = full_adder(0, 0, carry) # the inputs are ready at level 0
sums.append(s)
return sums, carry
def carry_select(n):
"""The low half ripples; the high half is computed twice, for carry 0 and 1."""
low, c = ripple(n // 2)
high0, c0 = ripple(n // 2, 0) # assuming carry 0
high1, c1 = ripple(n // 2, 0) # assuming carry 1: a constant too, at level 0
not_c = gate(c)
chosen = [gate(gate(not_c, x0), gate(c, x1)) # a 2:1 multiplexer per bit
for x0, x1 in zip(high0 + [c0], high1 + [c1])]
return low + chosen[:-1], chosen[-1]
$ python gate_count.py
n | ripple: gates levels | carry-select: gates levels
2 | 10 5 | 22 6
4 | 20 9 | 40 8
8 | 40 17 | 76 12
16 | 80 33 | 148 20
32 | 160 65 | 292 36
64 | 320 129 | 580 68
Part I — One full adder.
- In
gate_count.py, what doesgatereturn, and why is the maximum of the inputs the right choice? - Check that its
full_adderuses the same five gates as the figure of the full adder. - With all three inputs at level , at which level are and the carry out ready?
- With and at level and the carry in at level , at which levels are and the carry out ready?
Part II — The ripple-carry adder.
- Show that the carry gains two levels at each column after the first, and deduce that is ready at level , for .
- Deduce the level of the last sum bit and of the carry out, for bits, and check them against the output.
- How many gates for , , and bits?
- If a gate takes picoseconds to switch, how long does a -bit ripple-carry addition take, and how many such additions could follow each other in one second?
- Which part of the circuit decides that time: the sum bits or the carry chain?
Part III — Carry-select.
- The carry-select adder adds the low half with a ripple adder. Explain why the high half can be computed before the carry of the low half is known.
- Why is it computed twice, and how is the right copy chosen?
- In the program, how many multiplexers are used for bits, and how many gates does each take?
- Compute the number of gates of the carry-select adder for bits, and check it for .
- At which level is the carry of the low half ready, and at which level is the output of a multiplexer ready?
- Check the depth of for bits.
Part IV — Comparing.
- For bits, compute the ratio of the gates and the ratio of the levels of the two adders.
- Split the bits into four blocks of instead of two halves, each block after the first computed twice. Estimate its depth.
- Why do processors pay for more gates to save levels?
- Is there a limit to the speed-up? Describe the shortest adder you can imagine, and what it costs.
- State the result: the gates and levels of a -bit ripple-carry adder, and what carry-select buys and costs.
Solution
Solution of Problem 12.1.
1. The level of its output: one more than the latest of its inputs, since a gate can only switch once all its inputs are there.
2. p is the XOR of and , s the XOR of p and , then two ANDs, of and and of p and , and the OR of these: five gates, as in the figure.
3. at , at ; the ANDs at and , the carry out at .
4. at , at ; the AND of and at , the AND of and at , and the carry out at .
5. By question 3, is at level ; by question 4, a carry at level gives the next one at . So are at : is at .
6. The last sum bit is at , the carry out at . The output gives for bits and for : , the carry out being the last signal ready.
7. : , , and gates.
8. ps ns, so about million additions in a row per second.
9. The carry chain: each sum bit is ready one level after its carry, so the sums wait for the carries.
10. Its inputs, the high halves of and , are there from the start; only its carry in is missing, and that carry can only be or .
11. Once assuming a carry of , once assuming ; when the low half’s carry arrives, a multiplexer per output bit keeps the copy made with the right assumption.
12. One multiplexer per sum bit of the high half and one for the carry out: . Each takes two ANDs and an OR, and the NOT of the select signal is shared by all.
13. Three ripple adders of bits, gates, plus for the multiplexers and NOT: . For , , as printed.
14. The low half is a ripple adder of bits: its carry is at level . The high halves are ready earlier, at level at most. The NOT of the carry is at , the AND that uses it at , the OR at .
15. .
16. times the gates, for times the levels.
17. The first block of bits gives its carry at level . The three other blocks are computed both ways in parallel, and ready at level too. Each multiplexer stage adds levels to the chosen carry: after the second block, after the third, and the outputs of the last block at about . The gates grow again, to about .
18. Every instruction must finish within one beat of the clock, so the slowest circuit sets the speed of the whole processor. Gates are tiny and cheap, counted in billions on one chip; time is not.
19. More blocks, and blocks inside blocks, reduce the depth further: adders used in processors make the depth grow much more slowly than the number of bits, so that doubling the bits adds only a few levels. The shortest imaginable adder writes each output as one OR of ANDs of the inputs, two levels deep, but the cost explodes: for the top carry of bits, the OR would need on the order of AND terms, each with up to inputs. Speed always costs gates, and two levels cost exponentially many.
20. A -bit ripple-carry adder needs gates, five per full adder, and its longest chain crosses gates, the carry gaining two levels per column. A carry-select adder of two halves needs gates, times as many, and levels, times as many: it nearly halves the delay for less than twice the gates.