Professional Documents
Culture Documents
Computer Architecture
Chapter 4
The Processor
Introduction
AND-gate Adder
Y=A&B Y=A+B
A
A Y
Y +
B
B
M A
I0
u Y ALU Y
I1 x
B
S
F
7 COMP 140 – Summer 2014
Sequential Elements
Clk
D Q
D
Clk
Q
Clk
D Q Write
Write
Clk
D
Q
n Datapath
§ Elements that process data and addresses
in the CPU
– Registers, ALUs, mux’s, memories, …
n We will build a MIPS datapath incrementally
§ Refining the overview design
Increment
by 4 for next
32-bit instruction
register
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
op rs rt constant or address
6 bits 5 bits 5 bits 16 bits
n Examples:
§ lw $t0, 32($s3)
§ beq rs, rt, L1
Just
re-routes
wires
Sign-bit wire
replicated
Load/
35 or 43 rs rt address
Store
31:26 25:21 20:16 15:0
Branch 4 rs rt address
31:26 25:21 20:16 15:0
rd rs rt
add $t1,$t2,$t3
26 COMP 140 – Summer 2014
op rs rt constant or address
Load Instruction 6 bits 5 bits 5 bits 16 bits
rt rs
lw $t1,offset($t2)
27 COMP 140 – Summer 2014
op rs rt constant or address
Branch-on-Equal 6 bits 5 bits 5 bits 16 bits
rs rt
beq $t1,$t2,offset
28 COMP 140 – Summer 2014
Implementing Jumps
Jump 2 address
31:26 25:0
1.5hrs) ≈ 4 (# of stages)
32 COMP 140 – Summer 2014
MIPS Pipeline
Instr 1 IF ID EX MEM WB
Instr 2 IF ID EX MEM WB
Instr 3 IF ID EX MEM WB
Time à
33 COMP 140 – Summer 2014
Pipeline Performance
Prediction
correct
Prediction
incorrect
MEM
Right-to-left WB
flow leads to
hazards
Soon…
128 bits
64 bits
97 bits
64 bits
56 COMP 140 – Summer 2014
Pipeline Operation
Wrong
register
number
IF ID EX DM WB
IF ID EX DM WB
IF ID EX DM WB
IF ID EX DM WB
IF ID EX DM WB
n EX hazard
§ if (EX/MEM.RegWrite and (EX/MEM.RegisterRd ≠ 0)
and (EX/MEM.RegisterRd = ID/EX.RegisterRs))
ForwardA = 10
§ if (EX/MEM.RegWrite and (EX/MEM.RegisterRd ≠ 0)
and (EX/MEM.RegisterRd = ID/EX.RegisterRt))
ForwardB = 10
n MEM hazard
§ if (MEM/WB.RegWrite and (MEM/WB.RegisterRd ≠ 0)
and (MEM/WB.RegisterRd = ID/EX.RegisterRs))
ForwardA = 01
§ if (MEM/WB.RegWrite and (MEM/WB.RegisterRd ≠ 0)
and (MEM/WB.RegisterRd = ID/EX.RegisterRt))
ForwardB = 01
86 COMP 140 – Summer 2014
Double Data Hazard
Need to stall
for one cycle
Stall inserted
here
Flush these
instructions
(Set control
values to 0)
PC
… IF ID EX MEM WB
beq stalled IF ID
beq stalled IF ID
beq stalled ID
outer: …
…
inner: …
…
beq …, …, inner
…
beq …, …, outer
n Interrupt
§ From an external I/O controller
n Dealing with them without sacrificing
performance is hard
Preserves
dependencies
Hold pending
operands