Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions lib/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,26 @@
#endif


/* target attribute */
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
/* target attribute
*
* This condition must stay in sync with the one DYNAMIC_BMI2 uses in
* portability_macros.h. clang in MSVC-compatible mode (clang-cl) supports
* __attribute__((__target__)) but does not define __GNUC__, so testing
* __GNUC__ alone silently expands this to nothing while DYNAMIC_BMI2
* remains enabled -- the runtime dispatch then calls _bmi2 entry points
* that were compiled with no BMI2 at all.
*/
#if defined(__has_attribute)
# if __has_attribute(__target__)
# define ZSTD_HAS_TARGET_ATTRIBUTE 1
# endif
#endif
#if !defined(ZSTD_HAS_TARGET_ATTRIBUTE) && \
(defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__))
# define ZSTD_HAS_TARGET_ATTRIBUTE 1
#endif

#if defined(ZSTD_HAS_TARGET_ATTRIBUTE)
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
#else
# define TARGET_ATTRIBUTE(target)
Expand Down Expand Up @@ -183,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
Expand Down