Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: runtime/vm/cpuid.cc

Issue 136303012: Updates refactoring of CPU feature detection (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
siva 2014/02/21 19:28:55 2014
zra 2014/02/21 21:51:55 Done.
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.
4
5 #include "vm/globals.h"
6 #include "vm/cpuid.h"
7
8 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
9 // GetCpuId() on Windows, __get_cpuid() on Linux
10 #if defined(TARGET_OS_WINDOWS)
11 #include <intrin.h> // NOLINT
12 #else
13 #include <cpuid.h> // NOLINT
14 #endif
15 #endif
16
17 namespace dart {
18
19 bool CpuId::sse2_ = false;
20 bool CpuId::sse41_ = false;
21 const char* CpuId::id_string_ = NULL;
22 const char* CpuId::brand_string_ = NULL;
23
24 #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
25
26 void CpuId::GetCpuId(int32_t level, uint32_t info[4]) {
27 #if defined(TARGET_OS_WINDOWS)
28 // The documentation for __cpuid is at:
29 // http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx
30 __cpuid(reinterpret_cast<int*>(info), level);
31 #else
32 __get_cpuid(level, &info[0], &info[1], &info[2], &info[3]);
33 #endif
34 }
35
36
37 void CpuId::InitOnce() {
38 uint32_t info[4] = {-1};
39
40 GetCpuId(0, info);
41 char *id_string = new char[3 * sizeof(int32_t)];
siva 2014/02/21 19:28:55 probably you also need a CpuId::Cleanup() method t
zra 2014/02/21 21:51:55 Done. Also added cleanup code for ProcCpuInfo, an
42 // Yes, these are supposed to be out of order.
43 *reinterpret_cast<uint32_t*>(id_string) = info[1];
44 *reinterpret_cast<uint32_t*>(id_string + 4) = info[3];
45 *reinterpret_cast<uint32_t*>(id_string + 8) = info[2];
46 CpuId::id_string_ = id_string;
47
48 GetCpuId(1, info);
49 CpuId::sse41_ = (info[2] & (1 << 19)) != 0;
50 CpuId::sse2_ = (info[3] & (1 << 26)) != 0;
51
52 char* brand_string = new char[3 * 4 * sizeof(uint32_t)];
53 for (uint32_t i = 0x80000002; i <= 0x80000004; i++) {
54 uint32_t off = (i - 0x80000002U) * 4 * sizeof(uint32_t);
55 GetCpuId(i, info);
56 *reinterpret_cast<int32_t*>(brand_string + off) = info[0];
57 *reinterpret_cast<int32_t*>(brand_string + off + 4) = info[1];
58 *reinterpret_cast<int32_t*>(brand_string + off + 8) = info[2];
59 *reinterpret_cast<int32_t*>(brand_string + off + 12) = info[3];
60 }
61 CpuId::brand_string_ = brand_string;
62 }
63
64
65 const char* CpuId::field(CpuInfoIndices idx) {
66 switch (idx) {
67 case kCpuInfoProcessor:
68 return id_string();
69 case kCpuInfoModel:
70 return brand_string();
71 case kCpuInfoHardware:
72 return brand_string();
73 case kCpuInfoFeatures: {
74 if (sse2() && sse41()) {
75 return "sse2 sse4.1";
76 } else if (sse2()) {
77 return "sse2";
78 } else if (sse41()) {
79 return "sse4.1";
80 } else {
81 return "";
82 }
83 }
84 default: {
85 UNREACHABLE();
86 return NULL;
87 }
88 }
89 }
90
91 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
92
93 } // namespace dart
94
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698