1 Changelog Changes made in this version not seen in fjrst lecture: - - PowerPoint PPT Presentation

1 changelog
SMART_READER_LITE
LIVE PREVIEW

1 Changelog Changes made in this version not seen in fjrst lecture: - - PowerPoint PPT Presentation

1 Changelog Changes made in this version not seen in fjrst lecture: 10 October 2017: remove duplication of stall logic slides 10 October 2017: slide 6: use d_dstE and reg_dstE instead of dstE, use P_pc and p_pc consistently 10 October 2017:


slide-1
SLIDE 1

1

slide-2
SLIDE 2

Changelog

Changes made in this version not seen in fjrst lecture:

10 October 2017: remove duplication of stall logic slides 10 October 2017: slide 6: use d_dstE and reg_dstE instead of dstE, use P_pc and p_pc consistently 10 October 2017: move pipeline stages slide after mention of the stall for ret 10 October 2017: slide 8: show version without moved wires for dstE/dstM 10 October 2017: slide 16: add valA and valB, not valB and valB

1

slide-3
SLIDE 3

addq processor timing

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r10, %r11 addq %r12, %r13 addq %r9, %r8

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4 10 11 800 900 9 3 0x6 12 13 1000 1100 11 1700 9 4 9 8 1200 1300 13 2100 11 5 1700 800 8 2500 13 6 2500 8 fetch/decode decode/execute execute/writeback

2

slide-4
SLIDE 4

addq processor timing

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r10, %r11 addq %r12, %r13 addq %r9, %r8

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4 10 11 800 900 9 3 0x6 12 13 1000 1100 11 1700 9 4 9 8 1200 1300 13 2100 11 5 1700 800 8 2500 13 6 2500 8 fetch/decode decode/execute execute/writeback

2

slide-5
SLIDE 5

addq processor timing

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r10, %r11 addq %r12, %r13 addq %r9, %r8

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4 10 11 800 900 9 3 0x6 12 13 1000 1100 11 1700 9 4 9 8 1200 1300 13 2100 11 5 1700 800 8 2500 13 6 2500 8 fetch/decode decode/execute execute/writeback

2

slide-6
SLIDE 6

addq processor timing

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r10, %r11 addq %r12, %r13 addq %r9, %r8

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4 10 11 800 900 9 3 0x6 12 13 1000 1100 11 1700 9 4 9 8 1200 1300 13 2100 11 5 1700 800 8 2500 13 6 2500 8 fetch/decode decode/execute execute/writeback

2

slide-7
SLIDE 7

addq processor timing

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r10, %r11 addq %r12, %r13 addq %r9, %r8

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4 10 11 800 900 9 3 0x6 12 13 1000 1100 11 1700 9 4 9 8 1200 1300 13 2100 11 5 1700 800 8 2500 13 6 2500 8 fetch/decode decode/execute execute/writeback

2

slide-8
SLIDE 8

pipeline register naming convention

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

f_rA D_rA d_dstE E_dstE e_dstE W_dstE

3

slide-9
SLIDE 9

pipeline register naming convention

f — fetch sends values here D — decode receives values here d — decode sends values here …

4

slide-10
SLIDE 10

addq HCL

... /* f: from fetch */ f_rA = i10bytes[12..16]; f_rB = i10bytes[12..16]; /* fetch to decode */ /* f_rA -> D_rA, etc. */ register fD { rA : 4 = REG_NONE; rB : 4 = REG_NONE; } /* D: to decode d: from decode */ d_dstE = D_rB; /* use register file: */ reg_srcA = D_rA; d_valA = reg_outputA; ... /* decode to execute */ register dE { dstE : 4 = REG_NONE; valA : 64 = 0; valB : 64 = 0; } ...

5

slide-11
SLIDE 11

addq fetch/decode

/* Fetch+PC Update*/ pc = P_pc; p_pc = pc + 2; rA = i10bytes[12..16]; rB = i10bytes[8..12]; /* Decode */ reg_srcA = rA; reg_srcB = rB; reg_dstE = rB; valA = reg_outputA; valB = reg_outputB;

unpipelined

/* Fetch+PC Update*/ pc = P_pc; p_pc = pc + 2; f_rA = i10bytes[12..16]; f_rB = i10bytes[8..12]; /* Decode */ reg_srcA = D_rA; reg_srcB = D_rB; d_dstE = D_rB; d_valA = reg_outputA; d_valB = reg_outputB;

pipelined

6

slide-12
SLIDE 12

addq pipeline registers

register pP { pc : 64 = 0; }; /* Fetch+PC Update*/ register fD { rA : 4 = REG_NONE; rB : 4 = REG_NONE; }; /* Decode */ register dE { valA : 64 = 0; valB : 64 = E; dstE : 4 = REG_NONE; } /* Execute */ register eW { valE : 64 = 0; dstE : 4 = REG_NONE; } /* Writeback */ 7

slide-13
SLIDE 13

SEQ without stages

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

8

slide-14
SLIDE 14

SEQ with stages

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback rule: signal to next stage (except fmow control)

9

slide-15
SLIDE 15

SEQ with stages

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback rule: signal to next stage (except fmow control)

9

slide-16
SLIDE 16

SEQ with stages

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback rule: signal to next stage (except fmow control)

9

slide-17
SLIDE 17

SEQ with stages (actually sequential)

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback

10

slide-18
SLIDE 18

adding pipeline registers

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback not shown — control logic

11

slide-19
SLIDE 19

adding pipeline registers

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback not shown — control logic

11

slide-20
SLIDE 20

passing values in pipeline

read prior stage’s outputs

e.g. decode: get from fetch via pipeline registers (D_icode, …)

send inputs for next stage

e.g. decode: send to execute via pipeline registers (d_icode, …)

exceptions: deliberate sharing between instructions

via register fjle/memory/etc. via control fmow instructions

12

slide-21
SLIDE 21

memory read/write logic

data memory address data input data

  • utput

is read? is write? icode

from instr. mem

from instr. mem.

13

slide-22
SLIDE 22

memory read/write logic

data memory address data input data

  • utput

is read? is write? icode

from instr. mem

from instr. mem.

13

slide-23
SLIDE 23

memory read/write logic

data memory address data input data

  • utput

is read? is write? icode

from instr. mem

from instr. mem.

13

slide-24
SLIDE 24

memory read/write: SEQ code

icode = i10bytes[4..8]; mem_readbit = [ icode == MRMOVQ || ...: 1; 0; ];

14

slide-25
SLIDE 25

memory read/write: PIPE code

f_icode = i10bytes[4..8]; register fD { /* and dE and eM and mW */ icode : 4 = NOP; } d_icode = D_icode ... e_icode = E_icode; mem_readbit = [ M_icode == MRMOVQ || ...: 1; 0; ];

15

slide-26
SLIDE 26

memory read/write: PIPE code

f_icode = i10bytes[4..8]; register fD { /* and dE and eM and mW */ icode : 4 = NOP; } d_icode = D_icode ... e_icode = E_icode; mem_readbit = [ M_icode == MRMOVQ || ...: 1; 0; ];

15

slide-27
SLIDE 27

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE rB execute valE ← valA + valB memory write back R[ rB ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-28
SLIDE 28

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE rB execute valE ← valA + valB memory write back R[ rB ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-29
SLIDE 29

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE rB execute valE ← valA + valB memory write back R[ rB ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-30
SLIDE 30

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE rB execute valE ← valA + valB memory write back R[ rB ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-31
SLIDE 31

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE ← rB execute valE ← valA + valB memory write back R[ dstE ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-32
SLIDE 32

addq pipeline registers

stage addq rA, rB fetch icode : ifun ← M1[PC] rA : rB ← M1[PC+1] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[ rB ] dstE ← rB execute valE ← valA + valB memory write back R[ dstE ] ← valE PC icode icode icode icode icode, rA, rB icode, rB icode, rB icode, rB icode, rB, valA, valB icode, rB, valE icode, rB, valE icode, rA, rB icode, dstE, valA, valB icode, dstE, valE icode, dstE, valE

redundant with rB + icode but will make implementation simpler

16

slide-33
SLIDE 33

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] execute valE ← valB − 8 memory M[ valE ] ← valA write back R[%rsp] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-34
SLIDE 34

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] execute valE ← valB − 8 memory M[ valE ] ← valA write back R[%rsp] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-35
SLIDE 35

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] execute valE ← valB − 8 memory M[ valE ] ← valA write back R[%rsp] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-36
SLIDE 36

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] execute valE ← valB − 8 memory M[ valE ] ← valA write back R[%rsp] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-37
SLIDE 37

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] dstE ← %rsp execute valE ← valB − 8 memory M[ valE ] ← valA write back R[ dstE ] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-38
SLIDE 38

pushq pipeline registers

stage pushq rA fetch icode : ifun ← M1[PC] valP ← PC + 2 PC update PC ← valP decode valA ← R[ rA ] valB ← R[%rsp] dstE ← %rsp execute valE ← valB − 8 memory M[ valE ] ← valA write back R[ dstE ] ← valE PC icode icode icode icode icode, rA icode icode icode, valA, valB icode, valA icode icode icode, valA, valE icode, valE icode, valA, valB, dstE icode, valA, valE, dstE icode, valE, dstE

redundant with icode but will make implementation simpler

17

slide-39
SLIDE 39

addq processor: data hazard

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r9, %r8 addq ... addq ...

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 9 8 800 900 9 3 900 800 8 1700 9 4 1700 8 fetch/decode decode/execute execute/writeback

should be 1700

18

slide-40
SLIDE 40

addq processor: data hazard

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 addq %r9, %r8 addq ... addq ...

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 9 8 800 900 9 3 900 800 8 1700 9 4 1700 8 fetch/decode decode/execute execute/writeback

should be 1700

18

slide-41
SLIDE 41

data hazard

addq %r8, %r9 // (1) addq %r9, %r8 // (2) step# pipeline implementation ISA specifjcation 1 read r8, r9 for (1) read r8, r9 for (1) 2 read r9, r8 for (2) write r9 for (1) 3 write r9 for (1) read r9, r8 for (2) 4 write r8 for (2) write r8 ror (2)

pipeline reads older value… instead of value ISA says was just written

19

slide-42
SLIDE 42

data hazard compiler solution

addq %r8, %r9 nop nop addq %r9, %r8

  • ne solution: change the ISA

all addqs take efgect three instructions later

make it compiler’s job usually not acceptable

20

slide-43
SLIDE 43

data hazard hardware solution

addq %r8, %r9 // hardware inserts: nop // hardware inserts: nop addq %r9, %r8

how about hardware add nops? called stalling extra logic:

sometimes don’t change PC sometimes put do-nothing values in pipeline registers

21

slide-44
SLIDE 44

addq processor: data hazard stall

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2* 8 9 2 0x2* F F 800 900 9 3 0x2 F F

  • F

1700 9 4 0x4 9 8

  • F
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

22

slide-45
SLIDE 45

addq processor: data hazard stall

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2* 8 9 2 0x2* F F 800 900 9 3 0x2 F F

  • F

1700 9 4 0x4 9 8

  • F
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

22

slide-46
SLIDE 46

addq processor: data hazard stall

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2* 8 9 2 0x2* F F 800 900 9 3 0x2 F F

  • F

1700 9 4 0x4 9 8

  • F
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

22

slide-47
SLIDE 47

addq stall

addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11 cycle fetch decode execute writeback addq %r8, %r9 1 addq %r9, %r8 addq %r8, %r9 2 addq %r9, %r8 nop “bubble” addq %r8, %r9 3 addq %r9, %r8 nop “bubble” nop “bubble” addq %r8, %r9 4 addq %r10, %r11 addq %r9, %r8 nop “bubble” nop “bubble” 5 … addq %r10, %r11 addq %r9, %r8 nop “bubble”

23

slide-48
SLIDE 48

addq stall (alternative)

addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11 cycle fetch decode execute writeback addq %r8, %r9 1 addq %r9, %r8 addq %r8, %r9 2 addq %r10, %r11 addq %r9, %r8 addq %r8, %r9 3 addq %r10, %r11 addq %r9, %r8 nop “bubble” addq %r8, %r9 4 addq %r10, %r11 addq %r9, %r8 nop “bubble” nop “bubble” 5 … addq %r10, %r11 addq %r9, %r8 nop “bubble”

24

slide-49
SLIDE 49

addq processor: data hazard stall (alternative)

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4* 9* 8* 800 900 9 3 0x4* 9* 8*

  • F*

1700 9 4 0x4 9 8

  • F*
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

25

slide-50
SLIDE 50

addq processor: data hazard stall (alternative)

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4* 9* 8* 800 900 9 3 0x4* 9* 8*

  • F*

1700 9 4 0x4 9 8

  • F*
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

25

slide-51
SLIDE 51

addq processor: data hazard stall (alternative)

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2 + stalling logic (not shown)

// initially %r8 = 800, // %r9 = 900, etc. addq %r8, %r9 // hardware stalls twice addq %r9, %r8 addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 1 0x2 8 9 2 0x4* 9* 8* 800 900 9 3 0x4* 9* 8*

  • F*

1700 9 4 0x4 9 8

  • F*
  • F

5 10 11 1700 800 8

  • F

6 1000 1100 11 2500 8 fetch→decode decode→execute execute→writeback

R[9] written during cycle 3; read during cycle 4

25

slide-52
SLIDE 52

hazard exericse

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

addq %r8, %r9 addq %r10, %r11 addq %r9, %r8 addq %r11, %r10

to resolve hazards with stalling, how many stalls are needed?

26

slide-53
SLIDE 53

hazard exericse solution

PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM] split

0xF

ADD

ADD

add 2

cycle # 0 1 2 3 4 5 6 7 8

addq %r8, %r9

F D E W

addq %r10, %11

F D E W

addq %r9, %r8

F D E W

addq %r11, %r10

F D E W

27

slide-54
SLIDE 54

exercise: pipelining improvement (1)

1% of instructions executed need to stall 4 cycles for hazard 2% stall exactly 3 10% stall exactly 2 15% stall exactly 1 how many cycles per instruction? (compute the mean)

28

slide-55
SLIDE 55

exercise: pipelining improvement (1)

1% of instructions executed need to stall 4 cycles for hazard 2% stall exactly 3 10% stall exactly 2 15% stall exactly 1 how many cycles per instruction? (compute the mean) 1 + .15 × 1 + .10 × 2 + .02 × 3 + .01 × 4 = 1.45

28

slide-56
SLIDE 56

exercise: pipelining improvement (2)

1% of instructions executed need to stall 4 cycles for hazard 2% stall exactly 3 10% stall exactly 2 15% stall exactly 1 how many cycles per instruction? 1.45

  • riginal cycle time: 1200 ps; new cycle time: 300 ps

how much better throughput? 1 every ( ps) versus 1 every 1200 — faster

29

slide-57
SLIDE 57

exercise: pipelining improvement (2)

1% of instructions executed need to stall 4 cycles for hazard 2% stall exactly 3 10% stall exactly 2 15% stall exactly 1 how many cycles per instruction? 1.45

  • riginal cycle time: 1200 ps; new cycle time: 300 ps

how much better throughput? 1 every (1.45 × 300 = 435 ps) versus 1 every 1200 — 2.76 faster

29

slide-58
SLIDE 58

control hazard

addq %r8, %r9 je 0xFFFF addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC SF/ZF rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 0/1 1 0x2 0/1 8 9 2 ??? 0/1 0xF 0xF 800 900 9 fetch→decode decode→execute execute→writeback

0xFFFF if R[8] = R[9]; 0x12 otherwise

30

slide-59
SLIDE 59

control hazard

addq %r8, %r9 je 0xFFFF addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC SF/ZF rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 0/1 1 0x2 0/1 8 9 2 ??? 0/1 0xF 0xF 800 900 9 fetch→decode decode→execute execute→writeback

0xFFFF if R[8] = R[9]; 0x12 otherwise

30

slide-60
SLIDE 60

control hazard: stall

addq %r8, %r9 // insert two nops je 0xFFFF addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC SF/ZF rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 0/1 1 0x2* 0/1 8 9 2 0x2* 0/1 0xF 0xF 800 900 9 3 0x2 0/0 0xF 0xF

  • 0xF

1700 9 4 0x10 0/0 0xF 0xF

  • 0xF
  • 0xF

5 10 11

  • 0xF
  • 0xF

6 1000 1100 11

  • 0xF

fetch→decode decode→execute execute→writeback

wait for two cycles for addq to update SF/ZF execute je instruction (use SF/ZF)

31

slide-61
SLIDE 61

control hazard: stall

addq %r8, %r9 // insert two nops je 0xFFFF addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC SF/ZF rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 0/1 1 0x2* 0/1 8 9 2 0x2* 0/1 0xF 0xF 800 900 9 3 0x2 0/0 0xF 0xF

  • 0xF

1700 9 4 0x10 0/0 0xF 0xF

  • 0xF
  • 0xF

5 10 11

  • 0xF
  • 0xF

6 1000 1100 11

  • 0xF

fetch→decode decode→execute execute→writeback

wait for two cycles for addq to update SF/ZF execute je instruction (use SF/ZF)

31

slide-62
SLIDE 62

control hazard: stall

addq %r8, %r9 // insert two nops je 0xFFFF addq %r10, %r11

fetch rA rB R[srcA] R[srcB] dstE next R[dstE] dstE cycle PC SF/ZF rA rB R[srcA] R[srcB] dstE next R[dstE] dstE 0x0 0/1 1 0x2* 0/1 8 9 2 0x2* 0/1 0xF 0xF 800 900 9 3 0x2 0/0 0xF 0xF

  • 0xF

1700 9 4 0x10 0/0 0xF 0xF

  • 0xF
  • 0xF

5 10 11

  • 0xF
  • 0xF

6 1000 1100 11

  • 0xF

fetch→decode decode→execute execute→writeback

wait for two cycles for addq to update SF/ZF execute je instruction (use SF/ZF)

31

slide-63
SLIDE 63

stalling for conditional jmps

time fetch decode execute memory writeback 1 OPq 2 jCC OPq 3 wait for jCC jCC OPq (set ZF) 4 wait for jCC nothing jCC (use ZF) OPq 5 irmovq nothing nothing jCC (done) OPq

subq %r8, %r8 je label label: irmovq ... ZF sent via register “taken” sent from execute to fetch

32

slide-64
SLIDE 64

stalling for conditional jmps

time fetch decode execute memory writeback 1 OPq 2 jCC OPq 3 wait for jCC jCC OPq (set ZF) 4 wait for jCC nothing jCC (use ZF) OPq 5 irmovq nothing nothing jCC (done) OPq

subq %r8, %r8 je label label: irmovq ... ZF sent via register “taken” sent from execute to fetch

32

slide-65
SLIDE 65

stalling for conditional jmps

time fetch decode execute memory writeback 1 OPq 2 jCC OPq 3 wait for jCC jCC OPq (set ZF) 4 wait for jCC nothing jCC (use ZF) OPq 5 irmovq nothing nothing jCC (done) OPq

subq %r8, %r8 je label label: irmovq ... ZF sent via register “taken” sent from execute to fetch

32

slide-66
SLIDE 66

stalling for conditional jmps

time fetch decode execute memory writeback 1 OPq 2 jCC OPq 3 wait for jCC jCC OPq (set ZF) 4 wait for jCC nothing jCC (use ZF) OPq 5 irmovq nothing nothing jCC (done) OPq

subq %r8, %r8 je label label: irmovq ... ZF sent via register “taken” sent from execute to fetch

32

slide-67
SLIDE 67

stalling for ret

time fetch decode execute memory writeback 1 call 2 ret call 3 wait for ret ret call 4 wait for ret nothing ret call (store) 5 wait for ret nothing nothing ret (load) call 6 addq nothing nothing nothing ret

return address stored here return address loaded here why not start addq here? call empty addq %r8, %r9 empty: ret

33

slide-68
SLIDE 68

stalling for ret

time fetch decode execute memory writeback 1 call 2 ret call 3 wait for ret ret call 4 wait for ret nothing ret call (store) 5 wait for ret nothing nothing ret (load) call 6 addq nothing nothing nothing ret

return address stored here return address loaded here why not start addq here? call empty addq %r8, %r9 empty: ret

33

slide-69
SLIDE 69

stalling for ret

time fetch decode execute memory writeback 1 call 2 ret call 3 wait for ret ret call 4 wait for ret nothing ret call (store) 5 wait for ret nothing nothing ret (load) call 6 addq nothing nothing nothing ret

return address stored here return address loaded here why not start addq here? call empty addq %r8, %r9 empty: ret

33

slide-70
SLIDE 70

pipeline stages

fetch — instruction memory, most PC computation decode — reading register fjle execute — computation, condition code read/write memory — memory read/write writeback — writing register fjle, writing Stat register

common case: fetch next instruction in next cycle can’t for conditional jump, return read/write in same stage avoids reading wrong value get value updated for prior instruction (not earlier/later) don’t want to halt until everything else is done

34

slide-71
SLIDE 71

pipeline stages

fetch — instruction memory, most PC computation decode — reading register fjle execute — computation, condition code read/write memory — memory read/write writeback — writing register fjle, writing Stat register

common case: fetch next instruction in next cycle can’t for conditional jump, return read/write in same stage avoids reading wrong value get value updated for prior instruction (not earlier/later) don’t want to halt until everything else is done

34

slide-72
SLIDE 72

pipeline stages

fetch — instruction memory, most PC computation decode — reading register fjle execute — computation, condition code read/write memory — memory read/write writeback — writing register fjle, writing Stat register

common case: fetch next instruction in next cycle can’t for conditional jump, return read/write in same stage avoids reading wrong value get value updated for prior instruction (not earlier/later) don’t want to halt until everything else is done

34

slide-73
SLIDE 73

pipeline stages

fetch — instruction memory, most PC computation decode — reading register fjle execute — computation, condition code read/write memory — memory read/write writeback — writing register fjle, writing Stat register

common case: fetch next instruction in next cycle can’t for conditional jump, return read/write in same stage avoids reading wrong value get value updated for prior instruction (not earlier/later) don’t want to halt until everything else is done

34

slide-74
SLIDE 74

PC update (adding stall)

PC

MUX

convert icode icode (from instr. mem)

+2 +10

… to instr. mem

MUX

control logic need to stall? “taken” (from execute) jump target/ret address

35

slide-75
SLIDE 75

PC update (adding stall)

PC

MUX

convert icode icode (from instr. mem)

+2 +10

… to instr. mem

MUX

control logic need to stall? “taken” (from execute) jump target/ret address

35

slide-76
SLIDE 76

PC update (rearranged)

predicted PC

(replaces PC)

MUX

convert icode icode (from instr. mem) need to stall?

+2 +10

MUX

control logic to stall logic taken?; etc. … jump target to instr. mem.

36

slide-77
SLIDE 77

PC update (rearranged)

predicted PC

(replaces PC)

MUX

convert icode icode (from instr. mem) need to stall?

+2 +10

MUX

control logic to stall logic taken?; etc. … jump target to instr. mem.

36

slide-78
SLIDE 78

PC update (rearranged)

predicted PC

(replaces PC)

MUX

convert icode icode (from instr. mem) need to stall?

+2 +10

MUX

control logic to stall logic taken?; etc. … jump target to instr. mem.

36

slide-79
SLIDE 79

PC update (rearranged)

predicted PC

(replaces PC)

MUX

convert icode icode (from instr. mem) need to stall?

+2 +10

MUX

control logic to stall logic taken?; etc. … jump target to instr. mem.

36

slide-80
SLIDE 80

rearranged PC update in HCL

/* actual input to instruction memory */ pc = [ conditionCodesSaidTaken : jumpTarget; /* from later in pipeline */ ... 1: P_predictedPC; /* a register, replacing PC register */ ];

37

slide-81
SLIDE 81

stalling for ret

time fetch decode execute memory writeback 1 call 2 ret call 3 wait for ret ret call 4 wait for ret nothing ret call (store) 5 wait for ret nothing nothing ret (load) call 6 addq nothing nothing nothing ret

return address stored here return address loaded here why not start addq here? call empty addq %r8, %r9 empty: ret

38

slide-82
SLIDE 82

ret paths

pred. PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback

jmp target (from other stage)

very long critical path

39

slide-83
SLIDE 83

ret paths

pred. PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback

jmp target (from other stage)

very long critical path

39

slide-84
SLIDE 84

ret paths

pred. PC

Instr. Mem.

register fjle

srcA srcB R[srcA] R[srcB] dstE next R[dstE] dstM next R[dstM]

Data Mem.

ZF/SF Stat

Data in Addr in Data out

valC

0xF 0xF %rsp %rsp 0xF 0xF %rsp rA rB

ALU

aluA aluB valE 8 add/sub xor/and (function

  • f instr.)

write? function

  • f opcode

PC+9

instr. length +

fetch decode execute memory writeback

jmp target (from other stage)

very long critical path

39

slide-85
SLIDE 85

fetch/fetch logic — advance or not

predicted PC

MUX from incremented PC should we stall? …

40

slide-86
SLIDE 86

fetch/decode logic — bubble or not

rA

MUX no-op value — 0xF should we send no-op value (“bubble”)?

41

slide-87
SLIDE 87

HCLRS signals

register aB { ... }

HCLRS: every register bank has these MUXes built-in stall_B: keep old value for all registers

register input → register output

bubble_B: use default value for all registers

register input → default value

42

slide-88
SLIDE 88

exercise

register aB { value : 8 = 0xFF; } ... time a_value B_value stall_B bubble_B 0x01 0xFF 1 0x02 ??? 1 2 0x03 ??? 3 0x04 ??? 1 4 0x05 ??? 5 0x06 ??? 6 0x07 ??? 1 7 0x08 ??? 1 8 ???

stall: keep old value bubble: store default value

43

slide-89
SLIDE 89

exercise result

register aB { value : 8 = 0xFF; } ... time a_value B_value stall_B bubble_B 0x01 0xFF 1 0x02 0x01 1 2 0x03 0x01 3 0x04 0x03 1 4 0x05 0xFF 5 0x06 0x05 6 0x07 0x06 1 7 0x08 0x06 1 8 0x06

44

slide-90
SLIDE 90

ret stall

time fetch decode execute memory writeback call 1 ret call 2 wait for ret ret call 3 wait for ret nothing ret call (store) 4 wait for ret nothing nothing ret (load) call 5 addq nothing nothing nothing ret

stall (S) = keep old value; normal (N) = use new value bubble (B) = use default (no-op);

N N S N N S B N N S B N N N N B N N N

45

slide-91
SLIDE 91

ret stall

time fetch decode execute memory writeback call 1 ret call 2 wait for ret ret call 3 wait for ret nothing ret call (store) 4 wait for ret nothing nothing ret (load) call 5 addq nothing nothing nothing ret

stall (S) = keep old value; normal (N) = use new value bubble (B) = use default (no-op);

N N S N N S B N N S B N N N N B N N N

45

slide-92
SLIDE 92

ret stall

time fetch decode execute memory writeback call 1 ret call 2 wait for ret ret call 3 wait for ret nothing ret call (store) 4 wait for ret nothing nothing ret (load) call 5 addq nothing nothing nothing ret

stall (S) = keep old value; normal (N) = use new value bubble (B) = use default (no-op);

N N S N N S B N N S B N N N N B N N N

45

slide-93
SLIDE 93

ret stall

time fetch decode execute memory writeback call 1 ret call 2 wait for ret ret call 3 wait for ret nothing ret call (store) 4 wait for ret nothing nothing ret (load) call 5 addq nothing nothing nothing ret

stall (S) = keep old value; normal (N) = use new value bubble (B) = use default (no-op);

N N S N N S B N N S B N N N N B N N N

45

slide-94
SLIDE 94

ret stall

time fetch decode execute memory writeback call 1 ret call 2 wait for ret ret call 3 wait for ret nothing ret call (store) 4 wait for ret nothing nothing ret (load) call 5 addq nothing nothing nothing ret

stall (S) = keep old value; normal (N) = use new value bubble (B) = use default (no-op);

N N S N N S B N N S B N N N N B N N N

45

slide-95
SLIDE 95

backup slides

46

slide-96
SLIDE 96

PC update from lab

PC

MUX

convert icode icode (from instr. mem)

+2 +10

… to instr. mem

47

slide-97
SLIDE 97

PC update from lab

icode = i10bytes[4..8]; p_pc = [ icode == ADD || ...: P_pc + 2; icode == IRMOVQ || ...: P_pc + 10; ... ];

48