Section 3 · Revision

Computer Organization and Architecture formula sheet

Addressing modes, ALU and control formulas, cache and AMAT equations, I/O overhead and pipeline timing on one page for last-minute revision.

Full notes Section test

Instruction set and addressing modes

Mode Effective address / operand Data memory accesses for operand Typical use
Immediate operand =A= A 0 constants
Register operand =R= R 0 temporaries
Direct (absolute) EA=AEA = A 1 globals
Memory indirect EA=M[A]EA = M[A] 2 pointers in memory
Register indirect EA=REA = R 1 *p
Base + displacement EA=R+AEA = R + A 1 locals (frame pointer), struct fields
Indexed EA=A+RidxEA = A + R_{idx} (times scale) 1 arrays
PC-relative EA=PCnext+offsetEA = PC_{next} + \text{offset} 1 branches, position-independent code
Auto-increment (R)+(R)+ EA=REA = R, then R+=sR \mathrel{+}= s 1 step through array, pop
Auto-decrement −(R)-(R) R−=sR \mathrel{-}= s, then EA=REA = R 1 push
  • Field width for NN choices: ⌈log⁡2N⌉\lceil \log_2 N \rceil bits. Address field == instruction length minus all other fields.

  • Signed nn-bit immediate or offset: −2n−1-2^{n-1} to 2n−1−12^{n-1} - 1. Unsigned: 00 to 2n−12^n - 1.

  • Branch target: PCnext+offset×(instruction size, if offset counts instructions)PC_{next} + \text{offset} \times \text{(instruction size, if offset counts instructions)}. Read whether PC is already incremented.

  • Expanding opcode: kk-bit primary opcode, XX instructions used at that level, aa-bit field given up: next level has at most (2k−X)⋅2a(2^k - X) \cdot 2^a instructions. Work level by level; to fit a lower level you may need to reserve whole patterns.

  • Little-endian: least significant byte at the lowest address.

  • Z=A+BZ = A + B: 3-address ADD Z, A, B; 2-address MOV Z, A; ADD Z, B; accumulator LOAD A; ADD B; STORE Z; stack PUSH A; PUSH B; ADD; POP Z. Stack binary ops pop yy, then xx, push xx op yy.

ALU and control unit design

Item Formula
nn-bit two's complement range −2n−1-2^{n-1} to 2n−1−12^{n-1} - 1
Overflow (signed add) V=cn⊕cn−1V = c_n \oplus c_{n-1}; same-sign operands give a different-sign result
Carry flag (unsigned) carry out of the top bit
Negate invert all bits, add 1
Sign extension copy the sign bit into new high bits (value unchanged)
Arithmetic shift right by 1 floor division by 2, sign bit kept
Product width n×nn \times n bits gives 2n2n bits

Adders:

  • Ripple carry, carry delay tct_c per full adder, sum delay tst_s: cnc_n at ntcn t_c, top sum at (n−1)tc+ts(n-1) t_c + t_s. Delay is O(n)O(n).
  • Carry lookahead: Gi=AiBiG_i = A_i B_i, Pi=Ai⊕BiP_i = A_i \oplus B_i, Ci+1=Gi+PiCiC_{i+1} = G_i + P_i C_i.
  • C2=G1+P1G0+P1P0C0C_2 = G_1 + P_1 G_0 + P_1 P_0 C_0; C3=G2+P2G1+P2P1G0+P2P1P0C0C_3 = G_2 + P_2 G_1 + P_2 P_1 G_0 + P_2 P_1 P_0 C_0.
  • Single-level CLA: P,GP, G in 1 gate delay, carries 2 more, sums 1 more. Fan-in grows with nn.
  • CLA blocks in ripple: first block carry at tPG+tblkt_{PG} + t_{blk}, then +tblk+t_{blk} per block.
  • Carry select: upper blocks compute both carry-in cases; a mux chain picks. About one block ripple plus one mux per later block.

Booth (radix 2), pair (qi,qi−1)(q_i, q_{i-1}) with q−1=0q_{-1} = 0: 00 or 11 shift only; 01 add multiplicand; 10 subtract multiplicand. Alternating bits are the worst case.

Control units:

Hardwired Microprogrammed
Speed faster slower (control memory read per step)
Change redesign logic rewrite control memory
Typical ISA RISC CISC
Sequencing ⌈log⁡2T⌉\lceil \log_2 T \rceil-bit step counter + decoder microprogram counter + opcode mapping

Microinstruction width, SS control signals:

  • Horizontal: SS bits for control, many signals in parallel.
  • Fully vertical (one signal at a time, plus a "none" code): ⌈log⁡2(S+1)⌉\lceil \log_2 (S + 1) \rceil bits; needs a decoder.
  • Grouped encoding with mutually exclusive groups g1,…,gmg_1, \ldots, g_m: ∑i⌈log⁡2(gi+1)⌉\sum_i \lceil \log_2 (g_i + 1) \rceil bits.
  • Next-address field: ⌈log⁡2W⌉\lceil \log_2 W \rceil bits for WW control words. Condition select: ⌈log⁡2(conditions)⌉\lceil \log_2 (\text{conditions}) \rceil bits.
  • Control memory size =W×= W \times word width.

Memory hierarchy and cache

Address split for capacity CC, block BB, associativity kk, address width nn:

Field Bits
Offset log⁡2B\log_2 B
Sets S=C/(Bk)S = C / (B k)
Index log⁡2S\log_2 S (0 if fully associative)
Tag n−index−offsetn - \text{index} - \text{offset}
  • Tag store == lines ×\times (tag + valid + dirty + replacement bits). Lines =C/B= C / B.
  • A kk-way cache needs kk tag comparators and a kk-to-1 mux. Exact LRU per set: ⌈log⁡2k!⌉\lceil \log_2 k! \rceil bits.
  • VIPT without aliasing: C/k≤C / k \le page size.
  • Chips needed =total wordschip words×word widthchip width= \dfrac{\text{total words}}{\text{chip words}} \times \dfrac{\text{word width}}{\text{chip width}}.

Average access time:

Organisation One level Two levels
Hierarchical (miss pays every level visited) tc+(1−h)tmt_c + (1 - h) t_m t1+m1(t2+m2tm)t_1 + m_1 (t_2 + m_2 t_m)
Simultaneous (served by the first level that has it) htc+(1−h)tmh t_c + (1 - h) t_m h1t1+m1h2t2+m1m2tmh_1 t_1 + m_1 h_2 t_2 + m_1 m_2 t_m
  • m2m_2 above is the local L2 miss rate. Global L2 miss rate =m1m2= m_1 m_2, so hierarchical T=t1+m1t2+mglobaltmT = t_1 + m_1 t_2 + m_{global} t_m.
  • Given a "miss penalty": T=thit+m×penaltyT = t_{hit} + m \times \text{penalty}.
  • Block of ww words, bus cycles (1 for address, 1 per word): non-interleaved 1+w tacc+w1 + w\, t_{acc} + w; ww-way interleaved 1+tacc+w1 + t_{acc} + w.
  • TLB plus physical cache: T=tTLB+mTLB⋅L⋅tm+tc+mctmT = t_{TLB} + m_{TLB} \cdot L \cdot t_m + t_c + m_c t_m for an LL-level page table walk with uncached entries.

Write policies:

Policy Bus traffic per reference
Write-through, no-write-allocate (ww bytes per write) frmrB+fwwf_r m_r B + f_w w
Write-back, write-allocate mB(1+pdirty)m B (1 + p_{dirty})
  • Usual pairs: write-through with no-write-allocate and a write buffer; write-back with write-allocate.
  • Write-back read miss with dirty victim: two block transfers.

Misses (3C): compulsory depends only on distinct blocks touched; capacity on size; conflict is the extra over fully associative, cut by associativity. Larger blocks first cut misses, then raise misses and penalty.

Array loops, row-major A[R][C]A[R][C], element size ss, address =base+(iC+j)s= base + (iC + j)s:

  • Row-wise read, cold cache: misses =RCs/B= R C s / B.
  • Column-wise: if every block touched by one column stays resident until the next column, misses =RCs/B= R C s / B; if each column pass evicts its own blocks, every access misses (RCR C). Otherwise simulate.
  • Two arrays exactly a multiple of the cache size apart thrash a direct-mapped cache; 2-way fixes it.

Inclusion: inclusive means every L1 block is also in L2 (L2 eviction invalidates L1); exclusive holds L1 + L2 distinct data. A victim cache keeps recent L1 evictions.

I/O interface: interrupts and DMA

Quantity Formula
Polling CPU fraction polls per second ×\times cycles per poll // clock rate
Interrupt CPU fraction ratebytes per interrupt×\dfrac{\text{rate}}{\text{bytes per interrupt}} \times cycles per interrupt // clock
DMA CPU fraction rateblock size×\dfrac{\text{rate}}{\text{block size}} \times setup and completion cycles // clock
Burst DMA, CPU off the bus (block/bus width)×(\text{block} / \text{bus width}) \times bus cycle
Cycle stealing, fraction of bus cycles ratebytes per cycle×\dfrac{\text{rate}}{\text{bytes per cycle}} \times bus cycle time
Max rate under a CPU budget ff f×f \times clock // cycles per interrupt ×\times bytes per interrupt
Serial line characters per second bits per second // bits per character
  • Programmed I/O: CPU busy-waits and moves every word. Interrupt-driven: CPU moves every word inside the ISR. DMA: CPU only sets up and handles the completion interrupt.
  • Interrupts are recognised at the end of an instruction; PC and status are saved first.
  • Interrupt latency for a lower-priority device (non-nested) == rest of current instruction ++ every higher ISR (entry + body + return) ++ its own entry.
  • Priority: daisy chain by position (nearest the CPU wins); software polling by polling order; vectored interrupts give the ISR address directly.
  • DMA modes: burst (CPU locked out for the block), cycle stealing (one word per stolen cycle), transparent (idle bus cycles only, CPU never slowed). Bus request and grant first; interrupt at block end.
  • Memory-mapped I/O uses ordinary load and store; isolated I/O uses IN/OUT and a separate address space.

Instruction pipelining and hazards

Quantity Formula
Clock period tp=max⁡iτi+dt_p = \max_i \tau_i + d (latch delay dd)
Non-pipelined time per instruction tn=∑iτit_n = \sum_i \tau_i
nn instructions, kk stages, no stalls (k+n−1) tp(k + n - 1)\, t_p
With stalls (k+n−1+stall cycles) tp(k + n - 1 + \text{stall cycles})\, t_p
Speedup n tn(k+n−1) tp→tntp\dfrac{n\, t_n}{(k + n - 1)\, t_p} \to \dfrac{t_n}{t_p} (=k= k if balanced, no overhead)
Efficiency speedup /k/ k
CPI with stalls 1+∑(frequency×stall cycles)1 + \sum (\text{frequency} \times \text{stall cycles})
Speedup with stalls (balanced) depth /(1+stalls per instruction)/ (1 + \text{stalls per instruction})
Stages needed for clock ≤T\le T smallest kk with τ/k+d≤T\tau / k + d \le T

Branches:

  • Resolved at the end of stage ss: penalty s−1s - 1 cycles if the guess is wrong.
  • Predict not-taken: CPI =1+fb⋅ptaken⋅P= 1 + f_b \cdot p_{taken} \cdot P.
  • Dynamic predictor with accuracy aa: CPI =1+fb(1−a)P= 1 + f_b (1 - a) P (plus any cost on correct taken predictions if stated).
  • Delay slot instruction always executes. Earlier resolution, BTB and filled delay slots cut the penalty; deeper front ends raise it.

Data hazards in the classic 5-stage pipeline (IF, ID, EX, MEM, WB):

Producer to next instruction No forwarding, split-cycle register file No forwarding, no split Full forwarding
ALU to ALU 2 stalls 3 stalls 0
Load to use 2 stalls 3 stalls 1 stall
Producer two instructions back 1 stall 2 stalls 0 (from MEM/WB)
  • Only RAW hazards occur in an in-order 5-stage pipeline. WAR and WAW appear with out-of-order or multi-cycle units; register renaming removes both.
  • Structural hazard: shared resource in the same cycle, such as one memory port for IF and MEM (1 stall per load or store), or a non-pipelined multi-cycle unit (next user waits until it frees).
  • Unequal stages: the slowest stage sets the clock. Splitting it helps only until another stage becomes the slowest.
  • Deeper is not always better: tp>dt_p > d always, and hazard penalties grow with depth.
  • "Speedup for large nn" with stalls: tn/(CPI⋅tp)t_n / (\text{CPI} \cdot t_p).