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

C8 · Lesson 35 · The single-cycle processor

A datapath and its control, one instruction per clock

Everything so far treated the processor as something that runs instructions. Now look inside. A processor is a datapath (the program counter, the instruction memory, the register file, an ALU, the data memory, and multiplexers between them) plus control logic that reads each instruction's opcode and sets the multiplexers and write enables. In the simplest design every instruction finishes in one clock cycle, which is easy to understand and makes the cost plain: the clock has to be slow enough for the slowest instruction, and every other instruction waits for it.

  • The program runs one of each kind of instruction: a load, two ALU operations, a store and a branch. Step it one instruction at a time with the datapath showing.
  • For lw, the lit wires go through every unit: instruction memory, register file, ALU (adding the offset), data memory, and back to the register file.
  • For add the data memory sits idle, for sw nothing is written back, and for beq the ALU compares and the PC takes the branch target.

Predict

In a single-cycle processor, which instruction sets the length of the clock period?

Name it

The datapath

UnitDoes
PCa 32-bit register holding the current instruction's address
instruction memoryreads the instruction at the PC
register filereads two registers (rs1, rs2) and, at the clock edge, writes one (rd)
immediate extenderbuilds the 32-bit immediate from the instruction's fields (I, S, B or J layout)
ALUadds, subtracts, compares, does logic
data memoryread by loads, written by stores
addersPC + 4, and PC + offset for branches and jumps

Control

The control unit decodes the opcode (and funct3 and funct7) into signals:

InstructionRegWriteImmSrcALUSrcMemWriteResultNext PC
lw1Iimmediate0memoryPC + 4
sw0Simmediate1nonePC + 4
R-type1noneregister0ALUPC + 4
addi1Iimmediate0ALUPC + 4
beq0Bregister0nonePC + offset if equal
jal1Jnone0PC + 4PC + offset

Timing

Everything between the PC's output and the next clock edge is combinational, so the clock period must cover the longest path, which is the load's:

Tc=tpcq+timem+tRFread+tALU+tdmem+tmux+tRFsetup

The single-cycle CPI is exactly 1, but Tc is long, and every instruction pays for the slowest one.

Worked example

A single-cycle processor has tpcq = 40 ps, memories of 200 ps, a register-file read of 100 ps, an ALU of 120 ps, a multiplexer of 30 ps and a register-file setup of 60 ps. What is its clock period and frequency?

Show the solution
  1. Add up the longest path. Tc=40+200+100+120+200+30+60=750ps
  2. Frequency. f=1750ps=1.33GHz
  3. An add. It doesn't use the data memory, so it's done after 550 ps and idles for the other 200, 27% of the cycle.

Answer a clock period of 750 ps, 1.33 GHz.

Worked example

A 300 ps multiplier is added beside the 120 ps ALU, with results chosen by the same path. What happens to the clock?

Show the solution
  1. The new longest path. It grows by 300 − 120 = 180 ps: 750+180=930ps
  2. The new clock. It falls from 1.33 GHz to 1.08 GHz.
  3. Who pays. Every instruction slows down by 24%, including the 98% of them that aren't multiplies.
  4. What real designs do. They give a slow unit several cycles instead, which is the idea behind multicycle and pipelined processors.

Answer the clock falls from 1.33 GHz to 1.08 GHz, and every instruction slows down by 24%.

Worked example

A multi-cycle version of the same processor clocks at the memory's 200 ps plus 50 ps of register overhead. Loads take 5 cycles, stores and R-type 4, branches 3. With 25% loads, 10% stores, 50% R-type and 15% branches, how does it compare with the single-cycle 750 ps?

Show the solution
  1. CPI. CPI=0.25(5)+0.10(4)+0.50(4)+0.15(3)=4.1
  2. Time per instruction. Each cycle is 200 + 50 = 250 ps: 4.1×250=1025ps which is 37% slower than the single-cycle design.
  3. Why. Splitting the work saves the idle time of short instructions, but each step pays the register overhead and the steps aren't balanced.
  4. Where it wins. The multi-cycle design wins on hardware (one memory, one adder) and loses on speed; pipelining is what makes the short steps pay.

Answer 1025 ps per instruction, 37% slower than the single-cycle 750 ps.

Check

A single-cycle processor has tpcq = 30, memory reads of 150, a register-file read of 120, an ALU of 180, a mux of 20 and register-file setup of 40 (all ps).

(a)

What is the minimum clock period?

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

(b)

What is the highest clock frequency?

Check

A single-cycle processor's clock period is 850 ps, set by lw, whose path includes a 150 ps data-memory read.

(a)

How long do 50 million instructions take?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

What percentage of each cycle does an add, which skips the data memory, spend idle?

Check

A designer replaces the 250 ps data memory of a 700 ps single-cycle processor with one 50 ps faster.

(a)

What is the new clock period, if lw is still the slowest?

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

(b)

How many times faster does every program run?

Check

Which control signal differs between add t0, t1, t2 and addi t0, t1, 5?

Check

What are RegWrite and MemWrite for sw t0, 8(sp)?

Check

Put the steps of beq t0, t1, loop in a single-cycle processor in order.

  1. Subtract in the ALU and check for zero
  2. Read the instruction at the PC
  3. Read t0 and t1 from the register file, and build the branch offset from the immediate fields
  4. Load PC + offset into the PC at the clock edge if they were equal, PC + 4 otherwise

Check

A multi-cycle processor clocks at the memory's 200 ps plus 60 ps of overhead. Loads (25%) take 5 cycles, stores (15%) 4, branches (10%) 3 and everything else 4.

(a)

What's its CPI?

(b)

What's its average time per instruction?

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

Check

A single-cycle processor has tpcq = 30 ps, memories of 150 ps, a register-file read of 120 ps, an ALU of 180 ps, a multiplexer of 25 ps and a register-file setup of 40 ps.

(a)

What's the clock period, set by a load?

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

(b)

What share of the cycle does an add leave idle?

Explain why

Why does a single-cycle processor waste time on most instructions?

Practice

Keep practicing

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