Branch direction predictor
分支方向预测器

A branch direction predictor generates taken/not-taken predictions of the direction of conditional branch instructions. It sits near the front of the processor pipeline, and is responsible for directing instruction fetch down the (hopefully) correct program execution path. A branch direction predictor is usually used with a branch target buffer (BTB), where the BTB predicts the target addresses and the direction predictor chooses whether to branch to the target or keep fetching along the fall-through path.
分支方向预测器会预测条件分支指令方向的执行/不执行情况。它位于处理器流水线前端附近,负责引导指令提取到(希望)正确的程序执行路径。分支方向预测器通常与分支目标缓冲区 (BTB) 一起使用,其中 BTB 预测目标地址,方向预测器选择是分支到目标地址还是继续沿着 fall-through 路径提取指令。

Sometime later in the pipeline (typically at branch execution or retire), the results of executed branch instructions are sent back to the branch predictor to train it to predict more accurately in the future by observing past branch behaviour. There can also be pipeline flushes when there is a mispredicted branch.
在流水线的某个稍后阶段(通常是在分支执行或退出时),已执行分支指令的结果会被发送回分支预测器,以便通过观察过去的分支行为来训练它,使其能够更准确地预测未来的分支。当出现分支预测错误时,也可能会触发流水线刷新。

Branch direction predictor located in the Fetch stage. The branch predictor makes a prediction using the current pc and history register, with the result of the prediction affecting the next pc value. Training and misprediction requests come from later in the pipeline.
分支方向预测器位于提取阶段。分支预测器使用当前 pc 和历史寄存器进行预测,预测结果会影响下一个 pc 值。训练和错误预测请求来自流水线的后期。

For this exercise, the branch direction predictor is assumed to sit in the fetch stage of a hypothetical processor pipeline shown in the diagram on the right. This exercise builds only the branch direction predictor, indicated by the blue dashed rectangle in the diagram.
在本练习中,假设分支方向预测器位于右图所示的假设处理器流水线的提取阶段。本练习仅构建分支方向预测器,图中蓝色虚线矩形表示。

The branch direction prediction is a combinational path: The pc register is used to compute the taken/not-taken prediction, which affects the next-pc multiplexer to determine the value of pc in the next cycle.
分支方向预测是一条组合路径: pc 寄存器用于计算是否被采取的预测,这会影响下一个 pc 多路复用器以确定下一个周期中 pc 的值。

Conversely, updates to the pattern history table (PHT) and branch history register take effect at the next positive clock edge, as would be expected for state stored in flip-flops.
相反,模式历史表 (PHT) 和分支历史寄存器的更新将在下一个正时钟边沿生效,正如触发器中存储的状态所预期的那样。

Gshare predictor  Gshare 预测器

Branch direction predictors are often structured as tables of counters indexed by the program counter and branch history. The table index is a hash of the branch address and history, and tries to give each branch and history combination its own table entry (or at least, reduce the number of collisions). Each table entry contains a two-bit saturating counter to remember the branch direction when the same branch and history pattern executed in the past.
分支方向预测器通常构造为由程序计数器和分支历史记录索引的计数器表。表索引是分支地址和历史记录的哈希值,并尝试为每个分支和历史记录组合赋予其自己的表条目(或至少减少冲突次数)。每个表条目包含一个两位饱和计数器,用于记住过去执行相同分支和历史记录模式时的分支方向。

One example of this style of predictor is the gshare predictor[1]. In the gshare algorithm, the branch address (pc) and history bits "share" the table index bits. The basic gshare algorithm computes an N-bit PHT table index by xoring N branch address bits and N global branch history bits together.
这种预测器的一个例子是 gshare 预测器 [1] 。在 gshare 算法中,分支地址 ( pc ) 和历史位“共享”表索引位。基本的 gshare 算法通过对 N 个分支地址位和 N 个全局分支历史位进行异或运算来计算 N 位 PHT 表索引。

The N-bit index is then used to access one entry of a 2N-entry table of two-bit saturating counters. The value of this counter provides the prediction (0 or 1 = not taken, 2 or 3 = taken).
然后使用 N 位索引访问 2 N 个两位饱和计数器表中的一项。该计数器的值用于预测(0 或 1 = 未执行,2 或 3 = 执行)。

Training indexes the table in a similar way. The training pc and history are used to compute the table index. Then, the two-bit counter at that index is incremented or decremented depending on the actual outcome of the branch.
训练以类似的方式对表进行索引。训练 pc 和历史记录用于计算表索引。然后,根据分支的实际结果,该索引处的两位计数器会递增或递减。

References  参考
  1.  S. McFarling, "Combining Branch Predictors", WRL Technical Note TN-36, Jun. 1993
     S. McFarling,“ 合并分支预测器 ”, WRL 技术说明 TN-36,1993 年 6 月

Description  描述

Build a gshare branch predictor with 7-bit pc and 7-bit global history, hashed (using xor) into a 7-bit index. This index accesses a 128-entry table of two-bit saturating counters (similar to cs450/counter_2bc). The branch predictor should contain a 7-bit global branch history register (similar to cs450/history_shift).
构建一个 gshare 分支预测器,其 7 位 pc 和 7 位全局历史记录,并通过异或操作将其散列到一个 7 位索引中。该索引访问一个包含 128 个条目的两位饱和计数器表(类似于 cs450/counter_2bc) 。 )。分支预测器应包含一个 7 位全局分支历史寄存器(类似于 cs450/history_shift )。

The branch predictor has two sets of interfaces: One for doing predictions and one for doing training. The prediction interface is used in the processor's Fetch stage to ask the branch predictor for branch direction predictions for the instructions being fetched. Once these branches proceed down the pipeline and are executed, the true outcomes of the branches become known. The branch predictor is then trained using the actual branch direction outcomes.
分支预测器有两组接口:一组用于预测,一组用于训练。预测接口用于处理器的提取阶段,用于请求分支预测器对正在提取的指令进行分支方向预测。一旦这些分支指令沿着流水线向下执行,就会知道分支的真实结果。然后,使用实际的分支方向结果对分支预测器进行训练。

When a branch prediction is requested (predict_valid = 1) for a given pc, the branch predictor produces the predicted branch direction and state of the branch history register used to make the prediction. The branch history register is then updated (at the next positive clock edge) for the predicted branch.
当针对给定 pc 请求分支预测( predict_valid = 1)时,分支预测器会生成预测的分支方向以及用于进行预测的分支历史寄存器的状态。然后,分支历史寄存器会在下一个正时钟沿根据预测的分支进行更新。

When training for a branch is requested (train_valid = 1), the branch predictor is told the pc and branch history register value for the branch that is being trained, as well as the actual branch outcome and whether the branch was a misprediction (needing a pipeline flush). Update the pattern history table (PHT) to train the branch predictor to predict this branch more accurately next time. In addition, if the branch being trained is mispredicted, also recover the branch history register to the state immediately after the mispredicting branch completes execution.
当请求训练分支时 ( train_valid = 1),分支预测器会被告知正在训练的分支的 pc 和分支历史寄存器值,以及实际分支结果以及该分支是否为错误预测(需要流水线刷新)。更新模式历史表 (PHT) 以训练分支预测器,使其下次能够更准确地预测该分支。此外,如果正在训练的分支预测错误,还会将分支历史寄存器恢复到错误预测分支执行完成后的状态。

If training for a misprediction and a prediction (for a different, younger instruction) occurs in the same cycle, both operations will want to modify the branch history register. When this happens, training takes precedence, because the branch being predicted will be discarded anyway. If training and prediction of the same PHT entry happen at the same time, the prediction sees the PHT state before training because training only modifies the PHT at the next positive clock edge. The following timing diagram shows the timing when training and predicting PHT entry 0 at the same time. The training request at cycle 4 changes the PHT entry state in cycle 5, but the prediction request in cycle 4 outputs the PHT state at cycle 4, without considering the effect of the training request in cycle 4.
如果在同一周期内发生针对错误预测和预测(针对不同的、较新的指令)的训练,则这两个操作都需要修改分支历史寄存器。当这种情况发生时,训练优先,因为被预测的分支无论如何都会被丢弃。如果对同一 PHT 条目的训练和预测同时发生,则预测会在训练之前看到 PHT 状态,因为训练只会在下一个时钟上升沿修改 PHT。下图显示了同时训练和预测 PHT 条目 0 的时序。周期 4 的训练请求会改变周期 5 的 PHT 条目状态,但周期 4 的预测请求会输出周期 4 的 PHT 状态,而没有考虑周期 4 训练请求的影响。

Training and predicting using PHT entry 0 at the same time123456789clktrain_validtrain_pc ^ train_history0train_takenpht[0]123predict_validpredict_pc ^ predict_history0predict_takentrainpredictabc


areset is an asynchronous reset that clears the entire PHT to 2b'01 (weakly not-taken). It also clears the global history register to 0.
areset 是一个异步复位,它会将整个 PHT 清零为 2b'01(弱不执行)。它还会将全局历史寄存器清零。

module top_module#(parameter N = 128,parameter M = 7
)(input clk,input areset,input  predict_valid,input  [M-1:0] predict_pc,output predict_taken,output [M-1:0] predict_history,input train_valid,input train_taken,input train_mispredicted,input [M-1:0] train_history,input [M-1:0] train_pc
);reg [1:0] PHT [N-1:0];reg [M-1:0] GHR;assign predict_history = GHR;assign predict_taken = PHT[predict_history ^ predict_pc] > 1;integer i;always@(posedge clk or posedge areset) beginif(areset) beginfor (i=0; i<N; i=i+1) PHT[i] <= 1;GHR <= 0;endelse begin//处理GHR,回滚优先if(train_valid & train_mispredicted)beginGHR <= {train_history[M-2:0],train_taken};endelse if(predict_valid) beginGHR <= {GHR[M-2:0],predict_taken};   end//处理PHTif(train_valid) beginif(train_taken) beginPHT[train_history ^ train_pc] <= PHT[train_history ^ train_pc] == 3 ? 3 : PHT[train_history ^ train_pc] + 1;endelse beginPHT[train_history ^ train_pc] <= PHT[train_history ^ train_pc] == 0 ? 0 : PHT[train_history ^ train_pc] - 1;endend    endend
endmodule

还想用之前的模块,但发现越改越麻烦,还是重写吧。

那么HDLBits就堂堂完结了,希望秋招能找个好工作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/89867.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/89867.shtml
英文地址,请注明出处:http://en.pswp.cn/bicheng/89867.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[学习] 双边带调制 (DSB) 与单边带调制 (SSB) 深度对比

双边带调制 (DSB) 与单边带调制 (SSB) 深度对比 文章目录双边带调制 (DSB) 与单边带调制 (SSB) 深度对比**数学原理****调制表达式与频谱****时域特性****频域特性****Python 仿真代码****仿真结果分析****工程应用建议**数学原理 设基带信号为 m(t)m(t)m(t)&#xff08;带宽为…

Gitee 提交信息的规范

在使用 git push 命令将代码推送到 Gitee&#xff08;或任何 Git 平台&#xff09;时&#xff0c;引号中的信息通常指的是 提交信息&#xff08;Commit Message&#xff09;。提交信息是对本次代码修改的简要描述&#xff0c;规范的提交信息有助于团队协作和版本管理。 Gitee 提…

C 语言经典编程题实战:从基础算法到趣味问题全解析

在 C 语言学习过程中&#xff0c;通过实战编程题巩固知识点是非常有效的方式。本文整理了一系列经典 C 语言编程题&#xff0c;涵盖基础计算、逻辑判断、图形打印等多个维度&#xff0c;并附上完整代码与解析&#xff0c;适合初学者参考学习上机题1.计算n以内所有正奇数的和 ?…

Chapter 3 Design of Switching Power Regulators

Chapter 3 Design of Switching Power Regulators Power Management Techniques for Integrated Circuit Design by Ke-Horng Chen 这本书比较深, 简单介绍基本概念后, 就直接抛出大段公式和结论, 一章讲其他书几章内容, 适合有一定基础, 想进一步做电源系统的人查阅. 优点是不…

算法题(176):three states

审题&#xff1a; 本题需要我们找到最佳铺设道路&#xff0c;将三个国家联通起来&#xff0c;然后输出最佳铺设道路的铺设数量&#xff0c;若没有联通方法则输出-1 思路&#xff1a; 首先我们正面思考&#xff1a;只需从某个点出发然后搜索到三个国家即可&#xff0c;最后对比所…

BIOS+MBR微内核加载loader程序实现过程

上一篇讲到的微内核程序是由BIOS例程自动加载到内存中运行的,而且大小有限,能做的事情有限。我们知道内核程序大小是可以扩展的不能只有512字节,同时在加载运行内核前还需要完成一些必要的实模式下才能做的准备工作。所以单纯在实模式下只使用微内核程序是不太够的,就有了加…

使用Proxy设计模式来增强类的功能:ToastProxy和DesktopToast的设计关系

使用代理模式来增强类的功能&#xff1a;ToastProxy和DesktopToast Documentation: v1.0.0 Specified for Version v1.12.0&#xff0c;First Release in 2025/7/12 Documenation belongs to Projects: Charliechen114514/CCIMXDesktop: This is a Simple Desktop with Common …

瑞芯微2025开发者大会之见闻

序言本人参加了2025年的瑞芯微开发者大会&#xff0c;在展览区看到了很多有意思的音视频产品&#xff0c;下面按照产品类型分类给大家做一下展示。期间并没有将所有展出物进行拍摄&#xff0c;但是基本已经覆盖大部分内容。1、RK3566该芯片内置DSP音频处理器&#xff0c;蓝牙5.…

【最新】Java的几种设计模式详解及适用业务场景

✅ 1. 单例模式&#xff08;Singleton&#xff09; 定义&#xff1a;确保类只有一个实例&#xff0c;并提供全局访问点。优点&#xff1a;节省资源、控制访问。场景&#xff1a;数据库连接池、日志管理器、配置中心。代码要点&#xff1a; 构造方法私有静态变量保存唯一实例公共…

单链表的手动实现+相关OJ题

目录 链表的介绍 单链表的手动实现 单链表的基本框架 打印链表&#xff1a; 获取表长&#xff1a; 头插法新增节点&#xff1a; 尾插法新增节点&#xff1a; 在指定下标插入&#xff1a; 链表的查找 删除链表中第一个出现的key&#xff1a; 删除链表中所有key值 链表…

梯度提升之原理

简介 梯度提升主要是基于数学最值问题 数学描述 目标函数为 obj(θ)∑i1nl(yi,y^i(t))∑k1tw(fk)obj(\theta) \sum_{i1}^n l(y_i, \hat y_i^{(t)}) \sum_{k1}^t w(f_k)obj(θ)i1∑n​l(yi​,y^​i(t)​)k1∑t​w(fk​) 其中ttt表示集成的树的个数&#xff0c;y^i(t)y^i(t−1)…

[学习] Hilbert变换:从数学原理到物理意义的深度解析与仿真实验(完整实验代码)

Hilbert变换&#xff1a;从数学原理到物理意义的深度解析与仿真实验 文章目录Hilbert变换&#xff1a;从数学原理到物理意义的深度解析与仿真实验一、数学原理二、作用与物理意义1.构造解析信号2.相位移动特性3.应用场景三、仿真实验实验1&#xff1a;正弦信号的Hilbert变换实验…

对话弋途科技:当AI重构汽车大脑,一场车载操作系统的“觉醒年代“开始了

&#xff08;图片来源&#xff1a;Pixels&#xff09;站在未来看历史&#xff0c;AI汽车刚刚开始。数科星球原创作者丨苑晶编辑丨大兔当特斯拉的自动驾驶仍在全球引发争议时&#xff0c;中国智能汽车战场已悄然开启第二幕。从"四个轮子的大手机"到"移动智能空间…

❗机器学习量化交易模型全面剖析报告基于因子库的机器学习交易模型构建指南

目录 第一章&#xff1a;机器学习在加密货币量化交易中的应用概述 范式转变&#xff1a;从传统因子到机器学习驱动的策略 为什么选择机器学习&#xff1f;机遇、挑战与核心概念 机遇 挑战 核心概念 第二章&#xff1a;为机器学习准备您的因子库 理解量化因子作为机器学…

内容创作智能体:多模态内容生成的完整解决方案

内容创作智能体&#xff1a;多模态内容生成的完整解决方案 &#x1f31f; 嗨&#xff0c;我是IRpickstars&#xff01; &#x1f30c; 总有一行代码&#xff0c;能点亮万千星辰。 &#x1f50d; 在技术的宇宙中&#xff0c;我愿做永不停歇的探索者。 ✨ 用代码丈量世界&…

测试学习之——Pytest Day4

Pytest作为Python中功能强大且易于使用的测试框架&#xff0c;深受开发者喜爱。它不仅提供了简洁的测试编写方式&#xff0c;还通过丰富的配置选项、灵活的标记机制和强大的数据驱动能力&#xff0c;极大地提升了测试效率和可维护性。本文将深入探讨Pytest的配置意义与层级、常…

【软件系统架构】系列七:系统性能——路由器性能深入解析

目录 一、路由器的核心功能 二、路由器性能核心指标 1. 吞吐量&#xff08;Throughput&#xff09; 2. 并发连接数&#xff08;Session Capacity&#xff09; 3. 每秒连接数&#xff08;CPS&#xff0c;Connections Per Second&#xff09; 4. 转发延迟&#xff08;Laten…

【数据结构】第一讲 —— 概论

【数据结构】第一讲 —— 概论 文章目录【数据结构】第一讲 —— 概论1.1 基本概念和常用术语1.2 了解数据结构1. 数据结构2. 数据的逻辑结构3. 数据的物理结构&#xff08;存储结构&#xff09;4. 数据的运算1.3 算法的描述和分析1.3.1 算法的描述1.3.21.1 基本概念和常用术语…

全面解析MySQL(2)——CRUD基础

1.CreateCreate(创建)&#xff1a;添加新数据到数据库中#基础语法 insert into table_name (column1,column2,column3, ...) values (value1,value2,value3, ...);1.1 单行全列插入value中值的数量和顺序必须和column⼀致describe demo1; -----------------------------------…

某外企笔试总结——纯C语言

这里写自定义目录标题一、sizeof 计算&#xff08;32位环境&#xff09;二、简答题三、数据存储区域与可修改性四、字符串比较输出及原因五、数组指针运算输出六、字符串倒序代码错误排查七、下面程序可以把1维数组转为2维数组&#xff0c;然后调用 printArr2D 打印出数组内容&…