1/* Compiler.h : Compiler specific defines and pragmas 22023-04-02 : Igor Pavlov : Public domain */ 3 4#ifndef ZIP7_INC_COMPILER_H 5#define ZIP7_INC_COMPILER_H 6 7#if defined(__clang__) 8# define Z7_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) 9#endif 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__) 16#endif 17 18#ifdef _MSC_VER 19#if !defined(__clang__) && !defined(__GNUC__) 20#define Z7_MSC_VER_ORIGINAL _MSC_VER 21#endif 22#endif 23 24#if defined(__MINGW32__) || defined(__MINGW64__) 25#define Z7_MINGW 26#endif 27 28// #pragma GCC diagnostic ignored "-Wunknown-pragmas" 29 30#ifdef __clang__ 31// padding size of '' with 4 bytes to alignment boundary 32#pragma GCC diagnostic ignored "-Wpadded" 33#endif 34 35 36#ifdef _MSC_VER 37 38 #ifdef UNDER_CE 39 #define RPC_NO_WINDOWS_H 40 /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ 41 #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union 42 #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int 43 #endif 44 45#if defined(_MSC_VER) && _MSC_VER >= 1800 46#pragma warning(disable : 4464) // relative include path contains '..' 47#endif 48 49// == 1200 : -O1 : for __forceinline 50// >= 1900 : -O1 : for printf 51#pragma warning(disable : 4710) // function not inlined 52 53#if _MSC_VER < 1900 54// winnt.h: 'Int64ShllMod32' 55#pragma warning(disable : 4514) // unreferenced inline function has been removed 56#endif 57 58#if _MSC_VER < 1300 59// #pragma warning(disable : 4702) // unreachable code 60// Bra.c : -O1: 61#pragma warning(disable : 4714) // function marked as __forceinline not inlined 62#endif 63 64/* 65#if _MSC_VER > 1400 && _MSC_VER <= 1900 66// strcat: This function or variable may be unsafe 67// sysinfoapi.h: kit10: GetVersion was declared deprecated 68#pragma warning(disable : 4996) 69#endif 70*/ 71 72#if _MSC_VER > 1200 73// -Wall warnings 74 75#pragma warning(disable : 4711) // function selected for automatic inline expansion 76#pragma warning(disable : 4820) // '2' bytes padding added after data member 77 78#if _MSC_VER >= 1400 && _MSC_VER < 1920 79// 1400: string.h: _DBG_MEMCPY_INLINE_ 80// 1600 - 191x : smmintrin.h __cplusplus' 81// is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' 82#pragma warning(disable : 4668) 83 84// 1400 - 1600 : WinDef.h : 'FARPROC' : 85// 1900 - 191x : immintrin.h: _readfsbase_u32 86// no function prototype given : converting '()' to '(void)' 87#pragma warning(disable : 4255) 88#endif 89 90#if _MSC_VER >= 1914 91// Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified 92#pragma warning(disable : 5045) 93#endif 94 95#endif // _MSC_VER > 1200 96#endif // _MSC_VER 97 98 99#if defined(__clang__) && (__clang_major__ >= 4) 100 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \ 101 _Pragma("clang loop unroll(disable)") \ 102 _Pragma("clang loop vectorize(disable)") 103 #define Z7_ATTRIB_NO_VECTORIZE 104#elif defined(__GNUC__) && (__GNUC__ >= 5) 105 #define Z7_ATTRIB_NO_VECTORIZE __attribute__((optimize("no-tree-vectorize"))) 106 // __attribute__((optimize("no-unroll-loops"))); 107 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE 108#elif defined(_MSC_VER) && (_MSC_VER >= 1920) 109 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE \ 110 _Pragma("loop( no_vector )") 111 #define Z7_ATTRIB_NO_VECTORIZE 112#else 113 #define Z7_PRAGMA_OPT_DISABLE_LOOP_UNROLL_VECTORIZE 114 #define Z7_ATTRIB_NO_VECTORIZE 115#endif 116 117#if defined(MY_CPU_X86_OR_AMD64) && ( \ 118 defined(__clang__) && (__clang_major__ >= 4) \ 119 || defined(__GNUC__) && (__GNUC__ >= 5)) 120 #define Z7_ATTRIB_NO_SSE __attribute__((__target__("no-sse"))) 121#else 122 #define Z7_ATTRIB_NO_SSE 123#endif 124 125#define Z7_ATTRIB_NO_VECTOR \ 126 Z7_ATTRIB_NO_VECTORIZE \ 127 Z7_ATTRIB_NO_SSE 128 129 130#if defined(__clang__) && (__clang_major__ >= 8) \ 131 || defined(__GNUC__) && (__GNUC__ >= 1000) \ 132 /* || defined(_MSC_VER) && (_MSC_VER >= 1920) */ 133 // GCC is not good for __builtin_expect() 134 #define Z7_LIKELY(x) (__builtin_expect((x), 1)) 135 #define Z7_UNLIKELY(x) (__builtin_expect((x), 0)) 136 // #define Z7_unlikely [[unlikely]] 137 // #define Z7_likely [[likely]] 138#else 139 #define Z7_LIKELY(x) (x) 140 #define Z7_UNLIKELY(x) (x) 141 // #define Z7_likely 142#endif 143 144 145#if (defined(Z7_CLANG_VERSION) && (Z7_CLANG_VERSION >= 36000)) 146#define Z7_DIAGNOSCTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER \ 147 _Pragma("GCC diagnostic push") \ 148 _Pragma("GCC diagnostic ignored \"-Wreserved-macro-identifier\"") 149#define Z7_DIAGNOSCTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER \ 150 _Pragma("GCC diagnostic pop") 151#else 152#define Z7_DIAGNOSCTIC_IGNORE_BEGIN_RESERVED_MACRO_IDENTIFIER 153#define Z7_DIAGNOSCTIC_IGNORE_END_RESERVED_MACRO_IDENTIFIER 154#endif 155 156#define UNUSED_VAR(x) (void)x; 157/* #define UNUSED_VAR(x) x=x; */ 158 159#endif 160