OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Code in this file is taked from | |
6 // third_party/skia/src/opts/opts_check_SSE2.cpp. | |
7 | |
8 // Note that this file cannot be compiled with -msse2 in gcc. | |
9 | |
10 #include "build/build_config.h" | |
11 #include "media/base/cpu_features.h" | |
12 | |
13 namespace media { | |
14 | |
15 #ifdef _MSC_VER | |
16 static inline void getcpuid(int info_type, int info[4]) { | |
17 __asm { | |
18 mov eax, [info_type] | |
19 cpuid | |
20 mov edi, [info] | |
21 mov [edi], eax | |
22 mov [edi+4], ebx | |
23 mov [edi+8], ecx | |
24 mov [edi+12], edx | |
25 } | |
26 } | |
27 #else | |
28 static inline void getcpuid(int info_type, int info[4]) { | |
29 // We save and restore ebx, so this code can be compatible with -fPIC | |
30 #if defined(__i386__) | |
31 asm volatile ( | |
32 "pushl %%ebx \n\t" | |
33 "cpuid \n\t" | |
34 "movl %%ebx, %1 \n\t" | |
35 "popl %%ebx \n\t" | |
36 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) | |
37 : "a"(info_type) | |
38 ); | |
39 #else | |
40 // We can use cpuid instruction without pushing 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 : "%rbx" | |
47 ); | |
48 #endif | |
49 } | |
50 #endif | |
51 | |
52 bool hasMMX() { | |
53 #if defined(ARCH_CPU_X86_64) | |
54 // Every X86_64 processor has MMX. | |
55 return true; | |
56 #else | |
57 int cpu_info[4] = { 0 }; | |
58 getcpuid(1, cpu_info); | |
59 return (cpu_info[3] & (1<<23)) != 0; | |
60 #endif | |
61 } | |
62 | |
63 bool hasSSE() { | |
64 #if defined(ARCH_CPU_X86_64) | |
65 // Every X86_64 processor has SSE. | |
66 return true; | |
67 #else | |
68 int cpu_info[4] = { 0 }; | |
69 getcpuid(1, cpu_info); | |
70 return (cpu_info[3] & (1<<25)) != 0; | |
71 #endif | |
72 } | |
73 | |
74 bool hasSSE2() { | |
75 #if defined(ARCH_CPU_X86_64) | |
76 // All X86_64 machines have SSE2, so don't even bother checking. | |
77 return true; | |
78 #else | |
79 int cpu_info[4] = { 0 }; | |
80 getcpuid(1, cpu_info); | |
81 return (cpu_info[3] & (1<<26)) != 0; | |
82 #endif | |
83 } | |
84 | |
85 bool hasSSSE3() { | |
86 int cpu_info[4] = { 0 }; | |
87 getcpuid(1, cpu_info); | |
88 return (cpu_info[3] & 0x04000000) != 0 && (cpu_info[2] & 0x00000001) != 0 && | |
89 (cpu_info[2] & 0x00000200) != 0; | |
90 } | |
91 | |
92 } // namespace media | |
OLD | NEW |