Presentation is loading. Please wait.

Presentation is loading. Please wait.

CBP 2005Comp 3070 Computer Architecture1 Last Time … All instructions the same length We learned to program MIPS And a bit about Intel’s x86 Instructions.

Similar presentations


Presentation on theme: "CBP 2005Comp 3070 Computer Architecture1 Last Time … All instructions the same length We learned to program MIPS And a bit about Intel’s x86 Instructions."— Presentation transcript:

1 CBP 2005Comp 3070 Computer Architecture1 Last Time … All instructions the same length We learned to program MIPS And a bit about Intel’s x86 Instructions of variable length

2 CBP 2005Comp 3070 Computer Architecture2 Today the consequences of … Intel (CISC) MIPS (RISC)

3 CBP 2005Comp 3070 Computer Architecture3 Laundry Model Washer Drier Store Basket Wardrobe

4 CBP 2005Comp 3070 Computer Architecture4 Process Steps A. Wash then Dry idle running time 9.0010.0011.00 1.Load the washer at 9.00 2.Done at 10, load the drier 3.Drier Done at 11

5 CBP 2005Comp 3070 Computer Architecture5 Sequential Process 3 loads takes 6 hours time 9.00 15.00 11.00 1.Load washer at 9.00 2.Done at 10, load drier 3.Drier Done at 11 4.Reload washer at 11 5.Done at 12, load drier 6.Drier done at 13 7.Reload washer at 13 8.Done at 14, load drier 9.Done at 15 13.00

6 CBP 2005Comp 3070 Computer Architecture6 Overlapping Process 3 loads takes 4 hours time 9.00 15.00 11.00 1.Load washer at 9.00 2.Done at 10, load drier reload washer 3.Both Done at 11. Reload drier reload washer 4.Both done at 12. Reload drier 5.Drier done at 13 13.00 From 10.00 till 11.00 both washer and dryer running concurrently

7 CBP 2005Comp 3070 Computer Architecture7 Washing Pipeline Filling time 9.0011.0013.0015.0017.00 18.00 5 loads in 9 hours 5 Cycles !!! 1.Get washing 2.Wash 3.Dry 4.Store 5.Put away

8 CBP 2005Comp 3070 Computer Architecture8 Washing Pipeline Full time 9.0011.0013.0015.0017.00 Pipe Full gives 1 load per hour

9 CBP 2005Comp 3070 Computer Architecture9 Pipelining : Comments time 9.0011.0013.0015.0017.00 18.00 Potential speedup = number of stages Time to ‘fill’ and ‘drain’ reduces speedup Rate limited by slowest step

10 CBP 2005Comp 3070 Computer Architecture10 Can we Pipeline SAM ? Data Memory Instruction reg Code Memory ALU r1 r2 r0 X Y W XY W 0 1 7 mar mdr 1.Fetch 2.Dec/ Reg 3.ALU 4.Mem 5.RW

11 CBP 2005Comp 3070 Computer Architecture11 Pipelined Sam4 Data Memory 0 1 7 X Y W Y W r1 r2 r0 X Code Memory 1.Fetch2.Dec/ Reg 3.ALU4.Mem5.RW Buffer time

12 CBP 2005Comp 3070 Computer Architecture12 5 Stages in Pipeline ALU Mem Reg MemReg add r3,r1,r2 r1,r2 r3 add Let’s take the instruction add r3,r1,r2 and show which stage is needed for each part of the instruction. 1.Fetch 2.Dec/ Reg 3.ALU4.Mem5.RW time

13 CBP 2005Comp 3070 Computer Architecture13 ld r0 Memr3 Two Instructions ld r3,[r0+2] Two instructions into the pipeline add r4,r1,r2 ALU add r1,r2 r4 r0 2 time

14 CBP 2005Comp 3070 Computer Architecture14 Structural Hazard ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg Here we are being asked to read from memory and write to it simultaneously. Impossible! Write (store) Read (fetch) Solution – Use separate code and data memories add r4,r1,r2 st r0,[5]

15 CBP 2005Comp 3070 Computer Architecture15 Hazardous Washing time 9.0011.0013.0015.0017.00 18.00 Washing basket containes both clean and dirty washing!

16 CBP 2005Comp 3070 Computer Architecture16 Code and Data Memories ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg

17 CBP 2005Comp 3070 Computer Architecture17 add r1,r2 r3 Data Hazard add r3,r1,r2 but need r3 here EARLIER ! add r4,r1,r3 add r1,r3 r4 r3 set here time

18 CBP 2005Comp 3070 Computer Architecture18 Data Hazard ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg add r3,r1,r2 add r4,r1,r3 Need value of r3 for second instruction before the first is complete.

19 CBP 2005Comp 3070 Computer Architecture19 Pipeline Stalls ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg Mem ALU Reg MemReg Stall ALU Mem Reg MemReg add r3,r1,r2 add r4,r1,r3 Resolve Hazard – Insert delay into second instruction stream. ‘Stall’ Cycles. But this needs extra electronics on the chip. Complex and Costly.

20 CBP 2005Comp 3070 Computer Architecture20 Forwarding ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg add r3,r1,r2 add r4,r1,r3 Need value of r3 for second instruction before the first is complete. So build in extra circuits to get the data as soon as it is available from the ALU

21 CBP 2005Comp 3070 Computer Architecture21 Compiler resolves Hazard ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg ALU Mem Reg MemReg add r3,r1,r2 add r4,r1,r3 Compile can detect possible hazard and insert 2 nops (‘no ops’) ALU Mem Reg MemReg ALU Mem Reg MemReg nop

22 CBP 2005Comp 3070 Computer Architecture22 Example op code regs alu mem reg write ld r1,[7] ld r2,[8] add r3,r1,r2 ld r1 [7] ld r2 [8] add r1, r2 r3

23 CBP 2005Comp 3070 Computer Architecture23 Exercise op code regs alu mem reg write ld r1,[7] add r1,r2,r0 add r3,r1,r2

24 CBP 2005Comp 3070 Computer Architecture24 Control (branch) Hazard ? beq r1,r2 Test done add r1,r2 r3 st r3 [64] st r2 [68] ld 124 [124]r1 4 beq r1,r2,20 8 add r3,r1,r2 12 st r3,[64] 16 st r2,[68] 20 ld r1,[124] Program may branch to 20 If r1 = r2 branch to 20 Test if r1 = r2 done by ALU. Result known only in stage 4 Run from here now Must FLUSH these

25 CBP 2005Comp 3070 Computer Architecture25 Branch Hazard Resolution Let’s just assume the branch will NOT be taken So the following instruction needs to be executed And this is already in the pipeline So we make no changes to our CPU hardware design We will be wrong 50% of the time, at a guess. Then we have to flush the pipeline The above assumption is a crude form of Branch Prediction Could keep a branch prediction table storing the results of previous branches. Use this to make a statistics based decision


Download ppt "CBP 2005Comp 3070 Computer Architecture1 Last Time … All instructions the same length We learned to program MIPS And a bit about Intel’s x86 Instructions."

Similar presentations


Ads by Google