一个错误的条件分支预测成本多少?

huangapple go评论81阅读模式
英文:

How much does a mispredicted conditional branch cost?

问题

On x86-64,无论微架构如何,以及ARM64设备上,错误预测的条件分支需要多少个时钟周期?并且我想我还应该询问成功预测的分支(是否采取/不采取)的数据是多少?我可以尝试在Agner Fog的表格中找到这些信息,但我对ARM也很感兴趣。

从处理器本身获取这些数据是否有相对简单的方法?

英文:

On x86-64 whatever micro architecture and ARM64 devices, how many clock cycles does a mispredicted conditional branch cost? And I suppose I should also ask what the figure is for a successfully predicted branch taken/not taken ? I can try and find this in Agner Fog’s tables but I’m interested in ARM equally.

Is there a reasonably easy way of getting this data out of the processor itself?

答案1

得分: 3

Mispredicted branches just stall the front-end, not the entire pipeline. So the cost in terms of overall performance impact depends on the code. If it was bottlenecked purely on the front-end, losing 15 to 19 cycles of front-end throughput costs that many cycles of total time, but many other programs can somewhat hide the bubble since they have other work in flight to still be working on.

See:

It's something you can microbenchmark, but it's somewhat tricky to construct such a benchmark. 7-CPU has numbers for many CPUs, e.g.:

  • Cortex A76 is reported as a 14-cycle penalty.
  • Skylake: 16.5 cycles average (if mOp cache hit) or 19-20 cycles (if mOp cache miss). The uop-cache effectively shortens the pipeline, fewer stages between re-steer and having uops ready to issue from the front-end into the back-end.
  • Cortex A53: 7 cycles. Much shorter recovery time, as expected for a simpler in-order pipeline.

I suspect those numbers are from vendor manuals, unless 7-cpu has a standard benchmark they use.

Also, yes, Agner Fog attempted to microbenchmark this for many x86 CPUs, but hard numbers are hard to measure; he reports that measurements were pretty noisy on some CPUs. e.g. for Haswell/Broadwell he writes in his microarch PDF:

There may be a difference in branch misprediction penalty between the three sources of µops, but I have not been able to verify such a difference because the variance in the measurements is high. The measured misprediction penalty varies between 16 and 20 clock cycles in all three cases.

英文:

Mispredicted branches just stall the front-end, not the entire pipeline. So the cost in terms of overall performance impact depends on the code. If it was bottlenecked purely on the front-end, losing 15 to 19 cycles of front-end throughput costs that many cycles of total time, but many other programs can somewhat hide the bubble since they have other work in flight to still be working on.

See


It's something you can microbenchmark, but it's somewhat tricky to construct such a benchmark. https://www.7-cpu.com/ has numbers for many CPUs, e.g.

  • Cortex A76 is reported as a 14-cycle penalty,
  • Skylake 16.5 cycles average (if mOp cache hit) or 19-20 cycles (if mOp cache miss). The uop-cache effectively shortens the pipeline, fewer stages between re-steer and having uops ready to issue from the front-end into the back-end.
  • Cortex A53: 7 cycles. Much shorter recovery time, as expected for a simpler in-order pipeline.

I suspect those numbers are from vendor manuals, unless 7-cpu has a standard benchmark they use.

Also yes, Agner Fog attempted to microbenchmark this for many x86 CPUs, but hard numbers are hard to measure; he reports that measurements were pretty noisy on some CPUs. e.g. for Haswell/Broadwell he writes in his microarch PDF

> There may be a difference in branch misprediction penalty between the three sources of
µops, but I have not been able to verify such a difference because the variance in the
measurements is high. The measured misprediction penalty varies between 16 and 20 clock
cycles in all three cases.

huangapple
  • 本文由 发表于 2023年8月5日 05:38:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76839219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定