English 中文(简体)
使用_内建_ 期望_ 内建_ 内建_ 期望的指南
原标题:guidelines on using __builtin_expect

在有多个嵌套测试的 < code> if 内, 我该用什么来覆盖 gcc s 宏?

if((x<RADIUS && (forward?v<0:v>0)) || (x+RADIUS>dimensions[d] && (forward?v>0:v<0)))

我已尽我所能包罗万象:

#define likely(x)       __builtin_expect((x),1)
#define unlikely(x)     __builtin_expect((x),0)
if(unlikely(unlikely(unlikely(x<RADIUS) && likely(likely(forward)?likely(v<0):likely(v>0))) || unlikely(unlikely(x+RADIUS>dimensions[d]) && likely(likely(forward)?likely(v>0):likely(v<0)))))

我希望它只是一个过份的, 因为它几乎是 无法读取。

最佳回答

我不认为这里有错误的答案。 汇编者将使用您的提示来决定每个比较中的“ else” 案例的“ else” 案例; 这不仅是 C 代码, 而是在逻辑的 < em> 和 < em> 和 < em> 中, 信息越多越好 。

为了可以读的代码,我建议把它保留在大的东西上:每次如果声明一次,但是这并没有真正基于任何确凿的证据。

您是否考虑过使用 - fprofile-generate , 使用典型数据的代码运行代码, 然后用 < code>- fprofile- use 重建? 这样, 编译者就可以为所有这些案例建立自己的图片。 这是更便携的( 没有专门针对编译者的注释), 更易读, 以及更多未来的证据 。

问题回答

暂无回答




相关问题
gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared ...

Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Getting rid of pre-compiled headers

OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds. How does one get rid of Pre-compiled headers, ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

How to compile for Mac OS X 10.5

I d like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I ve tried -isysroot /Developer/SDKs/...

热门标签