OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
6 #if !defined(HOST_OS_MACOS) | 6 #if !defined(HOST_OS_MACOS) |
7 #include "vm/cpuid.h" | 7 #include "vm/cpuid.h" |
8 | 8 |
9 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) | 9 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64) |
10 // GetCpuId() on Windows, __get_cpuid() on Linux | 10 // GetCpuId() on Windows, __get_cpuid() on Linux |
(...skipping 16 matching lines...) Expand all Loading... |
27 void CpuId::GetCpuId(int32_t level, uint32_t info[4]) { | 27 void CpuId::GetCpuId(int32_t level, uint32_t info[4]) { |
28 #if defined(HOST_OS_WINDOWS) | 28 #if defined(HOST_OS_WINDOWS) |
29 // The documentation for __cpuid is at: | 29 // The documentation for __cpuid is at: |
30 // http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx | 30 // http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx |
31 __cpuid(reinterpret_cast<int*>(info), level); | 31 __cpuid(reinterpret_cast<int*>(info), level); |
32 #else | 32 #else |
33 __get_cpuid(level, &info[0], &info[1], &info[2], &info[3]); | 33 __get_cpuid(level, &info[0], &info[1], &info[2], &info[3]); |
34 #endif | 34 #endif |
35 } | 35 } |
36 | 36 |
37 | |
38 void CpuId::InitOnce() { | 37 void CpuId::InitOnce() { |
39 uint32_t info[4] = {static_cast<uint32_t>(-1)}; | 38 uint32_t info[4] = {static_cast<uint32_t>(-1)}; |
40 | 39 |
41 GetCpuId(0, info); | 40 GetCpuId(0, info); |
42 char* id_string = reinterpret_cast<char*>(malloc(3 * sizeof(int32_t))); | 41 char* id_string = reinterpret_cast<char*>(malloc(3 * sizeof(int32_t))); |
43 // Yes, these are supposed to be out of order. | 42 // Yes, these are supposed to be out of order. |
44 *reinterpret_cast<uint32_t*>(id_string) = info[1]; | 43 *reinterpret_cast<uint32_t*>(id_string) = info[1]; |
45 *reinterpret_cast<uint32_t*>(id_string + 4) = info[3]; | 44 *reinterpret_cast<uint32_t*>(id_string + 4) = info[3]; |
46 *reinterpret_cast<uint32_t*>(id_string + 8) = info[2]; | 45 *reinterpret_cast<uint32_t*>(id_string + 8) = info[2]; |
47 CpuId::id_string_ = id_string; | 46 CpuId::id_string_ = id_string; |
48 | 47 |
49 GetCpuId(1, info); | 48 GetCpuId(1, info); |
50 CpuId::sse41_ = (info[2] & (1 << 19)) != 0; | 49 CpuId::sse41_ = (info[2] & (1 << 19)) != 0; |
51 CpuId::sse2_ = (info[3] & (1 << 26)) != 0; | 50 CpuId::sse2_ = (info[3] & (1 << 26)) != 0; |
52 | 51 |
53 char* brand_string = | 52 char* brand_string = |
54 reinterpret_cast<char*>(malloc(3 * 4 * sizeof(uint32_t))); | 53 reinterpret_cast<char*>(malloc(3 * 4 * sizeof(uint32_t))); |
55 for (uint32_t i = 0x80000002; i <= 0x80000004; i++) { | 54 for (uint32_t i = 0x80000002; i <= 0x80000004; i++) { |
56 uint32_t off = (i - 0x80000002U) * 4 * sizeof(uint32_t); | 55 uint32_t off = (i - 0x80000002U) * 4 * sizeof(uint32_t); |
57 GetCpuId(i, info); | 56 GetCpuId(i, info); |
58 *reinterpret_cast<int32_t*>(brand_string + off) = info[0]; | 57 *reinterpret_cast<int32_t*>(brand_string + off) = info[0]; |
59 *reinterpret_cast<int32_t*>(brand_string + off + 4) = info[1]; | 58 *reinterpret_cast<int32_t*>(brand_string + off + 4) = info[1]; |
60 *reinterpret_cast<int32_t*>(brand_string + off + 8) = info[2]; | 59 *reinterpret_cast<int32_t*>(brand_string + off + 8) = info[2]; |
61 *reinterpret_cast<int32_t*>(brand_string + off + 12) = info[3]; | 60 *reinterpret_cast<int32_t*>(brand_string + off + 12) = info[3]; |
62 } | 61 } |
63 CpuId::brand_string_ = brand_string; | 62 CpuId::brand_string_ = brand_string; |
64 } | 63 } |
65 | 64 |
66 | |
67 void CpuId::Cleanup() { | 65 void CpuId::Cleanup() { |
68 ASSERT(id_string_ != NULL); | 66 ASSERT(id_string_ != NULL); |
69 free(const_cast<char*>(id_string_)); | 67 free(const_cast<char*>(id_string_)); |
70 id_string_ = NULL; | 68 id_string_ = NULL; |
71 | 69 |
72 ASSERT(brand_string_ != NULL); | 70 ASSERT(brand_string_ != NULL); |
73 free(const_cast<char*>(brand_string_)); | 71 free(const_cast<char*>(brand_string_)); |
74 brand_string_ = NULL; | 72 brand_string_ = NULL; |
75 } | 73 } |
76 | 74 |
77 | |
78 const char* CpuId::id_string() { | 75 const char* CpuId::id_string() { |
79 return strdup(id_string_); | 76 return strdup(id_string_); |
80 } | 77 } |
81 | 78 |
82 | |
83 const char* CpuId::brand_string() { | 79 const char* CpuId::brand_string() { |
84 return strdup(brand_string_); | 80 return strdup(brand_string_); |
85 } | 81 } |
86 | 82 |
87 | |
88 const char* CpuId::field(CpuInfoIndices idx) { | 83 const char* CpuId::field(CpuInfoIndices idx) { |
89 switch (idx) { | 84 switch (idx) { |
90 case kCpuInfoProcessor: | 85 case kCpuInfoProcessor: |
91 return id_string(); | 86 return id_string(); |
92 case kCpuInfoModel: | 87 case kCpuInfoModel: |
93 return brand_string(); | 88 return brand_string(); |
94 case kCpuInfoHardware: | 89 case kCpuInfoHardware: |
95 return brand_string(); | 90 return brand_string(); |
96 case kCpuInfoFeatures: { | 91 case kCpuInfoFeatures: { |
97 if (sse2() && sse41()) { | 92 if (sse2() && sse41()) { |
(...skipping 10 matching lines...) Expand all Loading... |
108 UNREACHABLE(); | 103 UNREACHABLE(); |
109 return NULL; | 104 return NULL; |
110 } | 105 } |
111 } | 106 } |
112 } | 107 } |
113 | 108 |
114 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 109 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
115 } // namespace dart | 110 } // namespace dart |
116 | 111 |
117 #endif // !defined(HOST_OS_MACOS) | 112 #endif // !defined(HOST_OS_MACOS) |
OLD | NEW |