1 /* Compiler.h : Compiler specific defines and pragmas
2 2024-01-22 : Igor Pavlov : Public domain */
4 #ifndef ZIP7_INC_COMPILER_H
5 #define ZIP7_INC_COMPILER_H
8 # define Z7_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
10 #if defined(__clang__) && defined(__apple_build_version__)
11 # define Z7_APPLE_CLANG_VERSION Z7_CLANG_VERSION
12 #elif defined(__clang__)
13 # define Z7_LLVM_CLANG_VERSION Z7_CLANG_VERSION
14 #elif defined(__GNUC__)
15 # define Z7_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
19 #if !defined(__clang__) && !defined(__GNUC__)
20 #define Z7_MSC_VER_ORIGINAL _MSC_VER
24 #if defined(__MINGW32__) || defined(__MINGW64__)
28 #if defined(__LCC__) && (defined(__MCST__) || defined(__e2k__))
30 #define Z7_MCST_LCC_VERSION (__LCC__ * 100 + __LCC_MINOR__)
34 #if defined(__AVX2__) \
35 || defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40900) \
36 || defined(Z7_APPLE_CLANG_VERSION) && (Z7_APPLE_CLANG_VERSION >= 40600) \
37 || defined(Z7_LLVM_CLANG_VERSION) && (Z7_LLVM_CLANG_VERSION >= 30100) \
38 || defined(Z7_MSC_VER_ORIGINAL) && (Z7_MSC_VER_ORIGINAL >= 1800) \
39 || defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1400)
40 #define Z7_COMPILER_AVX2_SUPPORTED
45 // #pragma GCC diagnostic ignored "-Wunknown-pragmas"
48 // padding size of '' with 4 bytes to alignment boundary
49 #pragma GCC diagnostic ignored "-Wpadded"
51 #if defined(Z7_LLVM_CLANG_VERSION) && (__clang_major__ == 13) \
52 && defined(__FreeBSD__)
54 #pragma GCC diagnostic ignored "-Wexcess-padding"
57 #if __clang_major__ >= 16
58 #pragma GCC diagnostic ignored "-Wunsafe-buffer-usage"
61 #if __clang_major__ == 13
62 #if defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 16)
64 #pragma GCC diagnostic ignored "-Wcapability-to-integer-cast"
68 #if __clang_major__ == 13
70 #pragma GCC diagnostic ignored "-Wreserved-identifier"
75 #if defined(_WIN32) && defined(__clang__) && __clang_major__ >= 16
76 // #pragma GCC diagnostic ignored "-Wcast-function-type-strict"
77 #define Z7_DIAGNOSTIC_IGNORE_CAST_FUNCTION \
78 _Pragma("GCC diagnostic ignored \"-Wcast-function-type-strict\"")
80 #define Z7_DIAGNOSTIC_IGNORE_CAST_FUNCTION
83 typedef void (*Z7_void_Function)(void);
84 #if defined(__clang__) || defined(__GNUC__)
85 #define Z7_CAST_FUNC_C (Z7_void_Function)
86 #elif defined(_MSC_VER) && _MSC_VER > 1920
87 #define Z7_CAST_FUNC_C (void *)
88 // #pragma warning(disable : 4191) // 'type cast': unsafe conversion from 'FARPROC' to 'void (__cdecl *)()'
90 #define Z7_CAST_FUNC_C
93 #if (defined(__GNUC__) && (__GNUC__ >= 8)) || defined(__clang__)
94 // #pragma GCC diagnostic ignored "-Wcast-function-type"
98 #if defined(Z7_GCC_VERSION) && (Z7_GCC_VERSION >= 40000) && (Z7_GCC_VERSION < 70000)
99 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
107 #define RPC_NO_WINDOWS_H
108 /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
109 #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
110 #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
113 #if defined(_MSC_VER) && _MSC_VER >= 1800
114 #pragma warning(disable : 4464) // relative include path contains '..'
117 // == 1200 : -O1 : for __forceinline
118 // >= 1900 : -O1 : for printf
119 #pragma warning(disable : 4710) // function not inlined
122 // winnt.h: 'Int64ShllMod32'
123 #pragma warning(disable : 4514) // unreferenced inline function has been removed
127 // #pragma warning(disable : 4702) // unreachable code
129 #pragma warning(disable : 4714) // function marked as __forceinline not inlined
133 #if _MSC_VER > 1400 && _MSC_VER <= 1900
134 // strcat: This function or variable may be unsafe
135 // sysinfoapi.h: kit10: GetVersion was declared deprecated
136 #pragma warning(disable : 4996)
143 #pragma warning(disable : 4711) // function selected for automatic inline expansion
144 #pragma warning(disable : 4820) // '2' bytes padding added after data member
146 #if _MSC_VER >= 1400 && _MSC_VER < 1920
147 // 1400: string.h: _DBG_MEMCPY_INLINE_
148 // 1600 - 191x : smmintrin.h __cplusplus'
149 // is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
150 #pragma warning(disable : 4668)
152 // 1400 - 1600 : WinDef.h : 'FARPROC' :
153 // 1900 - 191x : immintrin.h: _readfsbase_u32
154 // no function prototype given : converting '()' to '(void)'
155 #pragma warning(disable : 4255)
159 // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
160 #pragma warning(disable : 5045)
163 #endif // _MSC_VER > 1200
167 #if defined(__clang__) && (__clang_major__ >= 4)
168 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \
169 _Pragma("clang loop unroll(disable)") \
170 _Pragma("clang loop vectorize(disable)")
171 #define Z7_ATTRIB_NO_VECTORIZE
172 #elif defined(__GNUC__) && (__GNUC__ >= 5) \
173 && (!defined(Z7_MCST_LCC_VERSION) || (Z7_MCST_LCC_VERSION >= 12610))
174 #define Z7_ATTRIB_NO_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
175 // __attribute__((optimize("no-unroll-loops")));
176 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
177 #elif defined(_MSC_VER) && (_MSC_VER >= 1920)
178 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \
179 _Pragma("loop( no_vector )")
180 #define Z7_ATTRIB_NO_VECTORIZE
182 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE
183 #define Z7_ATTRIB_NO_VECTORIZE
186 #if defined(MY_CPU_X86_OR_AMD64) && ( \
187 defined(__clang__) && (__clang_major__ >= 4) \
188 || defined(__GNUC__) && (__GNUC__ >= 5))
189 #define Z7_ATTRIB_NO_SSE __attribute__((__target__("no-sse")))
191 #define Z7_ATTRIB_NO_SSE
194 #define Z7_ATTRIB_NO_VECTOR \
195 Z7_ATTRIB_NO_VECTORIZE \
199 #if defined(__clang__) && (__clang_major__ >= 8) \
200 || defined(__GNUC__) && (__GNUC__ >= 1000) \
201 /* || defined(_MSC_VER) && (_MSC_VER >= 1920) */
202 // GCC is not good for __builtin_expect()
203 #define Z7_LIKELY(x) (__builtin_expect((x), 1))
204 #define Z7_UNLIKELY(x) (__builtin_expect((x), 0))
205 // #define Z7_unlikely [[unlikely]]
206 // #define Z7_likely [[likely]]
208 #define Z7_LIKELY(x) (x)
209 #define Z7_UNLIKELY(x) (x)
214 #if (defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 30600))
216 #if (Z7_CLANG_VERSION < 130000)
217 #define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER \
218 _Pragma("GCC diagnostic push") \
219 _Pragma("GCC diagnostic ignored \"-Wreserved-id-macro\"")
221 #define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER \
222 _Pragma("GCC diagnostic push") \
223 _Pragma("GCC diagnostic ignored \"-Wreserved-macro-identifier\"")
226 #define Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER \
227 _Pragma("GCC diagnostic pop")
229 #define Z7_DIAGNOSTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER
230 #define Z7_DIAGNOSTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER
233 #define UNUSED_VAR(x) (void)x;
234 /* #define UNUSED_VAR(x) x=x; */