350 likes | 402 Views
MEM/WB. ID/EX. EX/MEM. IF/ID. Adder. 4. Address. ALU. Ciclo 6. Determinou o endereço de A. A. 06 - add r1,r2,r3. 04 - sub r8,r9,r10. 03 - or r5,r6,r7. 05 - xor r11,r12,r13. 02 - and r2,r3,r4. Next PC. MUX. Next SEQ PC. Next SEQ PC. Zero?. RS1. Reg File. MUX. Memory. RS2.
E N D
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 6 Determinou o endereço de A A 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 02 - and r2,r3,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 7 Determinou o endereço de A A 07 - and r2,r3,r4 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 8 Determinou o endereço de A A 04 - sub r8,r9,r10 08 - or r5,r6,r7 07 - and r2,r3,r4 06 - add r1,r2,r3 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 9 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r3,r4 06 - add r1,r2,r3 05 - xor r11,r12,r13 09 - sub r8,r9,r10 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 10 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r3,r4 06 - add r1,r2,r3 09 - sub r8,r9,r10 10 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 6 Com dependência de dados Determinou o endereço de A A 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 02 - and r2,r3,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 7 Determinou o endereço de A A 07 - and r2,r1,r4 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 8 Determinou o endereço de A A 04 - sub r8,r9,r10 08 - or r5,r6,r7 07 - and r2,r1,r4 06 - add r1,r2,r3 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 9 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r1,r4 bolha 06 - add r1,r2,r3 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
bolha bolha MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 10 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r1,r4 06 - add r1,r2,r3 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
bolha bolha bolha MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 11 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r1,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
bolha bolha MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 12 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r1,r4 09 - sub r8,r9,r10 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
bolha MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 13 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r3,r4 09 - sub r8,r9,r10 10 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
ALU Forwarding ID/EX EX/MEM MEM/WR NextPC mux Registers Data Memory mux mux Immediate CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 6 Com forwarding Determinou o endereço de A A 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 02 - and r2,r3,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r1,r7 Instr. 09 – sub r8,r1,r10 Instr. 10 – xor r11,r1,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 7 Determinou o endereço de A A 07 - and r2,r1,r4 06 - add r1,r2,r3 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r1,r7 Instr. 09 – sub r8,r1,r10 Instr. 10 – xor r11,r1,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Vai ler o valor errado no fim do ciclo Ciclo 8 Determinou o endereço de A A 04 - sub r8,r9,r10 08 - or r5,r1,r7 07 - and r2,r1,r4 06 - add r1,r2,r3 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r1,r7 Instr. 09 – sub r8,r1,r10 Instr. 10 – xor r11,r1,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Vai ler o valor errado no fim do ciclo Usa o valor correto via forwarding Ciclo 9 Determinou o endereço de A A 08 - or r5,r1,r7 07 - and r2,r1,r4 06 - add r1,r2,r3 05 - xor r11,r12,r13 09 - sub r8,r1,r10 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r1,r7 Instr. 09 – sub r8,r1,r10 Instr. 10 – xor r11,r1,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Vai ler o valor certo no fim do ciclo Usa o valor correto via forwarding Ciclo 10 Determinou o endereço de A A 08 - or r5,r1,r7 07 - and r2,r1,r4 06 - add r1,r2,r3 09 - sub r8,r1,r10 10 - xor r11,r1,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – add r1,r2,r3 Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r1,r7 Instr. 09 – sub r8,r1,r10 Instr. 10 – xor r11,r1,r13 WB Data Imm RD RD RD Registradores feitos com FFs tipo D acionados por nível CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 8 Dependência verdadeira - LW Determinou o endereço de A A 04 - sub r8,r9,r10 08 - or r5,r6,r7 07 - and r2,r1,r4 06 - lw r1,0(r3) 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – lw r1,0(r3) Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 9 Determinou o endereço de A A 08 - or r5,r6,r7 07 - and r2,r1,r4 bolha 06 - lw r1,0(r3) 05 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – lw r1,0(r3) Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 10 Determinou o endereço de A A 08 - or r5,r6,r7 09 - sub r8,r1,r10 bolha 06 - lw r1,0(r3) 07 - and r2,r1,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – lw r1,0(r3) Instr. 07 – and r2,r1,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 6 Desvios condicionais – bolhas para trás Determinou o endereço de A A 06 - beqz r1, i10 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 02 - and r2,r3,r4 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – beqz r1, i10 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 7 Determinou o endereço de A A 07 - and r2,r3,r4 04 - sub r8,r9,r10 03 - or r5,r6,r7 05 - xor r11,r12,r13 06 - beqz r1, i10 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – beqz r1, i10 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 8 Determinou o endereço de A A 04 - sub r8,r9,r10 08 - or r5,r6,r7 07 - and r2,r3,r4 05 - xor r11,r12,r13 06 - beqz r1, i10 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – beqz r1, i10 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Ciclo 9 Determinou o endereço de A A anulada 08 - or r5,r6,r7 anulada 07 - and r2,r3,r4 06 - beqz r1, i10 05 - xor r11,r12,r13 10 - xor r11,r12,r13 Next PC MUX Next SEQ PC Next SEQ PC Zero? RS1 Reg File MUX Memory RS2 Data Memory MUX MUX Sign Extend Instr. 01 – add r1,r2,r3 Instr. 02 – and r2,r3,r4 Instr. 03 – or r5,r6,r7 Instr. 04 – sub r8,r9,r10 Instr. 05 – xor r11,r12,r13 Instr. 06 – beqz r1, i10 Instr. 07 – and r2,r3,r4 Instr. 08 – or r5,r6,r7 Instr. 09 – sub r8,r9,r10 Instr. 10 – xor r11,r12,r13 WB Data Imm RD RD RD CS252-s06, Lec 02-intro
MEM/WB ID/EX EX/MEM IF/ID Adder 4 Address ALU Pipeline melhorado Instruction Fetch Execute Addr. Calc Memory Access Instr. Decode Reg. Fetch Write Back Next SEQ PC Next PC MUX Adder Zero? RS1 Reg File Memory RS2 Data Memory MUX MUX Sign Extend WB Data Imm RD RD RD • Perda de apenas um ciclo se o desvio for tomado CS252-s06, Lec 02-intro
Four Branch Hazard Alternatives #1: Stall until branch direction is clear #2: Predict Branch Not Taken • Execute successor instructions in sequence • “Squash” instructions in pipeline if branch actually taken • Advantage of late pipeline state update • 47% MIPS branches not taken on average • PC+4 already calculated, so use it to get next instruction #3: Predict Branch Taken • 53% MIPS branches taken on average • But haven’t calculated branch target address in MIPS • MIPS still incurs 1 cycle branch penalty • Other machines: branch target known before outcome CS252-s06, Lec 02-intro
Four Branch Hazard Alternatives #4: Delayed Branch • Define branch to take place AFTER a following instruction branch instruction sequential successor1 sequential successor2 ........ sequential successorn branch target if taken • 1 slot delay allows proper decision and branch target address in 5 stage pipeline • MIPS uses this Branch delay of length n CS252-s06, Lec 02-intro
becomes becomes becomes if $2=0 then add $1,$2,$3 if $1=0 then add $1,$2,$3 sub $4,$5,$6 add $1,$2,$3 if $1=0 then sub $4,$5,$6 Escalonando Branch Delay Slots A. From before branch B. From branch target C. From fall through add $1,$2,$3 if $1=0 then add $1,$2,$3 if $2=0 then • A é a melhor escolha, pois enche o slot e reduz a contagem de instruções (CI) • Em B, a instrução sub pode precisar ser copiada, aumentando a CI • Em B e C, não pode haver problemas em executar a sub quando o desvio não é tomado sub $4,$5,$6 delay slot delay slot add $1,$2,$3 if $1=0 then sub $4,$5,$6 delay slot CS252-s06, Lec 02-intro
Delayed Branch • Compiler effectiveness for single branch delay slot: • Fills about 60% of branch delay slots • About 80% of instructions executed in branch delay slots useful in computation • About 50% (60% x 80%) of slots usefully filled • Delayed Branch downside: As processor go to deeper pipelines and multiple issue, the branch delay grows and need more than one delay slot • Delayed branching has lost popularity compared to more expensive but more flexible dynamic approaches • Growth in available transistors has made dynamic approaches relatively cheaper CS252-s06, Lec 02-intro
Evaluating Branch Alternatives Assume 4% unconditional branch, 6% conditional branch- untaken, 10% conditional branch-taken Scheduling Branch CPI speedup v. speedup v. scheme penalty unpipelined stall Stall pipeline 3 1.60 3.1 1.0 Predict taken 1 1.20 4.2 1.33 Predict not taken 1 1.14 4.4 1.40 Delayed branch 0.5 1.10 4.5 1.45 CS252-s06, Lec 02-intro
Problems with Pipelining • Exception: An unusual event happens to an instruction during its execution • Examples: divide by zero, undefined opcode • Interrupt: Hardware signal to switch the processor to a new instruction stream • Example: a sound card interrupts when it needs more audio output samples (an audio “click” happens if it is left waiting) • Problem: It must appear that the exception or interrupt must appear between 2 instructions (Ii and Ii+1) • The effect of all instructions up to and including Ii is totalling complete • No effect of any instruction after Ii can take place • The interrupt (exception) handler either aborts program or restarts at instruction Ii+1 CS252-s06, Lec 02-intro
Precise Exceptions in Static Pipelines Key observation: architected state only change in memory and register write stages.
Outra alternativa para reduzir o impacto dos desvios condicionais • Predição de desvios! • Mas, para compreender como implementar, precisamos saber como funcionam os caches! CS252-s06, Lec 02-intro