是否可以告诉分支预测器跟随分支的可能性有多大? [英] Is it possible to tell the branch predictor how likely it is to follow the branch?

查看:33
本文介绍了是否可以告诉分支预测器跟随分支的可能性有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了清楚起见,我不会在这里寻求任何形式的可移植性,因此任何将我绑定到某个盒子的解决方案都可以.

Just to make it clear, I'm not going for any sort of portability here, so any solutions that will tie me to a certain box is fine.

基本上,我有一个 if 语句,该语句在 99% 的时间评估为真,并且我试图勉强维持每一个性能时钟,我可以发出某种编译器命令吗(使用 GCC 4.1.2 和 x86ISA,如果重要的话)告诉分支预测器它应该为那个分支缓存?

Basically, I have an if statement that will 99% of the time evaluate to true, and am trying to eke out every last clock of performance, can I issue some sort of compiler command (using GCC 4.1.2 and the x86 ISA, if it matters) to tell the branch predictor that it should cache for that branch?

推荐答案

是的.http://kerneltrap.org/node/4705

__builtin_expect 是一种方法gcc(版本 >= 2.96)提供程序员指示分支预测信息编译器.的返回值__builtin_expect 是第一个参数(只能是整数)传递给它.

The __builtin_expect is a method that gcc (versions >= 2.96) offer for programmers to indicate branch prediction information to the compiler. The return value of __builtin_expect is the first argument (which could only be an integer) passed to it.

if (__builtin_expect (x, 0))
                foo ();

     [This] would indicate that we do not expect to call `foo', since we
     expect `x' to be zero. 

这篇关于是否可以告诉分支预测器跟随分支的可能性有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆