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.
7 #if defined(ARCH_CPU_X86_FAMILY)
31 cpu_vendor_("unknown") {
35 #if defined(ARCH_CPU_X86_FAMILY)
38 #if defined(__pic__) && defined(__i386__)
40 void __cpuid(int cpu_info
[4], int info_type
) {
45 : "=a"(cpu_info
[0]), "=D"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
50 void __cpuidex(int cpu_info
[4], int info_type
, int info_index
) {
55 : "=a"(cpu_info
[0]), "=D"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
56 : "a"(info_type
), "c"(info_index
)
62 void __cpuid(int cpu_info
[4], int info_type
) {
65 : "=a"(cpu_info
[0]), "=b"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
70 void __cpuidex(int cpu_info
[4], int info_type
, int info_index
) {
73 : "=a"(cpu_info
[0]), "=b"(cpu_info
[1]), "=c"(cpu_info
[2]), "=d"(cpu_info
[3])
74 : "a"(info_type
), "c"(info_index
)
80 #endif // ARCH_CPU_X86_FAMILY
82 void CPU::Initialize() {
83 #if defined(ARCH_CPU_X86_FAMILY)
84 int cpu_info
[4] = {-1};
85 char cpu_string
[0x20];
87 // __cpuid with an InfoType argument of 0 returns the number of
88 // valid Ids in CPUInfo[0] and the CPU identification string in
89 // the other three array elements. The CPU identification string is
90 // not in linear order. The code below arranges the information
91 // in a human readable form.
93 // More info can be found here:
94 // http://msdn.microsoft.com/en-us/library/hskdteyh.aspx
96 int num_ids
= cpu_info
[0];
97 memset(cpu_string
, 0, sizeof(cpu_string
));
98 *(reinterpret_cast<int*>(cpu_string
)) = cpu_info
[1];
99 *(reinterpret_cast<int*>(cpu_string
+4)) = cpu_info
[3];
100 *(reinterpret_cast<int*>(cpu_string
+8)) = cpu_info
[2];
102 // Interpret CPU feature information.
104 __cpuid(cpu_info
, 1);
105 stepping_
= cpu_info
[0] & 0xf;
106 model_
= ((cpu_info
[0] >> 4) & 0xf) + ((cpu_info
[0] >> 12) & 0xf0);
107 family_
= (cpu_info
[0] >> 8) & 0xf;
108 type_
= (cpu_info
[0] >> 12) & 0x3;
109 ext_model_
= (cpu_info
[0] >> 16) & 0xf;
110 ext_family_
= (cpu_info
[0] >> 20) & 0xff;
111 cpu_vendor_
= cpu_string
;
112 has_mmx_
= (cpu_info
[3] & 0x00800000) != 0;
113 has_sse_
= (cpu_info
[3] & 0x02000000) != 0;
114 has_sse2_
= (cpu_info
[3] & 0x04000000) != 0;
115 has_sse3_
= (cpu_info
[2] & 0x00000001) != 0;
116 has_ssse3_
= (cpu_info
[2] & 0x00000200) != 0;
117 has_sse41_
= (cpu_info
[2] & 0x00080000) != 0;
118 has_sse42_
= (cpu_info
[2] & 0x00100000) != 0;