| 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(HOST_OS_WINDOWS) |
| 7 | |
| 8 | #include "vm/cpuid.h" |
| 9 | #include "vm/cpuinfo.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::Init() { |
| 23 | method_ = kCpuInfoCpuId; |
| 24 | |
| 25 | // Initialize the CpuId information. |
| 26 | CpuId::Init(); |
| 27 | |
| 28 | fields_[kCpuInfoProcessor] = "Processor" ; |
| 29 | fields_[kCpuInfoModel] = "Hardware" ; |
| 30 | fields_[kCpuInfoHardware] = "Hardware" ; |
| 31 | fields_[kCpuInfoFeatures] = "Features" ; |
| 32 | fields_[kCpuInfoArchitecture] = NULL; |
| 33 | } |
| 34 | |
| 35 | void CpuInfo::Cleanup() { |
| 36 | CpuId::Cleanup(); |
| 37 | } |
| 38 | |
| 39 | bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) { |
| 40 | ASSERT(method_ != kCpuInfoDefault); |
| 41 | return strstr(CpuId::field(idx), search_string); |
| 42 | } |
| 43 | |
| 44 | const char* CpuInfo::ExtractField(CpuInfoIndices idx) { |
| 45 | ASSERT(method_ != kCpuInfoDefault); |
| 46 | return CpuId::field(idx); |
| 47 | } |
| 48 | |
| 49 | bool CpuInfo::HasField(const char* field) { |
| 50 | ASSERT(method_ != kCpuInfoDefault); |
| 51 | return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) || |
| 52 | (strcmp(field, fields_[kCpuInfoModel]) == 0) || |
| 53 | (strcmp(field, fields_[kCpuInfoHardware]) == 0) || |
| 54 | (strcmp(field, fields_[kCpuInfoFeatures]) == 0); |
| 55 | } |
| 56 | |
| 57 | } // namespace dart |
| 58 | |
| 59 | #endif // defined(HOST_OS_WINDOWS) |
| 60 | |