Docsity

CPU Pipelining Issues - Lecture Slides | COMP 411, Study notes of Computer Architecture and Organization

Partial preview of the text

Download CPU Pipelining Issues - Lecture Slides | COMP 411 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

L20 โ€“ Pipeline Issues

CPU Pipelining Issues

Finishing up Chapter 6

This pipe stuff makes

my head hurt!

What have you been

beating your head

against?

L20 โ€“ Pipeline Issues

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.

L20 โ€“ Pipeline Issues

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.

L20 โ€“ Pipeline Issues

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.

  1. Add โ€œMEMORY WAITโ€ stages between START of read operation &

return of data.

  1. Build pipelined memories, so that multiple (say, N) memory

transactions can be in progress at once.

  1. (Optional). Stall pipeline when the N limit is exceeded.

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...

L20 โ€“ Pipeline Issues

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

call procedure

addi

$a0,$0,

delay slot

addi

$t0,$v0,-

return address

We need toreturn here, toPC+8, notPC+4. Oncemore we needto rewrite theISA spec!

L20 โ€“ Pipeline Issues

Return Address Register Writes

The code: Assume Reg[LP] = 100...

add

$ra,$0,$

jal

f

addi $ra,$ra,

In delay slot

...

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?

L20 โ€“ Pipeline Issues

ALU

A
B
ALUFN
RD
WD
R/W

Adr

Wr

WDSEL

0

1

2

PC+

Z

V

N

C

PC

Instruction

Memory

A
D

00

BT

PC<31:29>:J<25:0>:

JT

PCSEL

0 1 2 3 4 5 6

0x800000000x80000040 0x

PC

REG

00

IR

REG

WA

Register

File

RA
RA
RD
RD
J:<25:0>

Imm: <15:0>

x

BT

Rt: <20:16>

Rs: <25:21>

ASEL

2

0

BSEL

0

1

SEXT

SEXT

shamt:<10:6>

โ€œ16โ€

1

JAL PC Bypasses

PC

ALU

00

IR

ALU

A
B
WD

ALU

PC

MEM

00

IR

MEM

Y

MEM

WD

MEM

WA

Register

File

WA
WD
WE
WERF
WASEL

Rt:<20:16>Rd:<15:11>

โ€œ31โ€ โ€œ27โ€

0

1

2

3

InstructionFetch RegisterFile ALU WriteBack

PC

WB

00

IR

WB

Y

WB

Memory

addi $31,$31,4 jal f

We need anotherPC

ALU

bypass.

In this case, thebypass pathsupplies the $31operand for theXOR instruction.

Data Memory

add $ra,$0,$

JT

= BZ

xor $8,$31,$

A,B Bypass

(fetching or at f+4)

L20 โ€“ Pipeline Issues

ALU

A
B
ALUFN
RD
WD
R/W

Adr

Wr

WDSEL

0

1

2

PC+

Z

V

N

C

PC

Instruction

Memory

A
D

00

BT

PC<31:29>:J<25:0>:

JT

PCSEL

0 1 2 3 4 5 6

0x800000000x80000040 0x

PC

REG

00

IR

REG

WA

Register

File

RA
RA
RD
RD
J:<25:0>

Imm: <15:0>

x

BT

Rt: <20:16>

Rs: <25:21>

ASEL

2

0

BSEL

0

1

SEXT

SEXT

shamt:<10:6>

โ€œ16โ€

1

JAL PC Bypasses

PC

ALU

00

IR

ALU

A
B
WD

ALU

PC

MEM

00

IR

MEM

Y

MEM

WD

MEM

WA

Register

File

WA
WD
WE
WERF
WASEL

Rt:<20:16>Rd:<15:11>

โ€œ31โ€ โ€œ27โ€

0

1

2

3

InstructionFetch RegisterFile ALU WriteBack

PC

WB

00

IR

WB

Y

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.

Data Memory

JT

= BZ

xor $8,$31,$

A,B Bypass

or $1,$0,$

addi $31,$31,

(fetching add at f+8)

L20 โ€“ Pipeline Issues

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.

L20 โ€“ Pipeline Issues

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

  • If instruction is a sw (doesnโ€™t write into regfile), set rt for ALU/MEM/WB to $

L20 โ€“ Pipeline Issues

Pipeline Summary (I)

  • Started with unpipelined implementation
    • direct execute, 1 cycle/instructionโ€“ it had a long cycle time: mem + regs + alu + mem + wb
      • We ended up with a 5-stage pipelined implementation
        • increase throughput (3x???)โ€“ delayed branch decision (1 cycle)

Choose to execute instruction after branch

  • delayed register writeback (3 cycles)

Add bypass paths (6 x 2 = 12) to forward correct value

  • memory data available only in WB stage

Introduce NOPs at IR

ALU

, to stall IF and RF stages

until LD result was ready

L20 โ€“ Pipeline Issues

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.