From 59c88f846d1dcd901a4420651aedf27816618923 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 24 Feb 2021 11:14:44 -0300 Subject: Broadening the use of branch hints More uses of macros 'likely'/'unlikely' (renamed to 'l_likely'/'l_unlikely'), both in range (extended to the libraries) and in scope (extended to hooks, stack growth). --- luaconf.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'luaconf.h') diff --git a/luaconf.h b/luaconf.h index a44858c4..ae73e2fd 100644 --- a/luaconf.h +++ b/luaconf.h @@ -660,6 +660,26 @@ #define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) #endif + +/* +** macros to improve jump prediction, used mostly for error handling +** and debug facilities. +*/ +#if (defined(LUA_CORE) || defined(LUA_LIB)) && !defined(l_likely) + +#include +#if defined(__GNUC__) +#define l_likely(x) (__builtin_expect(((x) != 0), 1)) +#define l_unlikely(x) (__builtin_expect(((x) != 0), 0)) +#else +#define l_likely(x) (x) +#define l_unlikely(x) (x) +#endif + +#endif + + + /* }================================================================== */ -- cgit v1.2.3-55-g6feb