Use saturating counters for branch taken counters in `_POP_JUMP_IF_FALSE` and similar instructions.
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Each conditional branch instruction contains a 16 bit field for recording the direction of the last 16 jumps.
uint16_t *branches;
uint16_t val = *branches;
val = (val << 1) | direction;
*branches =val;
This tells the direction of the last 16 branches.
When recording traces for the JIT, 16 branches is not a lot of information to guide region selection.
Instead, we could record the count of the two directions instead using a pair of saturating 8 bit counters.
uint8_t branches[2];
branches[direction] += (branches[direction] != 255);
Which is only one extra ALU instruction for most C compilers, and no extra memory accesses.
With a JIT warmup of up 500, we can get precise numbers of the branches taken.
With a warmup of a 1000, the saturating counters can still distinguish between branches that are rarely taken and those which are more balanced.
For example, if a branch switches direction every 20 times, the current counter might show a perfectly biased branch, but the saturating counter approach will show that the branch is roughly balanced.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 _POP_JUMP_IF_FALSE 指令和类似的条件分支实现开始,然后追踪它们的分支数据是如何为 JIT 跟踪记录的。当方向计数使用两个饱和计数器、上限为 255,并在不改变指令行为的情况下提供所提议的预热信息时,这项更改就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- compilers, performance
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100