针对数据相关的值猜测执行 不等待产生结果的指令产生值,直接猜测一个值 继续 这种技术,仅在某些情况下可以使用: 分支预测 堆栈指针更新 存储器地址消除歧义( Memory address disambiguation)
针对数据相关的值猜测执行 • 不等待产生结果的指令产生值,直接猜测一个值 继续 • 这种技术,仅在某些情况下可以使用: – 分支预测 – 堆栈指针更新 – 存储器地址消除歧义(Memory address disambiguation) 22
采用软件方法避免数据相关 Try producing fast code for a = b+c assuming a, b, c, d, e, and f in memory. Slow code Fast code lw rb. b Rb, b LW RC.O LW RC. C LW ADD Ra rb. Rc Ree ADD Ra rb. Rc SW a Ra Rff LW Ree SW a Ra LW REf SUB Rd Rerf sub Rd Re, rf SW d Rd sW d rd 2/112021 hapter3. 23
采用软件方法避免数据相关 2/11/2021 chapter3.23 Fast code: LW Rb,b LW Rc,c LW Re,e ADD Ra,Rb,Rc LW Rf,f SW a,Ra SUB Rd,Re,Rf SW d,Rd Try producing fast code for a = b + c; d = e – f; assuming a, b, c, d ,e, and f in memory. Slow code: LW Rb,b LW Rc,c ADD Ra,Rb,Rc SW a,Ra LW Re,e LW Rf,f SUB Rd,Re,Rf SW d,Rd
Control hazards 如何计算下一条指令地址( next pc) 无条件直接转移 Opcode, PC, and offset 基于基址寄存器的无条件转移 Opcode, Register value, and offset 条件转移 Opcode, Register (for condition), PC and offset 其他指令 Opcode and pc and have to know it's not one of above
Control Hazards 如何计算下一条指令地址(next PC) • 无条件直接转移 – Opcode, PC, and offset • 基于基址寄存器的无条件转移 – Opcode, Register value, and offset • 条件转移 – Opcode, Register (for condition), PC and offset • 其他指令 – Opcode and PC ( and have to know it’s not one of above ) 24
O Control flow information in pipeline Fetch Decode EXecute Memory Writeback Opcode Branch condition PC known offset known Jump register value known / Data Instruction br Cache Cache
Fetch Decode EXecute Memory Control flow information in pipeline 25 Registers B A Data Cache PC Instruction Cache Store Imm Inst. Register Writeback PC known Opcode, offset known Branch condition, Jump register value known ALU
O RISC-V Unconditional PC-Relative Jumps PCJumpSel FKill 小ump Ki∥ bit turns d instruction into a bubble j +4 Instruction Cache Fetch Decode EXecute
Decode EXecute Fetch RISC-V Unconditional PC-Relative Jumps 26 Registers B A Instruction Cache Imm Inst. Register ALU PC_decode Add PCJumpSel Jump? PC_fetch Kill FKill +4 [ Kill bit turns instruction into a bubble ]