Lecture Pipelining Hazards Topics structural and data hazards

  • Slides: 16
Download presentation
Lecture: Pipelining Hazards • Topics: structural and data hazards • HW 2 posted later

Lecture: Pipelining Hazards • Topics: structural and data hazards • HW 2 posted later today; due in a week 1

A 5 -Stage Pipeline Source: H&P textbook 2

A 5 -Stage Pipeline Source: H&P textbook 2

RISC/CISC Loads/Stores Registers and memory Complex and reduced instrs Format of a load/store 3

RISC/CISC Loads/Stores Registers and memory Complex and reduced instrs Format of a load/store 3

Pipeline Summary RR ALU DM RW ADD R 3 R 1, R 2 Rd

Pipeline Summary RR ALU DM RW ADD R 3 R 1, R 2 Rd R 1, R 2 R 1+R 2 -- Wr R 3 BEZ R 1, [R 5] -- -- Rd R 1, R 5 -Compare, Set PC LD R 6 8[R 3] Rd R 3+8 Get data ST R 6 8[R 3] Rd R 3, R 6 R 3+8 Wr data Wr R 6 -- 4

Problem 3 • For the following code sequence, show the instrs flow through the

Problem 3 • For the following code sequence, show the instrs flow through the pipeline: ADD R 3 R 1, R 2 LD R 7 8[R 6] ST R 9 4[R 8] BEZ R 4, [R 5] 5

Problem 3 • For the following code sequence, show the instrs flow through the

Problem 3 • For the following code sequence, show the instrs flow through the pipeline: ADD R 3 R 1, R 2 LD R 7 8[R 6] ST R 9 4[R 8] BEZ R 4, [R 5] ADD LD ADD ADD LD LD LD ST ST ST LD ST BEZ 6

Problem 4 • Convert this C code into equivalent RISC assembly instructions a[i] =

Problem 4 • Convert this C code into equivalent RISC assembly instructions a[i] = b[i] + c[i]; 7

Problem 4 • Convert this C code into equivalent RISC assembly instructions a[i] =

Problem 4 • Convert this C code into equivalent RISC assembly instructions a[i] = b[i] + c[i]; LD R 2, [R 1] MUL R 3, R 2, 8 ADD R 7, R 3, R 4 ADD R 8, R 3, R 5 ADD R 9, R 3, R 6 LD R 10, [R 8] LD R 11, [R 9] ADD R 12, R 11, R 10 ST R 12, [R 7] # R 1 has the address for variable i # the offset from the start of the array # R 4 has the address of a[0] # R 5 has the address of b[0] # R 6 has the address of c[0] # Bringing b[i] # Bringing c[i] # Sum is in R 12 # Putting result in a[i] 8

Hazards • Structural hazards: different instructions in different stages (or the same stage) conflicting

Hazards • Structural hazards: different instructions in different stages (or the same stage) conflicting for the same resource • Data hazards: an instruction cannot continue because it needs a value that has not yet been generated by an earlier instruction • Control hazard: fetch cannot continue because it does not know the outcome of an earlier branch – special case of a data hazard – separate category because they are treated in different ways 9

Structural Hazards • Example: a unified instruction and data cache stage 4 (MEM) and

Structural Hazards • Example: a unified instruction and data cache stage 4 (MEM) and stage 1 (IF) can never coincide • The later instruction and all its successors are delayed until a cycle is found when the resource is free these are pipeline bubbles • Structural hazards are easy to eliminate – increase the number of resources (for example, implement a separate instruction and data cache) 10

Problem 5 • Show the instruction occupying each stage in each cycle (no bypassing)

Problem 5 • Show the instruction occupying each stage in each cycle (no bypassing) if I 1 is R 1+R 2 R 3 and I 2 is R 3+R 4 R 5 and I 3 is R 7+R 8 R 9 CYC-1 CYC-2 CYC-3 CYC-4 CYC-5 CYC-6 CYC-7 CYC-8 IF IF D/R D/R ALU ALU DM DM RW RW 11

Problem 5 • Show the instruction occupying each stage in each cycle (no bypassing)

Problem 5 • Show the instruction occupying each stage in each cycle (no bypassing) if I 1 is R 1+R 2 R 3 and I 2 is R 3+R 4 R 5 and I 3 is R 7+R 8 R 9 CYC-1 CYC-2 CYC-3 CYC-4 CYC-5 CYC-6 CYC-7 CYC-8 IF I 1 IF I 2 IF I 3 IF I 4 IF I 5 IF D/R I 1 D/R I 2 D/R I 3 D/R I 4 D/R ALU ALU I 1 ALU ALU I 2 ALU I 3 ALU DM DM I 1 DM DM DM I 2 DM I 3 RW RW RW I 1 RW RW RW I 2 12

Bypassing: 5 -Stage Pipeline Source: H&P textbook 13

Bypassing: 5 -Stage Pipeline Source: H&P textbook 13

Problem 6 • Show the instruction occupying each stage in each cycle (with bypassing)

Problem 6 • Show the instruction occupying each stage in each cycle (with bypassing) if I 1 is R 1+R 2 R 3 and I 2 is R 3+R 4 R 5 and I 3 is R 3+R 8 R 9. Identify the input latch for each input operand. CYC-1 CYC-2 CYC-3 CYC-4 CYC-5 CYC-6 CYC-7 CYC-8 IF IF D/R D/R ALU ALU DM DM RW RW 14

Problem 6 • Show the instruction occupying each stage in each cycle (with bypassing)

Problem 6 • Show the instruction occupying each stage in each cycle (with bypassing) if I 1 is R 1+R 2 R 3 and I 2 is R 3+R 4 R 5 and I 3 is R 3+R 8 R 9. Identify the input latch for each input operand. CYC-1 CYC-2 CYC-3 CYC-4 CYC-5 CYC-6 CYC-7 CYC-8 IF I 1 IF I 2 IF I 3 IF I 4 IF I 5 IF IF IF D/R I 1 D/R I 2 D/R I 3 D/R I 4 D/R D/R L 3 L 4 L 3 L 5 L 3 ALU I 3 ALU ALU ALU I 1 ALU I 2 DM DM I 1 DM I 2 DM I 3 DM DM RW RW RW I 1 RW I 2 RW I 3 RW

16

16