是否有可能告诉分支predictor的可能性有多大跟随分支? [英] Is it possible to tell the branch predictor how likely it is to follow the branch?
问题描述
只是要清楚,我不会对任何类型的便携性在这里,这样就配合我一定框中的任何解决办法是罚款。
基本上,我有一个if语句将在99%的时间计算为真,我试图竭力维持的性能每隔最后一个时钟,我可以发出一些编译器命令(使用GCC 4.1.2和86 ISA,如果它事项)告诉分支predictor,它应该缓存该分支?
是的。 http://kerneltrap.org/node/4705
的
__ builtin_expect
是一种方法,
海湾合作委员会(版本> = 2.96)报价为
程序员指示分支
prediction信息到
编译器。返回值
__ builtin_expect
是第一个参数(这只能是一个整数)
传递给它。
块引用>如果(__builtin_expect(X,0))
富(); [这]将表明我们并不指望调用'富',因为我们
期望`X'是零。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.
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?
解决方案Yes. http://kerneltrap.org/node/4705
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.
这篇关于是否有可能告诉分支predictor的可能性有多大跟随分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!