【发布时间】:2010-11-29 06:15:15
【问题描述】:
GCC 编译器支持 __builtin_expect 语句,用于定义可能和不可能的宏。
例如。
#define likely(expr) (__builtin_expect(!!(expr), 1))
#define unlikely(expr) (__builtin_expect(!!(expr), 0))
是否有 Microsoft Visual C 编译器的等效语句或等效语句?
【问题讨论】:
-
投票以在VS feedback 网站上添加此功能!
-
请注意,Microsoft 表示他们不喜欢 here 和 here 的此类优化。将来似乎不太可能(没有双关语)添加它。
We want people to use profile guided optimizations instead of annotating their code by hand. Seethis blog postfor more info. Profile counts don't lie (or rather, they lie much less than users do). -
@jrh 所有这些链接现在都已失效。另一个答案:*The argument for not implementing this feature is that it is non-standard. MSVC is pushing to implement standards features, not extend the language in ways that are incompatible with other compilers。 (我们过去做的太多了。)有一个标准提案来引入这样的属性。当它标准化后,我们将执行它:open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0627r0.pdf
-
@phuclv 另请参阅:this meta post 连接链接。
标签: visual-studio gcc optimization compiler-construction likely-unlikely