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

Side by Side Diff: runtime/vm/cpuinfo_win.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
« no previous file with comments | « runtime/vm/cpuinfo_test.cc ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "vm/globals.h"
6 #if defined(TARGET_OS_WINDOWS)
7
8 #include "vm/cpuinfo.h"
9 #include "vm/cpuid.h"
10
11 // __cpuid()
12 #include <intrin.h> // NOLINT
13 #include <string.h> // NOLINT
14
15 #include "platform/assert.h"
16
17 namespace dart {
18
19 CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
20 const char* CpuInfo::fields_[kCpuInfoMax] = {0};
21
22 void CpuInfo::InitOnce() {
23 method_ = kCpuInfoCpuId;
24
25 // Initialize the CpuId information.
26 CpuId::InitOnce();
27
28 fields_[kCpuInfoProcessor] = "Processor";
29 fields_[kCpuInfoModel] = "Hardware";
30 fields_[kCpuInfoHardware] = "Hardware";
31 fields_[kCpuInfoFeatures] = "Features";
32 }
33
34
35 void CpuInfo::Cleanup() {
36 CpuId::Cleanup();
37 }
38
39
40 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
41 ASSERT(method_ != kCpuInfoDefault);
42 return strstr(CpuId::field(idx), search_string);
43 }
44
45
46 bool CpuInfo::FieldContainsByString(const char* field,
47 const char* search_string) {
48 ASSERT(method_ != kCpuInfoDefault);
49 for (int i = 0; i < kCpuInfoMax; i++) {
50 if (strcmp(field, fields_[i]) == 0) {
51 return FieldContains(static_cast<CpuInfoIndices>(i), search_string);
52 }
53 }
54 UNIMPLEMENTED();
55 return false;
56 }
57
58
59 const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
60 ASSERT(method_ != kCpuInfoDefault);
61 return CpuId::field(idx);
62 }
63
64
65 const char* CpuInfo::ExtractFieldByString(const char* field) {
66 ASSERT(method_ != kCpuInfoDefault);
67 for (int i = 0; i < kCpuInfoMax; i++) {
68 if (strcmp(field, fields_[i]) == 0) {
69 return ExtractField(static_cast<CpuInfoIndices>(i));
70 }
71 }
72 UNIMPLEMENTED();
73 return NULL;
74 }
75
76
77 bool CpuInfo::HasField(const char* field) {
78 ASSERT(method_ != kCpuInfoDefault);
79 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) ||
80 (strcmp(field, fields_[kCpuInfoModel]) == 0) ||
81 (strcmp(field, fields_[kCpuInfoHardware]) == 0) ||
82 (strcmp(field, fields_[kCpuInfoFeatures]) == 0);
83 }
84
85 } // namespace dart
86
87 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/vm/cpuinfo_test.cc ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698