Advertisement
Guest User

ALMOST_ALWAYS/ALMOST_NEVER

a guest
Nov 23rd, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. // ALMOST_ALWAYS/ALMOST_NEVER (likely/unlikely early support)
  2. #ifdef __has_cpp_attribute
  3.     #if __has_cpp_attribute(likely)
  4.         #define ALMOST_ALWAYS(expr) (expr) [[likely]]
  5.     #endif
  6.     #if __has_cpp_attribute(unlikely)
  7.         #define ALMOST_NEVER(expr) (expr) [[unlikely]]
  8.     #endif
  9. #endif
  10. #ifndef ALMOST_ALWAYS
  11.     #if defined(__builtin_expect)
  12.         #define ALMOST_ALWAYS(expr) (__builtin_expect(static_cast<bool>(expr), 1))
  13.     #else
  14.         #define ALMOST_ALWAYS(expr) (expr)
  15.     #endif
  16. #endif
  17. #ifndef ALMOST_NEVER
  18.     #if defined(__builtin_expect)
  19.         #define ALMOST_NEVER(expr) (__builtin_expect(static_cast<bool>(expr), 0))
  20.     #else
  21.         #define ALMOST_NEVER(expr) (expr)
  22.     #endif
  23. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement