当前位置: 首页 > news >正文

处理器中的几种hazard

什么是hazard?

  • Instructions interact with each other in pipeline ;

Structural Hazard

原因:

  • An instruction in the pipeline may need a resource being used by another instruction in the pipeline ;
  • Structural hazard occurs when two instructions need same hardware resource at same time
  • 因缺乏硬件支持而导致指令不能在预定的时钟周期内执行的情况。

实例:

    例子1:存储器发生结构冒险(存、取冲突)

  • 假设图4-27 的流水线结构只有一个存储器而不是两个存储器,那么如果有第四条指令的话,第一条指令在访问存储器的同时第四条指令将会在同一存储器中预取指令,流水线就会发生结构冒险。
  • 这种解决方式,是stall older instruction;

   例子2:寄存器发生结构冒险(读、写冲突)

  • 如图所示,读寄存器和写寄存器同时发生,产生结构冒险。

如何解决:

  • Can resolve in hardware by stalling newer instruction till older instruction finished with resource
  • A structural hazard can always be avoided by adding more hardware to design;
    • E.g., if two instructions both need a port to memory at same time, could avoid hazard by adding second port to memory;
  • 感觉还有另外一种,是通过编译器解决的,就是编译器通过分析,将调整顺序不影响执行结果的指令,如果存在结构冒险,则通过调整顺序的方式,将这种结构冒险给消除掉;

Data Hazard

原因:

  • An instruction may depend on something produced by an earlier instruction;
    • Dependence for a data value;
  • 发生在由于一条指令必须等待另一条指令的完成而造成流水线暂停的情况下。
  • 这种hazard总结起来,就是说:无法提供指令所需数据;
    • 即一条指令的执行需要等待另一条指令执行完成后所产生的数据。

实例:

  • 上例中解决方式一:bubbles

  • 上例中解决方式二:bypass

如何解决:

  • Interlock
    • Wait for hazard to clear by holding dependent instruction in issue stage;
  • Bypass
    • Resolve hazard earlier by bypassing value as soon as available;
  • Speculate
    • Guess on value, correct if wrong;
    • So far, only effective in certain limited cases:
      • Branch prediction
      • Stack pointer updates
      • Memory address disambiguation

Control Hazard

原因:

  • An instruction may depend on something produced by an earlier instruction;
    • Dependence may be for the next instruction’s address(branches, exceptions);
  • 决策依赖于一条指令的结果,而其他指令正在执行中。比如说分支跳转指令,必须等ALU给出结果后才知道该跳转到哪一条语句。
  • 因为取到的指令并不是所需要的(或者说指令地址的变化并不是流水线所预期的)而导致指令不能在预定的时钟周期内执行。

实例一:

实例二:What do we need to calculate next PC?

  • 对于Unconditional Jumps类型的指令
    • Opcode, PC, and offset
  • 对于For Jump Register类型的指令
    • Opcode, Register value, and offset
  • 对于Conditional Branches类型的指令
    • Opcode, Register (for condition), PC and offset
  • 对于all other instructions
    • Opcode and PC ( and have to know it’s not one of above )

如何解决:

  • 加入delay slot;
  • 分支预测


http://www.mrgr.cn/news/45254.html

相关文章:

  • 幽门螺杆菌筛查在健康管理中的意义
  • 本地知识库+本地大模型,借助RAGFlow搭建医院医疗问诊助手,纯本地,超实用!
  • 全面整理人工智能(AI)学习路线图及资源推荐,非常详细收藏我这一篇就够了
  • 基于PHP+MySQL组合开发的720VR全景在线制作网站源码系统 带完整的安装代码包以及搭建部署教程
  • 自动化测试 | 下载谷歌驱动
  • 投资 -风口/政策大事记
  • 想走?可以!先买票——迭代器模式
  • 在 MySQL 中通过自定义哈希分片实现大规模数据的多线程并行处理20241008
  • 【Canvas与标牌】盾形银底红带Best Quality Premium标牌
  • JS 介绍/书写位置/输入输出语法
  • 一款开源Ai语音合成TTS工具:Fish Speech
  • SQL进阶技巧:如何优化NULL值引发的数据倾斜问题?
  • Dubbo超时设置与动态调整解决方案
  • Spring Boot实现License生成与校验详解
  • 省市区json记录
  • 上交2024最新-《动手学大模型》实战教程及ppt分享!
  • 什么是源代码加密?十种方法教你软件开发源代码加密
  • openmmlab使用系列(二):图像超分辨率重构
  • 雷池+frp 批量设置proxy_protocol实现真实IP透传
  • 创客匠人收官之作,创始人lP起点与终极之道,你一定要来!