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

Unified Diff: runtime/vm/cpuinfo_win.cc

Issue 120723003: Refactors CPU feature detection. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Cleanup Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/cpuinfo_win.cc
===================================================================
--- runtime/vm/cpuinfo_win.cc (revision 0)
+++ runtime/vm/cpuinfo_win.cc (revision 0)
@@ -0,0 +1,74 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "vm/globals.h"
+#if defined(TARGET_OS_WINDOWS)
+
+// __cpuid()
+#include <intrin.h> // NOLINT
+
+#include "vm/cpuinfo.h"
+
+#include "platform/assert.h"
+
+namespace dart {
+
+char* CpuInfo::data_ = NULL;
+intptr_t CpuInfo::datalen_ = 0;
+
+void CpuInfo::Read() {}
+
+
+bool CpuInfo::FieldContains(const char* field, const char* search_string) {
+ UNIMPLEMENTED();
+ return false;
+}
+
+
+intptr_t CpuInfo::ExtractField(
+ const char* field, char* dest, const intptr_t dest_len) {
+ UNIMPLEMENTED();
+ return 0;
+}
+
+
+bool CpuInfo::HasField(const char* field) {
+ UNIMPLEMENTED();
+ return 0;
+}
+
+
+intptr_t CpuInfo::GetCpuModel(char* dest, const intptr_t dest_len) {
+ ASSERT(dest != NULL);
+ ASSERT(dest_len >= 3 * 4 * sizeof(int32_t));
+ int32_t info[4] = {-1};
+ intptr_t i, num_ids = 0;
+
+ // The documentation for __cpuid is at:
+ // http://msdn.microsoft.com/en-us/library/hskdteyh(v=vs.90).aspx
+ // TODO(zra): In Read() above, read and cache more entries using __cpuid,
+ // then extract as in the implementations for other OS's.
+ dest[0] = '\0';
+ __cpuid(info, 0x80000000);
+ num_ids = info[0];
+ for (i = 0x80000000; i <= num_ids; i++) {
+ __cpuid(info, i);
+ if ((i == 0x80000002) || (i == 0x80000003) || (i == 0x80000004)) {
+ intptr_t off = (i - 0x80000002) * 4 * sizeof(int32_t);
+ char* chunk = reinterpret_cast<char*>(info);
+ for (int j = 0; j < 4 * sizeof(int32_t); j++) {
+ dest[off + j] = chunk[j];
+ }
+ }
+ if (i >= 0x80000004) {
+ break;
+ }
+ }
+
+ return strlen(dest);
+}
+
+} // namespace dart
+
+#endif // defined(TARGET_OS_WINDOWS)

Powered by Google App Engine
This is Rietveld 408576698