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

C8 · Lesson 37 · The multi-cycle processor

One memory, one ALU, and an instruction spread over several clocks

The single-cycle processor gives every instruction one long clock, as long as a load needs, and it needs an instruction memory, a data memory, an ALU and two more adders, because everything happens at once. Split each instruction into short steps instead, one per clock, and one memory and one ALU can be reused from step to step. Short instructions take fewer steps. Whether that's faster depends on how evenly the steps divide the work, and the arithmetic is the same one that decides how deep to pipeline.

  • The flat line is the single-cycle processor: 750 ps per instruction, whatever it is.
  • The rising line is the multi-cycle processor: loads take 5 steps, branches 3 and everything else 4, so its average time depends on the share of loads (along the bottom) and branches (slider).
  • Slide the step time. At 250 ps the multi-cycle design is slower for any mix; it would need steps of about 180 ps to break even, and real steps can't shrink that far, because the memory alone takes 200 ps.

Predict

The multi-cycle processor's clock is 250 ps, and beq takes 3 steps. How long does a branch take, against the single-cycle processor's 750 ps?

Name it

Steps and the registers between them

Each step does one major operation (a memory access, a register-file access or an ALU operation) and saves its result in a register for the next step. Those nonarchitectural registers are invisible to programs: IR (the instruction), OldPC, A and B (the two source registers), ALUOut and Data (a word read from memory). IR is needed because the one memory is used again for data, so the instruction must be kept somewhere.

StepDoes
FetchIR ← memory[PC]; the ALU computes PC + 4
Decoderead rs1 and rs2 into A and B; the ALU computes OldPC + immediate, the branch target
MemAdrALUOut ← A + immediate (loads and stores)
MemRead / MemWriteData ← memory[ALUOut], or memory[ALUOut] ← B
ExecuteR / ExecuteIALUOut ← A op B, or A op immediate
Write backrd ← Data or ALUOut
Branchcompare A and B; if equal, PC ← target

So lw takes 5 cycles (Fetch, Decode, MemAdr, MemRead, write back), sw 4, R-type and I-type 4, beq 3 and jal 4.

Control is a state machine

The control unit becomes a finite state machine, one state per step, that branches after Decode according to the opcode and returns to Fetch when the instruction is done. About a dozen states cover these instructions. Each state's outputs are the control signals for that step.

Timing and performance

The clock must fit the slowest step, typically

Tc=tpcq+tmux+max⁡(tALU+tmux,tmem)+tsetup

and an instruction's time is its cycle count times Tc. Averaged over a program,

CPI=∑ifici,t=CPI×Tc

Why it matters

The multi-cycle processor uses less hardware: one memory, one ALU, a few registers. It's rarely faster than the single-cycle design, because the steps are unequal and each one pays the register overhead. But it introduced the idea that makes processors fast: if an instruction is a sequence of short steps, different instructions can be in different steps at the same moment. That's pipelining, the subject of lessons 39 and 40.

Worked example

A multi-cycle processor has tpcq = 40 ps, multiplexers of 30 ps, an ALU of 120 ps, a memory of 200 ps and a register setup of 50 ps. A program is 25% loads, 10% stores, 11% branches, 2% jumps and 52% R-type. How long does an instruction take on average?

Show the solution
  1. Find the slowest step. The ALU path is 120 + 30 = 150 ps, shorter than the memory's 200, so Tc=40+30+200+50=320ps
  2. CPI. CPI=0.25(5)+0.10(4)+0.11(3)+0.02(4)+0.52(4)=4.14
  3. Time per instruction. 4.14×320≈1325ps which is 1.77 times the single-cycle 750 ps.
  4. Break-even. To break even the steps would need to be 750/4.14 = 181 ps, less than the memory takes.

Answer 1325 ps per instruction on average, 1.77 times the single-cycle 750 ps.

Worked example

A loop body of lw, add, addi and bne runs 1000 times. How many cycles does the multi-cycle processor take at 320 ps, and how does it compare with the single-cycle one at 750 ps?

Show the solution
  1. Cycles per pass. lw, add, addi and bne take 5+4+4+3=16cycles
  2. The whole loop. 16,000 cycles at 320 ps: 16,000×320ps=5.12μs
  3. Single-cycle. It runs 4000 instructions at 750 ps: 3.0 µs.
  4. Compare. The multi-cycle design is 1.7 times slower on this loop, which is 25% loads and 25% branches.

Answer 16,000 cycles, 5.12 µs, against 3.0 µs for the single-cycle processor.

Worked example

What hardware does the multi-cycle design save, and what does it add?

Show the solution
  1. It saves a memory. Instructions and data share one, with a multiplexer choosing PC or ALUOut as the address.
  2. It saves both extra adders. The ALU computes PC + 4 during Fetch and the branch target during Decode, steps when it's otherwise idle.
  3. It adds registers. Six 32-bit registers, IR, OldPC, A, B, ALUOut and Data: 192 flip-flops.
  4. It adds control. A few wider multiplexers, and a control unit that is a state machine instead of a truth table.

Answer it saves a memory and two adders, and adds six 32-bit registers (192 flip-flops), a few wider multiplexers and a state-machine control unit.

Check

A program is 25% loads, 8% stores and 20% branches; the rest are R-type. The multi-cycle clock is 320 ps.

(a)

What's the CPI?

(b)

What's the average time per instruction?

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

Check

A multi-cycle datapath has tpcq = 30 ps, multiplexers of 25 ps, an ALU of 250 ps, a memory of 200 ps and a setup time of 40 ps.

(a)

What's the clock period?

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

(b)

How long does a load take?

Check

A loop body has 1 loads, 5 R-type instructions and one branch, and runs 100 times.

(a)

How many cycles does it take on the multi-cycle processor?

(b)

And on the single-cycle one?

Check

Put the multi-cycle steps of lw t1, 8(t0) in order.

  1. Data ← memory[ALUOut]
  2. IR ← memory[PC], and the ALU computes PC + 4
  3. ALUOut ← A + 8
  4. t1 ← Data
  5. Read t0 into A

Check

Why does the multi-cycle processor need the IR register, when the single-cycle one doesn't?

Check

Adding instructions grows the control state machine to 13 states.

(a)

How many flip-flops does a binary state encoding need?

(b)

And a one-hot encoding?

Check

A single-cycle processor runs at period T; a multi-cycle one averages c cycles per instruction.

Step 1

Below what step time is the multi-cycle design faster?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

The multi-cycle processor is usually slower than the single-cycle one. Why was it worth inventing?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.