OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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_ = kCpuInfoSystem; |
| 20 const char* CpuInfo::fields_[kCpuInfoMax] = {0}; |
| 21 |
| 22 void CpuInfo::InitOnce(CpuInfoMethod method) { |
| 23 // On Windows, only the CpuId method is supported. |
| 24 ASSERT((method == kCpuInfoDefault) || (method == kCpuInfoCpuId)); |
| 25 method_ = kCpuInfoCpuId; |
| 26 |
| 27 // Initialize the CpuId information. |
| 28 CpuId::InitOnce(); |
| 29 |
| 30 fields_[kCpuInfoProcessor] = "Processor"; |
| 31 fields_[kCpuInfoModel] = "Hardware"; |
| 32 fields_[kCpuInfoHardware] = "Hardware"; |
| 33 fields_[kCpuInfoFeatures] = "Features"; |
| 34 } |
| 35 |
| 36 |
| 37 bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
| 38 return strstr(CpuId::field(idx), search_string); |
| 39 } |
| 40 |
| 41 |
| 42 bool CpuInfo::FieldContainsByString(const char* field, |
| 43 const char* search_string) { |
| 44 for (int i = 0; i < kCpuInfoMax; i++) { |
| 45 if (strcmp(field, fields_[i]) == 0) { |
| 46 return FieldContains(static_cast<CpuInfoIndices>(i), search_string); |
| 47 } |
| 48 } |
| 49 UNIMPLEMENTED(); |
| 50 return false; |
| 51 } |
| 52 |
| 53 |
| 54 const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
| 55 return CpuId::field(idx); |
| 56 } |
| 57 |
| 58 |
| 59 const char* CpuInfo::ExtractFieldByString(const char* field) { |
| 60 for (int i = 0; i < kCpuInfoMax; i++) { |
| 61 if (strcmp(field, fields_[i]) == 0) { |
| 62 return ExtractField(static_cast<CpuInfoIndices>(i)); |
| 63 } |
| 64 } |
| 65 UNIMPLEMENTED(); |
| 66 return NULL; |
| 67 } |
| 68 |
| 69 |
| 70 bool CpuInfo::HasField(const char* field) { |
| 71 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
| 72 (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
| 73 (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
| 74 (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
| 75 } |
| 76 |
| 77 } // namespace dart |
| 78 |
| 79 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |