| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "libyuv/cpu_id.h" | 11 #include "libyuv/cpu_id.h" |
| 12 | 12 |
| 13 #if defined(_MSC_VER) | 13 #if defined(_MSC_VER) |
| 14 #include <intrin.h> // For __cpuidex() | 14 #include <intrin.h> // For __cpuidex() |
| 15 #endif | 15 #endif |
| 16 #if !defined(__pnacl__) && !defined(__CLR_VER) && \ | 16 #if !defined(__pnacl__) && !defined(__CLR_VER) && \ |
| 17 !defined(__native_client__) && (defined(_M_IX86) || defined(_M_X64)) && \ | 17 !defined(__native_client__) && (defined(_M_IX86) || defined(_M_X64)) && \ |
| 18 defined(_MSC_VER) && (_MSC_FULL_VER >= 160040219) | 18 defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) |
| 19 #include <immintrin.h> // For _xgetbv() | 19 #include <immintrin.h> // For _xgetbv() |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #if !defined(__native_client__) | 22 #if !defined(__native_client__) |
| 23 #include <stdlib.h> // For getenv() | 23 #include <stdlib.h> // For getenv() |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 // For ArmCpuCaps() but unittested on all platforms | 26 // For ArmCpuCaps() but unittested on all platforms |
| 27 #include <stdio.h> | 27 #include <stdio.h> |
| 28 #include <string.h> | 28 #include <string.h> |
| 29 | 29 |
| 30 #include "libyuv/basic_types.h" // For CPU_X86 | 30 #include "libyuv/basic_types.h" // For CPU_X86 |
| 31 | 31 |
| 32 #ifdef __cplusplus | 32 #ifdef __cplusplus |
| 33 namespace libyuv { | 33 namespace libyuv { |
| 34 extern "C" { | 34 extern "C" { |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 // For functions that use the stack and have runtime checks for overflow, | 37 // For functions that use the stack and have runtime checks for overflow, |
| 38 // use SAFEBUFFERS to avoid additional check. | 38 // use SAFEBUFFERS to avoid additional check. |
| 39 #if (defined(_MSC_VER) && !defined(__clang__)) && (_MSC_FULL_VER >= 160040219) | 39 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) && \ |
| 40 !defined(__clang__) |
| 40 #define SAFEBUFFERS __declspec(safebuffers) | 41 #define SAFEBUFFERS __declspec(safebuffers) |
| 41 #else | 42 #else |
| 42 #define SAFEBUFFERS | 43 #define SAFEBUFFERS |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 // Low level cpuid for X86. | 46 // Low level cpuid for X86. |
| 46 #if (defined(_M_IX86) || defined(_M_X64) || \ | 47 #if (defined(_M_IX86) || defined(_M_X64) || \ |
| 47 defined(__i386__) || defined(__x86_64__)) && \ | 48 defined(__i386__) || defined(__x86_64__)) && \ |
| 48 !defined(__pnacl__) && !defined(__CLR_VER) | 49 !defined(__pnacl__) && !defined(__CLR_VER) |
| 49 LIBYUV_API | 50 LIBYUV_API |
| 50 void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { | 51 void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { |
| 51 #if defined(_MSC_VER) | 52 #if defined(_MSC_VER) |
| 52 // Visual C version uses intrinsic or inline x86 assembly. | 53 // Visual C version uses intrinsic or inline x86 assembly. |
| 53 #if (_MSC_FULL_VER >= 160040219) | 54 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) |
| 54 __cpuidex((int*)(cpu_info), info_eax, info_ecx); | 55 __cpuidex((int*)(cpu_info), info_eax, info_ecx); |
| 55 #elif defined(_M_IX86) | 56 #elif defined(_M_IX86) |
| 56 __asm { | 57 __asm { |
| 57 mov eax, info_eax | 58 mov eax, info_eax |
| 58 mov ecx, info_ecx | 59 mov ecx, info_ecx |
| 59 mov edi, cpu_info | 60 mov edi, cpu_info |
| 60 cpuid | 61 cpuid |
| 61 mov [edi], eax | 62 mov [edi], eax |
| 62 mov [edi + 4], ebx | 63 mov [edi + 4], ebx |
| 63 mov [edi + 8], ecx | 64 mov [edi + 8], ecx |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 #if defined(_M_IX86) && (_MSC_VER < 1900) | 111 #if defined(_M_IX86) && (_MSC_VER < 1900) |
| 111 #pragma optimize("g", off) | 112 #pragma optimize("g", off) |
| 112 #endif | 113 #endif |
| 113 #if (defined(_M_IX86) || defined(_M_X64) || \ | 114 #if (defined(_M_IX86) || defined(_M_X64) || \ |
| 114 defined(__i386__) || defined(__x86_64__)) && \ | 115 defined(__i386__) || defined(__x86_64__)) && \ |
| 115 !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__) | 116 !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__) |
| 116 #define HAS_XGETBV | 117 #define HAS_XGETBV |
| 117 // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. | 118 // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. |
| 118 int GetXCR0() { | 119 int GetXCR0() { |
| 119 uint32 xcr0 = 0u; | 120 uint32 xcr0 = 0u; |
| 120 #if (_MSC_FULL_VER >= 160040219) | 121 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) |
| 121 xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. | 122 xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. |
| 122 #elif defined(__i386__) || defined(__x86_64__) | 123 #elif defined(__i386__) || defined(__x86_64__) |
| 123 asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcr0) : "c" (0) : "%edx"); | 124 asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcr0) : "c" (0) : "%edx"); |
| 124 #endif // defined(__i386__) || defined(__x86_64__) | 125 #endif // defined(__i386__) || defined(__x86_64__) |
| 125 return xcr0; | 126 return xcr0; |
| 126 } | 127 } |
| 127 #endif // defined(_M_IX86) || defined(_M_X64) .. | 128 #endif // defined(_M_IX86) || defined(_M_X64) .. |
| 128 // Return optimization to previous setting. | 129 // Return optimization to previous setting. |
| 129 #if defined(_M_IX86) && (_MSC_VER < 1900) | 130 #if defined(_M_IX86) && (_MSC_VER < 1900) |
| 130 #pragma optimize("g", on) | 131 #pragma optimize("g", on) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // Note that use of this function is not thread safe. | 291 // Note that use of this function is not thread safe. |
| 291 LIBYUV_API | 292 LIBYUV_API |
| 292 void MaskCpuFlags(int enable_flags) { | 293 void MaskCpuFlags(int enable_flags) { |
| 293 cpu_info_ = InitCpuFlags() & enable_flags; | 294 cpu_info_ = InitCpuFlags() & enable_flags; |
| 294 } | 295 } |
| 295 | 296 |
| 296 #ifdef __cplusplus | 297 #ifdef __cplusplus |
| 297 } // extern "C" | 298 } // extern "C" |
| 298 } // namespace libyuv | 299 } // namespace libyuv |
| 299 #endif | 300 #endif |
| OLD | NEW |