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
addthe data memory sits idle, forswnothing is written back, and forbeqthe ALU compares and the PC takes the branch target.
Predict
In a single-cycle processor, which instruction sets the length of the clock period?
lw. Its path is the longest: read the instruction, read the base register, add the offset, read data memory, and write the result back to the register file before the next clock edge. Every instruction gets that much time, even the ones that need much less.
Name it
The datapath
| Unit | Does |
|---|---|
| PC | a 32-bit register holding the current instruction's address |
| instruction memory | reads the instruction at the PC |
| register file | reads two registers (rs1, rs2) and, at the clock edge, writes one (rd) |
| immediate extender | builds the 32-bit immediate from the instruction's fields (I, S, B or J layout) |
| ALU | adds, subtracts, compares, does logic |
| data memory | read by loads, written by stores |
| adders | PC + 4, and PC + offset for branches and jumps |
Control
The control unit decodes the opcode (and funct3 and funct7) into signals:
| Instruction | RegWrite | ImmSrc | ALUSrc | MemWrite | Result | Next PC |
|---|---|---|---|---|---|---|
lw | 1 | I | immediate | 0 | memory | PC + 4 |
sw | 0 | S | immediate | 1 | none | PC + 4 |
| R-type | 1 | none | register | 0 | ALU | PC + 4 |
addi | 1 | I | immediate | 0 | ALU | PC + 4 |
beq | 0 | B | register | 0 | none | PC + offset if equal |
jal | 1 | J | none | 0 | PC + 4 | PC + 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:
The single-cycle CPI is exactly 1, but is long, and every instruction pays for the slowest one.
Worked example
A single-cycle processor has = 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
- Add up the longest path.
- Frequency.
- 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
- The new longest path. It grows by 300 − 120 = 180 ps:
- The new clock. It falls from 1.33 GHz to 1.08 GHz.
- Who pays. Every instruction slows down by 24%, including the 98% of them that aren't multiplies.
- 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
- CPI.
- Time per instruction. Each cycle is 200 + 50 = 250 ps: which is 37% slower than the single-cycle design.
- Why. Splitting the work saves the idle time of short instructions, but each step pays the register overhead and the steps aren't balanced.
- 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 = 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.
- Subtract in the ALU and check for zero
- Read the instruction at the PC
- Read t0 and t1 from the register file, and build the branch offset from the immediate fields
- 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 = 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?
The clock period is fixed, so it has to be long enough for the slowest instruction to finish, and that's the load, whose path runs through the instruction memory, the register file, the ALU, the data memory and back to the register file. Most instructions are adds, branches and other operations that skip the data memory or the write-back, so they finish early and then sit idle until the next clock edge. Adding any slow unit, like a multiplier, makes it worse, because it stretches the period for every instruction, not just the ones that use it.
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.