Portable branch prediction hints

后端 未结 6 1852
谎友^
谎友^ 2020-12-05 02:07

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

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


        
6条回答
  •  眼角桃花
    2020-12-05 02:35

    Optimization is inherently a compiler thing, so you have to use compiler functionality to help it. The language itself doesn't care about (or mandate) optimizations.

    So the best you can do without compiler-specific extensions is organize your code in such a way where your compilers will "do the right thing" without help. But if you want to be sure, tap in to compiler extensions. (You might try abstracting them behind the preprocessor, so your code remains portable.)

提交回复
热议问题