| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef WEBP_DSP_CPU_H_ |
| 15 |
#define WEBP_DSP_CPU_H_ |
| 16 |
|
| 17 |
#include <stddef.h> |
| 18 |
|
| 19 |
#ifdef HAVE_CONFIG_H |
| 20 |
#include "src/webp/config.h" |
| 21 |
#endif |
| 22 |
|
| 23 |
#include "src/webp/types.h" |
| 24 |
|
| 25 |
#if defined(__GNUC__) |
| 26 |
#define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__) |
| 27 |
#define LOCAL_GCC_PREREQ(maj, min) (LOCAL_GCC_VERSION >= (((maj) << 8) | (min))) |
| 28 |
#else |
| 29 |
#define LOCAL_GCC_VERSION 0 |
| 30 |
#define LOCAL_GCC_PREREQ(maj, min) 0 |
| 31 |
#endif |
| 32 |
|
| 33 |
#if defined(__clang__) |
| 34 |
#define LOCAL_CLANG_VERSION ((__clang_major__ << 8) | __clang_minor__) |
| 35 |
#define LOCAL_CLANG_PREREQ(maj, min) \ |
| 36 |
(LOCAL_CLANG_VERSION >= (((maj) << 8) | (min))) |
| 37 |
#else |
| 38 |
#define LOCAL_CLANG_VERSION 0 |
| 39 |
#define LOCAL_CLANG_PREREQ(maj, min) 0 |
| 40 |
#endif |
| 41 |
|
| 42 |
#ifndef __has_builtin |
| 43 |
#define __has_builtin(x) 0 |
| 44 |
#endif |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#if !defined(HAVE_CONFIG_H) |
| 50 |
#if defined(_MSC_VER) && _MSC_VER > 1310 && \ |
| 51 |
(defined(_M_X64) || defined(_M_IX86)) |
| 52 |
#define WEBP_MSC_SSE2 |
| 53 |
#endif |
| 54 |
|
| 55 |
#if defined(_MSC_VER) && _MSC_VER >= 1500 && \ |
| 56 |
(defined(_M_X64) || defined(_M_IX86)) |
| 57 |
#define WEBP_MSC_SSE41 |
| 58 |
#endif |
| 59 |
#endif |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
#if (defined(__SSE2__) || defined(WEBP_MSC_SSE2)) && \ |
| 66 |
(!defined(HAVE_CONFIG_H) || defined(WEBP_HAVE_SSE2)) |
| 67 |
#define WEBP_USE_SSE2 |
| 68 |
#endif |
| 69 |
|
| 70 |
#if defined(WEBP_USE_SSE2) && !defined(WEBP_HAVE_SSE2) |
| 71 |
#define WEBP_HAVE_SSE2 |
| 72 |
#endif |
| 73 |
|
| 74 |
#if (defined(__SSE4_1__) || defined(WEBP_MSC_SSE41)) && \ |
| 75 |
(!defined(HAVE_CONFIG_H) || defined(WEBP_HAVE_SSE41)) |
| 76 |
#define WEBP_USE_SSE41 |
| 77 |
#endif |
| 78 |
|
| 79 |
#if defined(WEBP_USE_SSE41) && !defined(WEBP_HAVE_SSE41) |
| 80 |
#define WEBP_HAVE_SSE41 |
| 81 |
#endif |
| 82 |
|
| 83 |
#undef WEBP_MSC_SSE41 |
| 84 |
#undef WEBP_MSC_SSE2 |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
#if ((defined(__ARM_NEON__) || defined(__aarch64__)) && \ |
| 92 |
(!defined(HAVE_CONFIG_H) || defined(WEBP_HAVE_NEON))) && \ |
| 93 |
!defined(__native_client__) |
| 94 |
#define WEBP_USE_NEON |
| 95 |
#endif |
| 96 |
|
| 97 |
#if !defined(WEBP_USE_NEON) && defined(__ANDROID__) && \ |
| 98 |
defined(__ARM_ARCH_7A__) && defined(HAVE_CPU_FEATURES_H) |
| 99 |
#define WEBP_ANDROID_NEON |
| 100 |
#define WEBP_USE_NEON |
| 101 |
#endif |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
#if defined(_MSC_VER) && \ |
| 108 |
((_MSC_VER >= 1700 && defined(_M_ARM)) || \ |
| 109 |
(_MSC_VER >= 1926 && (defined(_M_ARM64) || defined(_M_ARM64EC)))) |
| 110 |
#define WEBP_USE_NEON |
| 111 |
#define WEBP_USE_INTRINSICS |
| 112 |
#endif |
| 113 |
|
| 114 |
#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) |
| 115 |
#define WEBP_AARCH64 1 |
| 116 |
#else |
| 117 |
#define WEBP_AARCH64 0 |
| 118 |
#endif |
| 119 |
|
| 120 |
#if defined(WEBP_USE_NEON) && !defined(WEBP_HAVE_NEON) |
| 121 |
#define WEBP_HAVE_NEON |
| 122 |
#endif |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
#if defined(__mips__) && !defined(__mips64) && defined(__mips_isa_rev) && \ |
| 128 |
(__mips_isa_rev >= 1) && (__mips_isa_rev < 6) |
| 129 |
#define WEBP_USE_MIPS32 |
| 130 |
#if (__mips_isa_rev >= 2) |
| 131 |
#define WEBP_USE_MIPS32_R2 |
| 132 |
#if defined(__mips_dspr2) || (defined(__mips_dsp_rev) && __mips_dsp_rev >= 2) |
| 133 |
#define WEBP_USE_MIPS_DSP_R2 |
| 134 |
#endif |
| 135 |
#endif |
| 136 |
#endif |
| 137 |
|
| 138 |
#if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5) |
| 139 |
#define WEBP_USE_MSA |
| 140 |
#endif |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
#ifndef WEBP_DSP_OMIT_C_CODE |
| 145 |
#define WEBP_DSP_OMIT_C_CODE 1 |
| 146 |
#endif |
| 147 |
|
| 148 |
#if defined(WEBP_USE_NEON) && WEBP_DSP_OMIT_C_CODE |
| 149 |
#define WEBP_NEON_OMIT_C_CODE 1 |
| 150 |
#else |
| 151 |
#define WEBP_NEON_OMIT_C_CODE 0 |
| 152 |
#endif |
| 153 |
|
| 154 |
#if !(LOCAL_CLANG_PREREQ(3, 8) || LOCAL_GCC_PREREQ(4, 8) || WEBP_AARCH64) |
| 155 |
#define WEBP_NEON_WORK_AROUND_GCC 1 |
| 156 |
#else |
| 157 |
#define WEBP_NEON_WORK_AROUND_GCC 0 |
| 158 |
#endif |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
#define WEBP_TSAN_IGNORE_FUNCTION |
| 164 |
#if defined(__has_feature) |
| 165 |
#if __has_feature(thread_sanitizer) |
| 166 |
#undef WEBP_TSAN_IGNORE_FUNCTION |
| 167 |
#define WEBP_TSAN_IGNORE_FUNCTION __attribute__((no_sanitize_thread)) |
| 168 |
#endif |
| 169 |
#endif |
| 170 |
|
| 171 |
#if defined(__has_feature) |
| 172 |
#if __has_feature(memory_sanitizer) |
| 173 |
#define WEBP_MSAN |
| 174 |
#endif |
| 175 |
#endif |
| 176 |
|
| 177 |
#if defined(WEBP_USE_THREAD) && !defined(_WIN32) |
| 178 |
#include <pthread.h> |
| 179 |
|
| 180 |
#define WEBP_DSP_INIT(func) \ |
| 181 |
do { \ |
| 182 |
static volatile VP8CPUInfo func##_last_cpuinfo_used = \ |
| 183 |
(VP8CPUInfo)&func##_last_cpuinfo_used; \ |
| 184 |
static pthread_mutex_t func##_lock = PTHREAD_MUTEX_INITIALIZER; \ |
| 185 |
if (pthread_mutex_lock(&func##_lock)) break; \ |
| 186 |
if (func##_last_cpuinfo_used != VP8GetCPUInfo) func(); \ |
| 187 |
func##_last_cpuinfo_used = VP8GetCPUInfo; \ |
| 188 |
(void)pthread_mutex_unlock(&func##_lock); \ |
| 189 |
} while (0) |
| 190 |
#else |
| 191 |
#define WEBP_DSP_INIT(func) \ |
| 192 |
do { \ |
| 193 |
static volatile VP8CPUInfo func##_last_cpuinfo_used = \ |
| 194 |
(VP8CPUInfo)&func##_last_cpuinfo_used; \ |
| 195 |
if (func##_last_cpuinfo_used == VP8GetCPUInfo) break; \ |
| 196 |
func(); \ |
| 197 |
func##_last_cpuinfo_used = VP8GetCPUInfo; \ |
| 198 |
} while (0) |
| 199 |
#endif |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
#define WEBP_DSP_INIT_FUNC(name) \ |
| 209 |
static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void); \ |
| 210 |
WEBP_TSAN_IGNORE_FUNCTION void name(void) { WEBP_DSP_INIT(name##_body); } \ |
| 211 |
static WEBP_TSAN_IGNORE_FUNCTION void name##_body(void) |
| 212 |
|
| 213 |
#define WEBP_UBSAN_IGNORE_UNDEF |
| 214 |
#define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW |
| 215 |
#if defined(__clang__) && defined(__has_attribute) |
| 216 |
#if __has_attribute(no_sanitize) |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
#undef WEBP_UBSAN_IGNORE_UNDEF |
| 221 |
#define WEBP_UBSAN_IGNORE_UNDEF __attribute__((no_sanitize("undefined"))) |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
#undef WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW |
| 227 |
#define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW \ |
| 228 |
__attribute__((no_sanitize("unsigned-integer-overflow"))) |
| 229 |
#endif |
| 230 |
#endif |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
#if !defined(WEBP_OFFSET_PTR) |
| 235 |
#define WEBP_OFFSET_PTR(ptr, off) (((ptr) == NULL) ? NULL : ((ptr) + (off))) |
| 236 |
#endif |
| 237 |
|
| 238 |
|
| 239 |
#if !defined(WEBP_SWAP_16BIT_CSP) |
| 240 |
#define WEBP_SWAP_16BIT_CSP 0 |
| 241 |
#endif |
| 242 |
|
| 243 |
|
| 244 |
#if !defined(WORDS_BIGENDIAN) && \ |
| 245 |
(defined(__BIG_ENDIAN__) || defined(_M_PPC) || \ |
| 246 |
(defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) |
| 247 |
#define WORDS_BIGENDIAN |
| 248 |
#endif |
| 249 |
|
| 250 |
typedef enum { |
| 251 |
kSSE2, |
| 252 |
kSSE3, |
| 253 |
kSlowSSSE3, |
| 254 |
kSSE4_1, |
| 255 |
kAVX, |
| 256 |
kAVX2, |
| 257 |
kNEON, |
| 258 |
kMIPS32, |
| 259 |
kMIPSdspR2, |
| 260 |
kMSA |
| 261 |
} CPUFeature; |
| 262 |
|
| 263 |
|
| 264 |
typedef int (*VP8CPUInfo)(CPUFeature feature); |
| 265 |
|
| 266 |
#endif |