| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Code in this file is taked from | 5 // Code in this file is taked from |
| 6 // third_party/skia/src/opts/opts_check_SSE2.cpp. | 6 // third_party/skia/src/opts/opts_check_SSE2.cpp. |
| 7 | 7 |
| 8 // Note that this file cannot be compiled with -msse2 in gcc. | 8 // Note that this file cannot be compiled with -msse2 in gcc. |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "media/base/cpu_features.h" | 11 #include "media/base/cpu_features.h" |
| 12 | 12 |
| 13 namespace media { | 13 namespace media { |
| 14 | 14 |
| 15 #if defined(ARCH_CPU_X86_64) | |
| 16 /* All x86_64 machines have SSE2, so don't even bother checking. */ | |
| 17 bool hasSSE2() { | |
| 18 return true; | |
| 19 } | |
| 20 #else | |
| 21 #ifdef _MSC_VER | 15 #ifdef _MSC_VER |
| 22 static inline void getcpuid(int info_type, int info[4]) { | 16 static inline void getcpuid(int info_type, int info[4]) { |
| 23 __asm { | 17 __asm { |
| 24 mov eax, [info_type] | 18 mov eax, [info_type] |
| 25 cpuid | 19 cpuid |
| 26 mov edi, [info] | 20 mov edi, [info] |
| 27 mov [edi], eax | 21 mov [edi], eax |
| 28 mov [edi+4], ebx | 22 mov [edi+4], ebx |
| 29 mov [edi+8], ecx | 23 mov [edi+8], ecx |
| 30 mov [edi+12], edx | 24 mov [edi+12], edx |
| 31 } | 25 } |
| 32 } | 26 } |
| 33 #else | 27 #else |
| 34 static inline void getcpuid(int info_type, int info[4]) { | 28 static inline void getcpuid(int info_type, int info[4]) { |
| 35 // We save and restore ebx, so this code can be compatible with -fPIC | 29 // We save and restore ebx, so this code can be compatible with -fPIC |
| 30 #if defined(__i386__) |
| 36 asm volatile ( | 31 asm volatile ( |
| 37 "pushl %%ebx \n\t" | 32 "pushl %%ebx \n\t" |
| 38 "cpuid \n\t" | 33 "cpuid \n\t" |
| 39 "movl %%ebx, %1 \n\t" | 34 "movl %%ebx, %1 \n\t" |
| 40 "popl %%ebx \n\t" | 35 "popl %%ebx \n\t" |
| 41 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) | 36 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) |
| 42 : "a"(info_type) | 37 : "a"(info_type) |
| 43 ); | 38 ); |
| 39 #else |
| 40 // We can use cpuid instruction without saving ebx on gcc x86-64 because it |
| 41 // does not use ebx (or rbx) as a GOT register. |
| 42 asm volatile ( |
| 43 "cpuid \n\t" |
| 44 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) |
| 45 : "a"(info_type) |
| 46 ); |
| 47 #endif |
| 44 } | 48 } |
| 45 #endif | 49 #endif |
| 46 | 50 |
| 47 bool hasSSE2() { | 51 bool hasSSE2() { |
| 52 #if defined(ARCH_CPU_X86_64) |
| 53 /* All x86_64 machines have SSE2, so don't even bother checking. */ |
| 54 return true; |
| 55 #else |
| 48 int cpu_info[4] = { 0 }; | 56 int cpu_info[4] = { 0 }; |
| 49 getcpuid(1, cpu_info); | 57 getcpuid(1, cpu_info); |
| 50 return (cpu_info[3] & (1<<26)) != 0; | 58 return (cpu_info[3] & (1<<26)) != 0; |
| 59 #endif |
| 51 } | 60 } |
| 52 #endif | 61 |
| 62 bool hasSSSE3() { |
| 63 int cpu_info[4] = { 0 }; |
| 64 getcpuid(1, cpu_info); |
| 65 return (cpu_info[3] & 0x04000000) != 0 && (cpu_info[2] & 0x00000001) != 0 && |
| 66 (cpu_info[2] & 0x00000200) != 0; |
| 67 } |
| 53 | 68 |
| 54 } // namespace media | 69 } // namespace media |
| OLD | NEW |