










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











CPU Pipelining Issues
Finishing up Chapter 6
This pipe stuff makes
my head hurt!
What have you been
beating your head
against?
Structural Data Hazard
Consider LOADS:
Can we fix all theseproblems using ourprevious bypass paths?
For a
lw
instruction fetched during clock I, data isnโt returned from
memory until late into cycle I+3. Bypassing will fix
xor
but not
add
!
IF
RF
ALU
WB
i
i+
i+
i+
i+
i+
i+
lw
add
xor
lw
add
xor
lw
add
xor
lw
add
xor
lw
$t4,0($t1)
add $t5,$t1,$t4xor $t6,$t3,$t
Load data hazardsare complicated bythe fact that theirresult is resolvedlater than the ALUpipeline stage.
Punting on Load Interlock
Early versions of MIPS did notinclude a pipeline interlock, thus,requiring the compiler/programmerto work around it.
IF
RF
ALU
WB
i
i+
i+
i+
i+
i+
i+
lw
nop
add
lw
nop
xor
lw
add
xor
lw
add
xor
lw
$t4,0($t1)
nop add $t5,$t1,$t4xor $t6,$t3,$t
xor add nop
nop
If compiler knows about load delay, it can often rearrange the code sequenceto eliminate the hazard. Many compilers can provide implementation-specific
instruction scheduling
. This requires no additional H/W, but it
further confuses the instruction semantics. Weโll include interlocks for SPIMcompatibility.
Load Delays (contโd)
But, but, what about FASTER processors?
FACT: Processors have been become very fast relative to memories!Can we just stall the pipe longer? Add more NOPs?
ALTERNATIVE: Longer pipelines.
return of data.
transactions can be in progress at once.
4-Stage pipeline requires READ access in
LESS
than one clock.
Sadly, this is ourbottleneck. If wewant to go fasterwill have tosurround it withpipeline stages
SOLUTION: A 5-Stage pipeline that allows nearly two clocks
for data memory accesses...
One More Fly in the Ointment
There is one more structural hazard that we have not
discussed. That is, the saving, and subsequentaccesses, of the return address resulting from the jump-and-link,
jal
, instruction.
Moreover, given that we have bought into a single delay-
slot, which is always executed, we now need to store theaddress of the instruction
FOLLOWING
the delay slot
instruction.
jal
sqr
addi
$a0,$0,
addi
$t0,$v0,-
We need toreturn here, toPC+8, notPC+4. Oncemore we needto rewrite theISA spec!
Return Address Register Writes
add
$ra,$0,$
jal
f
addi $ra,$ra,
...
f:
xor
$t0,$ra,$
or
$r1,$0,$ra
add
$t2,$0,$ra
IF
RF
ALU
MEM
WB
i
i+
i+
i+
i+
i+
i+
add
jal
addi
xor
or
add
add
jal
addi
xor
or
add
add
jal
addi
xor
or
add
jal
addi
xor
add
jal
BR Decision Time
ADDI reads
BR writes
addi
Can we make the
regfile accesses of
the 3 instructions
following the jal
work by bypassing?
Where do we get
the right return
address from?
Can we make the
regfile accesses of
the 3 instructions
following the jal
work by bypassing?
Where do we get
the right return
address from?
ALU
Adr
0
1
2
00
0 1 2 3 4 5 6
0x800000000x80000040 0x
REG
00
REG
Register
File
Imm: <15:0>
x
Rt: <20:16>
Rs: <25:21>
ASEL
2
0
BSEL
0
1
shamt:<10:6>
โ16โ
1
JAL PC Bypasses
ALU
00
ALU
ALU
MEM
00
MEM
MEM
MEM
Register
File
Rt:<20:16>Rd:<15:11>
โ31โ โ27โ
0
1
2
3
InstructionFetch RegisterFile ALU WriteBack
WB
00
WB
WB
Memory
addi $31,$31,4 jal f
We need anotherPC
ALU
bypass.
In this case, thebypass pathsupplies the $31operand for theXOR instruction.
add $ra,$0,$
= BZ
xor $8,$31,$
A,B Bypass
(fetching or at f+4)
ALU
Adr
0
1
2
00
0 1 2 3 4 5 6
0x800000000x80000040 0x
REG
00
REG
Register
File
Imm: <15:0>
x
Rt: <20:16>
Rs: <25:21>
ASEL
2
0
BSEL
0
1
shamt:<10:6>
โ16โ
1
JAL PC Bypasses
ALU
00
ALU
ALU
MEM
00
MEM
MEM
MEM
Register
File
Rt:<20:16>Rd:<15:11>
โ31โ โ27โ
0
1
2
3
InstructionFetch RegisterFile ALU WriteBack
WB
00
WB
WB
Memory
jal f
And, we needanother PC
MEM
bypass.In this case, thebypass pathsupplies the $31operand for theOR instruction.PC
WB
is already
taken care of, forthe following ADD,using the WBstage bypass atthe output of theWDSEL mux.
= BZ
xor $8,$31,$
A,B Bypass
or $1,$0,$
addi $31,$31,
(fetching add at f+8)
Bypass MUX Details
RD
RD
Register File
A Bypass
B Bypass
ASEL
0
2
A
ALU
BSEL
0
1
B
ALU
โ16โ
SEXT(imm)
To ALU
To ALU
WD
ALU
To Mem
JT
from ALU/MEM/WB/PC
from ALU/MEM/WB/PC
1
shamt
=
BZ
The previous diagram was oversimplified. Really need for the bypass muxesto precede the A and B muxes to provide the correct values for the jumptarget (JT), write data, and early branch decision logic.
Bypass Logic
rs or rt
rt or rd (WB)*
rt or rd (MEM)*
rt or rd (ALU)*
โ0โ
ALU bypassSelect โ0โ
WB bypassMEM bypass
Regfile (no bypass)
miniMIPS bypass logic (need two copies for A/B data):
5-bit
compare
Pipeline Summary (I)
Choose to execute instruction after branch
Add bypass paths (6 x 2 = 12) to forward correct value
Introduce NOPs at IR
ALU
, to stall IF and RF stages
until LD result was ready
Pipeline Summary (II)
Fallacy #1: Pipelining is easy
Smart people get it wrong all of the time! Costs? Re-spins of the design. Force S/W folks to deviseprogram/compiler workarounds.
Fallacy #2: Pipelining is independent of ISA
Many ISA decisions impact how easy/costly it is toimplement pipelining (i.e. branch semantics, addressingmodes). Bad decisions impact future implementations.(delay slot vs. annul?, load interlocks?) and breakotherwise clean semantics. For performance, S/W mustbe aware!
Fallacy #3: Increasing Pipeline stages improves
performance Diminishing returns. Increasing complexity. Can introduceunusable delay slots, long interlock stalls.