便携式分支prediction提示 [英] Portable branch prediction hints

查看:232
本文介绍了便携式分支prediction提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有这样做的分支prediction暗示任何可移植的方法?请看下面的例子:

Is there any portable way of doing branch prediction hints? Consider the following example:

  if (unlikely_condition) {
    /* ..A.. */
  } else {
    /* ..B.. */
  }

这是不是做任何的不同:

Is this any different than doing:

  if (!unlikely_condition) {
    /* ..B.. */
  } else {
    /* ..A.. */
  }

或者是使用编译器的具体线索的唯一途径? (例如__builtin_expect在GCC)

Or is the only way to use compiler specific hints? (e.g. __builtin_expect on GCC)

将编译器治疗如果情况的任何不同的基于条件的顺序?

Will compilers treat the if conditions any differently based on the ordering of the conditions?

推荐答案

的规范的方式做静态分支prediction是如果是predicted不-branched(即执行每如果子句,而不是其他),以及循环和落后 - 转到 s的拍摄。所以,如果你希望静态prediction是显著不要放在通常情况下别人。四处逛逛未获认购的循环是不容易;我从来没有尝试过但我想将它的一个其他条款应该工作pretty可移植性。

The canonical way to do static branch prediction is that if is predicted not-branched (i.e. every if clause is executed, not else), and loops and backward-gotos are taken. So, don't put the common case in else if you expect static prediction to be significant. Getting around an untaken loop isn't as easy; I've never tried but I suppose putting it an an else clause should work pretty portably.

许多编译器支持某种形式的的#pragma解开,但它仍需要以某种#如果来保护其他的编译器。

Many compilers support some form of #pragma unroll, but it will still be necessary to guard it with some kind of #if to protect other compilers.

分公司prediction提示理论上可前preSS的如何将一个程序的流量控制图,并安排可执行的内存基本块......所以有能恩$ P $各种事物的完整描述PSS,大多数不会非常便于携带。

Branch prediction hints can theoretically express a complete description of how to transform a program's flow-control graph and arrange the basic blocks in executable memory… so there are a variety of things to express, and most won't be very portable.

由于GNU建议文档 __ builtin_expect 中,档案导引优化优于提示,更省力。

As GNU recommends in the documentation for __builtin_expect, profile-guided optimization is superior to hints, and with less effort.

这篇关于便携式分支prediction提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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