compiler: honour LIKELY/UNLIKELY under clang-cl

Same __GNUC__ gate as TARGET_ATTRIBUTE. clang-cl supports
__builtin_expect, so test for it with __has_builtin and keep __GNUC__
as a fallback. Without this, every branch hint in the library is
discarded under clang-cl.
This commit is contained in:
Matevz Kovacic 2026-08-06 08:49:52 +02:00
parent b81b64a961
commit 4afc10ef28

View file

@ -201,7 +201,16 @@
* If you can remove a LIKELY/UNLIKELY annotation without speed changes in gcc
* and clang, please do.
*/
#if defined(__GNUC__)
#if defined(__has_builtin)
# if __has_builtin(__builtin_expect)
# define ZSTD_HAS_BUILTIN_EXPECT 1
# endif
#endif
#if !defined(ZSTD_HAS_BUILTIN_EXPECT) && defined(__GNUC__)
# define ZSTD_HAS_BUILTIN_EXPECT 1
#endif
#if defined(ZSTD_HAS_BUILTIN_EXPECT)
#define LIKELY(x) (__builtin_expect((x), 1))
#define UNLIKELY(x) (__builtin_expect((x), 0))
#else