Skip to content

Lecture 9 | The Processor-Part2

:material-circle-edit-outline: 约 645 个字 :material-clock-time-two-outline: 预计阅读时间 2 分钟

Dynamic Branch Prediction

方法:如果上一次跳了,这次也跳

Use dynamic prediction:

  1. Branch prediction buffer (aka branch history table)

专门用于储存branch记录

  1. Indexed by recent branch instruction addresses (lower part)

pc是64bit,太大了,我们只取低的几位n

可能会低几位有正好重复的,导致准确率降低,但是同时减少了reg的s/l开销

  1. Stores outcome (taken/not taken)
  • To execute a branch
    • Check table, expect the same outcome
    • Start fetching from fall-through or target
    • If wrong, flush pipeline and flip prediction

1-Bit Predictor: Shortcoming

1-Bit Predictor 就只记上一次是否有branch

对于loop循环有Shortcoming

image-20240428183208441

  • Inner loop branches mispredicted twice!
    • Mispredict as taken on last iteration of inner loop.
    • Then mispredict as not taken on first iteration of inner loop next time around

2-Bit Predictor

对于for循环有特效

Only change prediction on two successive mispredictions

image-20240428183324797

Calculating the Branch Target

Even with predictor, still need to calculate the target address

  • 1-cycle penalty for a taken branch

Branch target buffer

这个存的下一级要去的的pc地址

Branch prediction buffer 存的是跳转行为,决定是否要跳转

  • Cache of target addresses
  • Indexed by PC when instruction fetched
    • If hit and instruction is branch predicted taken, can fetch target immediately

4.9 Exceptions and Interrupts

“Unexpected” events requiring change in flow of control

  • Exception:Arises within the CPU
    • 异常
  • Interrupt:From an external I/O controller
    • 中断

Handling Exceptions

method-1

软件处理

遇到问题,保存当前位置,将相关信息交给专门的程序去统一处理

  1. Save PC of offending (or interrupted) instruction
    • Supervisor Exception Program Counter (SEPC) 用于储存当前PC
  2. Save indication of the problem
    • Supervisor Exception Cause Register (SCAUSE) 一组reg,传递异常时的状态,借给OS去处理
  3. Jump to handler
    1. Assume at 0000 0000 1C09 0000hex,异常处理程序的地址

method-2

硬件处理,指用硬件判断异常情况

也是需要专门的程序,但是用硬件先判断是什么异常,根据情况跳到不同程序去分别处理

  1. Vectored Interrupts
    • Handler address determined by the cause
  2. Exception vector address to be added to a vector table base register
    • Undefined opcode 00 0100 0000two
    • Hardware malfunction: 01 1000 0000two
    • ...
  3. Instructions either
    • Deal with the interrupt, or Jump to real handler

Handler Actions

  1. Read cause, and transfer to relevant handler
  2. Determine action required
  3. If restartable
    • Take corrective action,use SEPC to return to program
  4. Otherwise
    • Terminate program,Report error using SEPC, SCAUSE, …

从这开始后面的课可以重新听一下

Exceptions in a Pipeline

image-20240428185131602

Pipeline with Exceptions

image-20240428185210371

Exception Properties

image-20240428185704988

Exception Example

image-20240428185715626

image-20240428185810643

image-20240428185917470

Multiple Exceptions

image-20240428185931785

Imprecise Exceptions

image-20240428185950779

4.10 Instruction-Level Parallelism (ILP)

指令集并行

多发 Multiple issue ,同一时间安排多条指令

image-20240428190123723

Multiple Issue

image-20240428191035658

Speculation

与prediction不同,这个是调度方面的预测,看怎么排程序出错概率最低

image-20240428191240139

Compiler/Hardware Speculation

image-20240428191649579

Speculation and Exceptions

image-20240428191701258

Static Multiple Issue

image-20240428193536522

Scheduling Static Multiple Issue

image-20240428193555129

RISC-V with Static Dual Issue

image-20240428193632026

image-20240428193650257

Hazards in the Dual-Issue RISC-V

image-20240428193705849

Scheduling Example

image-20240428193714474

Loop Unrolling

image-20240428193722859

Loop Unrolling Example

image-20240428193735114

Dynamic Multiple Issue

image-20240428193746907

Dynamic Pipeline Scheduling

image-20240428193755369

Dynamically Scheduled CPU

image-20240428193811726

Register Renaming

image-20240428193823401

Speculation

image-20240428193850363

Why Do Dynamic Scheduling?

image-20240428193858203

Does Multiple Issue Work?

image-20240428193905708

Power Efficiency

image-20240428193915163