Pipeline

38
Pipeline Lab. FIC An03.Sapt03

description

Pipeline. Lab. FIC An03.Sapt03. Motto:. S aga lui Pip Eline. Pip Eline VS Vrăjitoarea Dacă Pip reuşeşte să facă clătitele mai repede decât vrăjitoarea, primeşte calul năzdrăvan. Cum lucrează vrăjitoarea?. Întors clătita. Scos clătita. Turnat aluatul. Încălzit tigaia. Timpul. - PowerPoint PPT Presentation

Transcript of Pipeline

Page 1: Pipeline

Pipeline

Lab. FICAn03.Sapt03

Page 2: Pipeline

2/38

Motto:

Page 3: Pipeline

3/38

Saga lui Pip Eline

• Pip Eline VS Vrăjitoarea– Dacă Pip reuşeşte să facă clătitele mai repede

decât vrăjitoarea, primeşte calul năzdrăvan

Page 4: Pipeline

4/38

Cum lucrează vrăjitoarea?

Timpul

Colectat ingredientele

Făcut aluatul

Încălzit tigaia

Turnat aluatul

Întors clătita

Scos clătita

Încălzit tigaia

Turnat aluatul

Întors clătitaScos clătita

Page 5: Pipeline

5/38

Cum lucrează Pip Eline?

Timpul

Colectat ingredientele

Făcut aluatul

Încălzit tigaia 1Turnat aluatul în tigaia 1

Încălzit tigaia 2

Întors clătita din tigaia 1Turnat aluatul în tigaia 2

Încălzit tigaia 3

Scos clătita din tigaia 1Întors clătita din tigaia 2Turnat aluatul în tigaia 3

Încălzit tigaia 4

Scos clătita din tigaia 3Întors clătita din tigaia 4Turnat aluatul în tigaia 1Încălzit tigaia 2

Scos clătita din tigaia 2Întors clătita din tigaia 3Turnat aluatul în tigaia 4Încălzit tigaia 1

Page 6: Pipeline

6/38

Cum ştim cine a câştigat?

• Timpul total– Timpul necesar până la terminarea apariţiei

tuturor ieşirilor

• Latenţa = L– Latency – Timpul necesar ca o intrare să apară la ieşire

• Capacitatea de trecere = T– Throughput– #outputs / time

Page 7: Pipeline

7/38

Pentru a obţine N clătite

• Vrăjitoarea– Timp total = timp ingrediente + timp aluat +

N*(t încălzit + t turnat + t întors + t scos)– Excluzând timpul pentru ingrediente şi aluat

• L= t încălzit + t turnat + t întors + t scos• T = 1 / L

• Pip Eline– Timp total = timp ingrediente + timp aluat +

N/4*(t încălzit + t turnat + t întors + t scos)– Excluzând timpul pentru ingrediente şi aluat

• L = max (t încălzit, t turnat, t întors, t scos) * 4• T = 1 / L

Page 8: Pipeline

8/38

Răsplata lui Pip.Eline

Page 9: Pipeline

9/38

Limitări al metodei pipeline

• Există porţiuni

NEPARALELIZABILE

Timpul

Colectat ingredientele

Făcut aluatul

Încălzit tigaia 1Turnat aluatul în tigaia 1

Încălzit tigaia 2

Întors clătita din tigaia 1Turnat aluatul în tigaia 2

Încălzit tigaia 3

Scos clătita din tigaia 1Întors clătita din tigaia 2Turnat aluatul în tigaia 3

Încălzit tigaia 4

Scos clătita din tigaia 2Întors clătita din tigaia 3Turnat aluatul în tigaia 4Încălzit tigaia 1

Page 10: Pipeline

10/38

De analizat: speed-up şi cost

A

C

B

16 km

44 km

Page 11: Pipeline

11/38

Speed-up & cost

A B C

4km/h

0 $

10km/h

10 $

50 km/h

40 $

250 km/h

150$

Timp Speed-up Cost

15h 1 0

8.4h 1.786 10

5.14h 2.92 40

4.176h 3.59 150

Page 12: Pipeline

12/38

Legea lui Amdhal

Page 13: Pipeline

13/38

Şi acum... Înapoi la circuite...

Page 14: Pipeline

14/38

Unpipelined VS pipelined in combinational logic

Unpipelined• L of the circuit =

longest path from the input to the output

• T is 1 output / L

Pipelined • registers in-between

• Ideal registers • zero contamination and

propagation delay• zero setup and hold time

• register’s clock cycle = propagation delay of the slowest block.

Page 15: Pipeline

15/38

Making a pipeline - rules of thumb

1. Put two dots on opposite sides of the circuit. Draw lines from one dot to another

2. Always put a register on the output

3. Isolate the slowest block with registers. Make this block the slowest stage for maximum throughput

4. Never cross a path twice with the same line. This helps ensure that each path has the same number of registers

5. Add a register every time a line crosses a wire.

• Sursa: A Student’s Guide to the Digital World by Margaret Chong

Page 16: Pipeline

16/38

Exemplu

• Any configuration is valid as long as there are an equal number of registers on each path from input to output.

• Sursa: A Student’s Guide to the Digital World by Margaret Chong

Page 17: Pipeline

17/38

MIPS

Page 18: Pipeline

18/38

MIPS - pipeline

Page 19: Pipeline

19/38

ALU instructions - schema

Page 20: Pipeline

20/38

ALU instructions – schema + tabelul IF/ID.IR ← Mem[PC]; IF/ID.NPC,PC ← (if ((EX/MEM.opcode == branch) & EX/MEM.cond){EX/MEM.ALUOutput} else {PC+4});

ID/EX.A ← Regs[IF/ID.IR[rs]]; ID/EX.B ← Regs[IF/ID.IR[rt]];ID/EX.IR ← IF/ID.IR;

EX/MEM.IR ← ID/EX.IR;EX/MEM.ALUOutput←ID/EX.A func ID/EX.B;orEX/MEM.ALUOutput ←ID/EX.A op ID/EX.Imm;EX/MEM.cond ← 0;

MEM/WB.IR ← EX/MEM.IR;MEM/WB.ALUOutput ←EX/MEM.ALUOutput;

Regs[MEM/WB.IR[rd]] ←MEM/WB.ALUOutput;orRegs[MEM/WB.IR[rt]] ←MEM/WB.ALUOutput;

Page 21: Pipeline

21/38

Load - schema

Page 22: Pipeline

22/38

Load – schema + tabelul IF/ID.IR ← Mem[PC]; IF/ID.NPC,PC ← (if ((EX/MEM.opcode == branch) & EX/MEM.cond){EX/MEM.ALUOutput} else {PC+4});

ID/EX.A ← Regs[IF/ID.IR[rs]]; ID/EX.Imm ← sign extend(IF/ID.IR[immediate field]);ID/EX.IR ← IF/ID.IR;

EX/MEM.IR← ID/EX.IREX/MEM.ALUOutput ←ID/EX.A + ID/EX.Imm;EX/MEM.cond ← 0;

MEM/WB.IR ← EX/MEM.IR;MEM/WB.LMD ←Mem[EX/MEM.ALUOutput];

Regs[MEM/WB.IR[rt]] ←MEM/WB.LMD;

Page 23: Pipeline

23/38

Store - schema

Page 24: Pipeline

24/38

Store – schema + tabelul IF/ID.IR ← Mem[PC]; IF/ID.NPC,PC ← (if ((EX/MEM.opcode == branch) & EX/MEM.cond){EX/MEM.ALUOutput} else {PC+4});

ID/EX.A ← Regs[IF/ID.IR[rs]]; ID/EX.B ← Regs[IF/ID.IR[rt]];ID/EX.Imm ← sign extend(IF/ID.IR[immediate field]);ID/EX.IR ← IF/ID.IR;

EX/MEM.IR← ID/EX.IREX/MEM.ALUOutput ←ID/EX.A + ID/EX.Imm;EX/MEM.cond ← 0;EX/MEM.B← ID/EX.B;

MEM/WB.IR ← EX/MEM.IR;Mem[EX/MEM.ALUOutput] ←EX/MEM.B;

Page 25: Pipeline

25/38

Branch - schema

NPC

Page 26: Pipeline

26/38

Branch – schema + tabelul IF/ID.IR ← Mem[PC]; IF/ID.NPC,PC ← (if ((EX/MEM.opcode == branch) & EX/MEM.cond){EX/MEM.ALUOutput} else {PC+4});

ID/EX.A ← Regs[IF/ID.IR[rs]]; ID/EX.NPC ← IF/ID.NPCID/EX.Imm ← sign extend(IF/ID.IR[immediate field]);ID/EX.IR ← IF/ID.IR;

EX/MEM.ALUOutput ←ID/EX.NPC+ID/EX.Imm;EX/MEM.cond ←(ID/EX.A == 0);

NPC

Page 27: Pipeline

27/38

And that’s MIPS pipeline schematics in a nutshell!

Page 28: Pipeline

28/38

Moduri de notatie

• O instructiune:

• sau

• Mai multe instructiuni

Page 29: Pipeline

29/38

Let’s complicate things!

Page 30: Pipeline

30/38

Moduri de tratare branch-uri -1/5

• De ce e necesar?– Pentru ca branch-ul se intoarce cu adresa CORECTA de

start abia dupa ciclul de EX

Page 31: Pipeline

31/38

Moduri de tratare branch-uri -2/5• Freeze & flush

1 2 3 4 5 6 7 8

Branch IF ID EX MEM WB

Next instruction

STALL STALL IF ID EX MEM WB

Page 32: Pipeline

32/38

Moduri de tratare branch-uri -4/5

• Predict as untaken

cc1 cc2 cc3 cc4 cc5 cc6 cc7

Branch instruction

IF ID EX MEM WB

IF

next

instruction

Stall ID EX MEM WB If not taken

IF

branch

target

ID EX MEM If taken

Page 33: Pipeline

33/38

Moduri de tratare branch-uri -3/5

• Predict as taken

cc1 cc2 cc3 cc4 cc5 cc6 cc7

Branch instruction

IF ID EX MEM WB

IF

branch

target

Stall ID EX MEM WB If taken

IF next

instruction

ID EX MEM If not taken

Page 34: Pipeline

34/38

Moduri de tratare branch-uri -5/5

• Delayslot

Page 35: Pipeline

35/38

Tricks & treats – 1/3

Page 36: Pipeline

36/38

Tricks & treats – 2/3

• Forwarding

Page 37: Pipeline

37/38

Tricks & treats – 3/3

• Bypassing

S.D F8, -8(R1)

Page 38: Pipeline

38/38

Congratulations! You’ve made it!