likely/unlikely equivalent for MSVC

前端 未结 6 1578
醉话见心
醉话见心 2020-12-02 18:19

GCC compiler supports __builtin_expect statement that is used to define likely and unlikely macros.

eg.

#define likely(expr)    (__builtin_expect(!!(         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 18:35

    C++20 standard will include [[likely]] and [[unlikely]] branch prediction attributes.

    The latest revision of attribute proposal can be found from http://wg21.link/p0479

    The original attribute proposal can be found from http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0479r0.html

    Programmers should prefer PGO. Attributes can easily reduce performance if applied incorrectly or they later become incorrect when program changes.

提交回复
热议问题