Cse431 06
Cse431 06
Computer Architecture
Fall 2005
Cycle 1 Cycle 2
Clk
lw sw Waste
multicycle clock
slower than 1/5th of
Multiple Cycle Implementation: single cycle clock
due to stage register
overhead
Clk Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9Cycle 10
lw sw R-type
IFetch Dec Exec Mem WB IFetch Dec Exec Mem IFetch
lw sw Waste
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9Cycle 10
Clk
lw sw R-type
IFetch Dec Exec Mem WB IFetch Dec Exec Mem IFetch
Pipeline Implementation:
lw IFetch Dec Exec Mem WB
Add
Add
4 Shift
left 2
Read Addr 1
Instruction Data
Register Read
IFetch/Dec
Memory Memory
Read Addr 2Data 1
Dec/Exec
Exec/Mem
Read
PC
File Read
Mem/WB
Address Address
Write Addr Read ALU Data
Data 2 Write Data
Write Data
Sign
16 Extend 32
System Clock
CSE431 L06 Basic MIPS Pipelining.6 Irwin, PSU, 2005
Pipelining the MIPS ISA
What makes it easy
all instructions are the same length (32 bits)
- can fetch in the 1st stage and decode in the 2nd stage
few instruction formats (three) with symmetry across formats
- can begin reading register file in 2nd stage
memory operations can occur only in loads and stores
- can use the execute stage to calculate memory addresses
each MIPS instruction writes at most one result (i.e.,
changes the machine state) and does so near the end of the
pipeline (MEM and WB)
What makes it hard
structural hazards: what if we had only one memory?
control hazards: what about branches?
data hazards: what if an instruction’s input operands
depend on the output of a previous instruction?
CSE431 L06 Basic MIPS Pipelining.7 Irwin, PSU, 2005
Graphically Representing MIPS Pipeline
ALU
IM Reg DM Reg
Once the
ALU
I Inst 0 IM Reg DM Reg pipeline is full,
n one instruction
s is completed
ALU
t Inst 1 IM Reg DM Reg
every cycle, so
r. CPI = 1
ALU
O Inst 2 IM Reg DM Reg
r
d
ALU
e Inst 3 IM Reg DM Reg
r
ALU
Inst 4 IM Reg DM Reg
ALU
I lw Mem Reg Mem Reg
memory
n
s
ALU
t Inst 1 Mem Reg Mem Reg
r.
ALU
O Inst 2 Mem Reg Mem Reg
r
d
ALU
e Inst 3 Mem Reg Mem Reg
r
ALU
Inst 4 Mem Reg Mem Reg
Reading instruction
from memory
Fix with separate instr and data memories (I$ and D$)
CSE431 L06 Basic MIPS Pipelining.11 Irwin, PSU, 2005
How About Register File Access?
Time (clock cycles)
ALU
I add $1, IM Reg DM Reg access hazard by
n doing reads in the
s second half of the
ALU
t Inst 1 IM Reg DM Reg
cycle and writes in
r. the first half
ALU
O Inst 2 IM Reg DM Reg
r
d
ALU
e add $2,$1, IM Reg DM Reg
r
ALU
add $1, IM Reg DM Reg
ALU
sub $4,$1,$5 IM Reg DM Reg
ALU
and $6,$1,$7 IM Reg DM Reg
ALU
or $8,$1,$9 IM Reg DM Reg
ALU
IM Reg DM Reg
xor $4,$1,$5
ALU
I lw $1,4($2) IM Reg DM Reg
n
s
ALU
t sub $4,$1,$5 IM Reg DM Reg
r.
ALU
O and $6,$1,$7 IM Reg DM Reg
r
d
ALU
e or $8,$1,$9 IM Reg DM Reg
r
ALU
IM Reg DM Reg
xor $4,$1,$5
ALU
I add $1, IM Reg DM Reg
waiting – stall –
n
but impacts CPI
s
t stall
r.
O stall
r
d
ALU
e sub $4,$1,$5 IM Reg DM Reg
r
ALU
and $6,$1,$7 IM Reg DM Reg
ALU
add $1, IM Reg DM Reg
I results as soon as
n they are available
s to where they are
ALU
t IM Reg DM Reg
sub $4,$1,$5 needed
r.
ALU
IM Reg DM Reg
r and $6,$1,$7
d
e
ALU
r IM Reg DM Reg
or $8,$1,$9
ALU
IM Reg DM Reg
xor $4,$1,$5
ALU
I lw $1,4($2) IM Reg DM Reg
n
s
ALU
sub $4,$1,$5 IM Reg DM Reg
t
r.
ALU
IM Reg DM Reg
O and $6,$1,$7
r
d
ALU
IM Reg DM Reg
e or $8,$1,$9
r
ALU
IM Reg DM Reg
xor $4,$1,$5
ALU
I beq IM Reg DM Reg
n
s
ALU
t lw IM Reg DM Reg
r.
ALU
O Inst 3 IM Reg DM Reg
r
d
ALU
e Inst 4 IM Reg DM Reg
r
Fix branch
ALU
I beq IM Reg DM Reg hazard by
n waiting –
s stall – but
t stall affects CPI
r.
O stall
r
d
e stall
r
ALU
IM Reg DM Reg
lw
ALU
IM Reg DM
Inst 3
Add
4 Add MEM/WB
Shift
left 2
Read Addr 1
Instruction Data
Register Read
Memory Read Addr 2Data 1 Memory
Read
PC
File Address
Read
Address Write Addr ALU
Read Data
Data 2 Write Data
Write Data
Sign
16 Extend 32
ID/EX
EX/MEM
IF/ID Control
Add MEM/WB
4 Add
Shift
left 2
Read Addr 1
Instruction Data
Register Read
Memory Read Addr 2Data 1 Memory
Read
PC
File Address
Read
Address Write Addr ALU
Read Data
Data 2 Write Data
Write Data
Sign
16 Extend 32
ALU
IM Reg DM Reg
ALU
IM Reg DM Reg
StrongARM-1
Reg
ALU
XScale IM1 IM2 Reg SHFT DM1
DM2
PC update decode DM write
BTB access reg 1 access ALU op reg write
start IM access
shift/rotate start DM access
IM access reg 2 access exception
Reminders
HW2 due September 29th
SimpleScalar tutorials scheduled
- Thursday, Sept 22, 5:30-6:30 pm in 218 IST