lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi

In one of my routine I want to mark one conditional _expression_ as "unlikely".

I checked Lua 5.3 and Lua 5.4 codebase. I found this usage in Lua 5.4, file llimits.h

#if defined(__GNUC__)
  #define likely(x) (__builtin_expect(((x) != 0), 1))
  #define unlikely(x) (__builtin_expect(((x) != 0), 0))
#else
  #define likely(x) (x)
  #define unlikely(x) (x)
#endif


I am looking on the web about different compilers support... and I found Hedley:

Hedley is a single C/C++ header you can include in your project to enable compiler-specific features while retaining compatibility with all compilers. It contains dozens of macros to help make your code easier to use, harder to misuse, safer, faster, and more portable.

You can safely include Hedley in your public API, and it works with virtually any C or C++ compiler.


I think it is very promosing; take a look for example at their implementation of likely:
https://nemequ.github.io/hedley/api-reference.html#HEDLEY_LIKELY

M