2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
8 * You may select, at your option, one of the above-listed licenses.
11 #ifndef ZSTD_COMPILER_H
12 #define ZSTD_COMPILER_H
14 /*-*******************************************************
16 *********************************************************/
18 #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
19 # define INLINE_KEYWORD inline
21 # define INLINE_KEYWORD
25 # define FORCE_INLINE_ATTR __attribute__((always_inline))
26 #elif defined(_MSC_VER)
27 # define FORCE_INLINE_ATTR __forceinline
29 # define FORCE_INLINE_ATTR
33 * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
34 * parameters. They must be inlined for the compiler to elimininate the constant
37 #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
39 * HINT_INLINE is used to help the compiler generate better code. It is *not*
40 * used for "templates", so it can be tweaked based on the compilers
43 * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the
44 * always_inline attribute.
46 * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline
49 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
50 # define HINT_INLINE static INLINE_KEYWORD
52 # define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
55 /* force no inlining */
57 # define FORCE_NOINLINE static __declspec(noinline)
60 # define FORCE_NOINLINE static __attribute__((__noinline__))
62 # define FORCE_NOINLINE static
67 #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */
68 # include <mmintrin.h> /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */
69 # define PREFETCH(ptr) _mm_prefetch((const char*)ptr, _MM_HINT_T0)
70 #elif defined(__GNUC__)
71 # define PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0)
73 # define PREFETCH(ptr) /* disabled */
76 /* disable warnings */
77 #ifdef _MSC_VER /* Visual Studio */
78 # include <intrin.h> /* For Visual 2005 */
79 # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
80 # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
81 # pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */
82 # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
83 # pragma warning(disable : 4324) /* disable: C4324: padded structure */
86 #endif /* ZSTD_COMPILER_H */