1 /* 2 * Copyright 2006 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 // IWYU pragma: private, include "SkTypes.h" 9 10 #ifndef SkPreConfig_DEFINED 11 #define SkPreConfig_DEFINED 12 13 // Allows embedders that want to disable macros that take arguments to just 14 // define that symbol to be one of these 15 #define SK_NOTHING_ARG1(arg1) 16 #define SK_NOTHING_ARG2(arg1, arg2) 17 #define SK_NOTHING_ARG3(arg1, arg2, arg3) 18 19 ////////////////////////////////////////////////////////////////////// 20 21 #if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \ 22 !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) 23 24 #ifdef __APPLE__ 25 #include "TargetConditionals.h" 26 #endif 27 28 #if defined(_WIN32) || defined(__SYMBIAN32__) 29 #define SK_BUILD_FOR_WIN 30 #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \ 31 defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \ 32 defined(__DragonFly__) || defined(__Fuchsia__) || \ 33 defined(__GLIBC__) || defined(__GNU__) || defined(__unix__) 34 #define SK_BUILD_FOR_UNIX 35 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR 36 #define SK_BUILD_FOR_IOS 37 #else 38 #define SK_BUILD_FOR_MAC 39 #endif 40 41 #endif 42 43 ////////////////////////////////////////////////////////////////////// 44 45 #if defined(SK_BUILD_FOR_WIN) && !defined(__clang__) 46 #if !defined(SK_RESTRICT) 47 #define SK_RESTRICT __restrict 48 #endif 49 #if !defined(SK_WARN_UNUSED_RESULT) 50 #define SK_WARN_UNUSED_RESULT 51 #endif 52 #endif 53 54 #if !defined(SK_RESTRICT) 55 #define SK_RESTRICT __restrict__ 56 #endif 57 58 #if !defined(SK_WARN_UNUSED_RESULT) 59 #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 60 #endif 61 62 ////////////////////////////////////////////////////////////////////// 63 64 #if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN) 65 #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 66 #define SK_CPU_BENDIAN 67 #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 68 #define SK_CPU_LENDIAN 69 #elif defined(__sparc) || defined(__sparc__) || \ 70 defined(_POWER) || defined(__powerpc__) || \ 71 defined(__ppc__) || defined(__hppa) || \ 72 defined(__PPC__) || defined(__PPC64__) || \ 73 defined(_MIPSEB) || defined(__ARMEB__) || \ 74 defined(__s390__) || \ 75 (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ 76 (defined(__ia64) && defined(__BIG_ENDIAN__)) 77 #define SK_CPU_BENDIAN 78 #else 79 #define SK_CPU_LENDIAN 80 #endif 81 #endif 82 83 ////////////////////////////////////////////////////////////////////// 84 85 #if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) 86 #define SK_CPU_X86 1 87 #endif 88 89 /** 90 * SK_CPU_SSE_LEVEL 91 * 92 * If defined, SK_CPU_SSE_LEVEL should be set to the highest supported level. 93 * On non-intel CPU this should be undefined. 94 */ 95 96 #define SK_CPU_SSE_LEVEL_SSE1 10 97 #define SK_CPU_SSE_LEVEL_SSE2 20 98 #define SK_CPU_SSE_LEVEL_SSE3 30 99 #define SK_CPU_SSE_LEVEL_SSSE3 31 100 #define SK_CPU_SSE_LEVEL_SSE41 41 101 #define SK_CPU_SSE_LEVEL_SSE42 42 102 #define SK_CPU_SSE_LEVEL_AVX 51 103 #define SK_CPU_SSE_LEVEL_AVX2 52 104 #define SK_CPU_SSE_LEVEL_AVX512 60 105 106 // When targetting iOS and using gyp to generate the build files, it is not 107 // possible to select files to build depending on the architecture (i.e. it 108 // is not possible to use hand optimized assembly implementation). In that 109 // configuration SK_BUILD_NO_OPTS is defined. Remove optimisation then. 110 #ifdef SK_BUILD_NO_OPTS 111 #define SK_CPU_SSE_LEVEL 0 112 #endif 113 114 // Are we in GCC/Clang? 115 #ifndef SK_CPU_SSE_LEVEL 116 // These checks must be done in descending order to ensure we set the highest 117 // available SSE level. 118 #if defined(__AVX512F__) 119 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX512 120 #elif defined(__AVX2__) 121 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 122 #elif defined(__AVX__) 123 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX 124 #elif defined(__SSE4_2__) 125 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42 126 #elif defined(__SSE4_1__) 127 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41 128 #elif defined(__SSSE3__) 129 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3 130 #elif defined(__SSE3__) 131 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3 132 #elif defined(__SSE2__) 133 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 134 #endif 135 #endif 136 137 // Are we in VisualStudio? 138 #ifndef SK_CPU_SSE_LEVEL 139 // These checks must be done in descending order to ensure we set the highest 140 // available SSE level. 64-bit intel guarantees at least SSE2 support. 141 #if defined(__AVX2__) 142 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2 143 #elif defined(__AVX__) 144 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX 145 #elif defined(_M_X64) || defined(_M_AMD64) 146 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 147 #elif defined(_M_IX86_FP) 148 #if _M_IX86_FP >= 2 149 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2 150 #elif _M_IX86_FP == 1 151 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1 152 #endif 153 #endif 154 #endif 155 156 ////////////////////////////////////////////////////////////////////// 157 // ARM defines 158 159 #if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR) 160 #define SK_CPU_ARM32 161 #elif defined(__aarch64__) && !defined(SK_BUILD_NO_OPTS) 162 #define SK_CPU_ARM64 163 #endif 164 165 // All 64-bit ARM chips have NEON. Many 32-bit ARM chips do too. 166 #if !defined(SK_ARM_HAS_NEON) && !defined(SK_BUILD_NO_OPTS) && defined(__ARM_NEON) 167 #define SK_ARM_HAS_NEON 168 #endif 169 170 // Really this __APPLE__ check shouldn't be necessary, but it seems that Apple's Clang defines 171 // __ARM_FEATURE_CRC32 for -arch arm64, even though their chips don't support those instructions! 172 #if defined(__ARM_FEATURE_CRC32) && !defined(__APPLE__) 173 #define SK_ARM_HAS_CRC32 174 #endif 175 176 ////////////////////////////////////////////////////////////////////// 177 178 #if !defined(SKIA_IMPLEMENTATION) 179 #define SKIA_IMPLEMENTATION 0 180 #endif 181 182 #if !defined(SK_API) 183 #if defined(SKIA_DLL) 184 #if defined(_MSC_VER) 185 #if SKIA_IMPLEMENTATION 186 #define SK_API __declspec(dllexport) 187 #else 188 #define SK_API __declspec(dllimport) 189 #endif 190 #else 191 #define SK_API __attribute__((visibility("default"))) 192 #endif 193 #else 194 #define SK_API 195 #endif 196 #endif 197 198 #endif 199