Index: source/lib/code_annotation.h =================================================================== --- source/lib/code_annotation.h +++ source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 Wildfire Games. +/* Copyright (c) 2023 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -413,4 +413,14 @@ // TODO: Maybe use __fallthrough for the MSVC code analyzer (also figure out if we need to add some switch when switching to a newer version of VS that supports [[fallthrough]] #endif +// Using of [[likely]]/[[unlikely]] should be avoided in a regular code. +// Ideally we should use PGO. +#if CLANG_VERSION || GCC_VERSION +#define IF_LIKELY(EXPRESSION) if (__builtin_expect(static_cast(EXPRESSION), 1)) +#define IF_UNLIKELY(EXPRESSION) if (__builtin_expect(static_cast(EXPRESSION), 0)) +#else +#define IF_LIKELY(EXPRESSION) if (EXPRESSION) +#define IF_UNLIKELY(EXPRESSION) if (EXPRESSION) +#endif + #endif // #ifndef INCLUDED_CODE_ANNOTATION Index: source/lib/debug.h =================================================================== --- source/lib/debug.h +++ source/lib/debug.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2022 Wildfire Games. +/* Copyright (C) 2023 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -290,9 +290,9 @@ #define ENSURE(expr)\ do\ {\ - static atomic_bool suppress__;\ - if(!(expr))\ + IF_UNLIKELY(!(expr))\ {\ + static atomic_bool suppress__;\ switch(debug_OnAssertionFailure(WIDEN(#expr), &suppress__, WIDEN(__FILE__), __LINE__, __func__))\ {\ case ER_CONTINUE:\