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