Flutter Engine
The Flutter Engine
cpuinfo_win.cc
Go to the documentation of this file.
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(DART_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
17namespace dart {
18
19CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
20const char* CpuInfo::fields_[kCpuInfoMax] = {};
21
22void CpuInfo::Init() {
23#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
24 method_ = kCpuInfoCpuId;
25
26 // Initialize the CpuId information.
28
29 fields_[kCpuInfoProcessor] = "Processor";
30 fields_[kCpuInfoModel] = "Hardware";
31 fields_[kCpuInfoHardware] = "Hardware";
32 fields_[kCpuInfoFeatures] = "Features";
33 fields_[kCpuInfoArchitecture] = nullptr;
34#elif defined(HOST_ARCH_ARM) || defined(HOST_ARCH_ARM64)
35 // We only rely on the base ARM64 version, so we don't need dynamic feature
36 // detection.
37 method_ = kCpuInfoNone;
38#else
39#error Unrecognized target architecture
40#endif
41}
42
43void CpuInfo::Cleanup() {
44 if (method_ == kCpuInfoCpuId) {
46 } else {
47 ASSERT(method_ == kCpuInfoNone);
48 }
49}
50
51bool CpuInfo::FieldContains(CpuInfoIndices idx, const char* search_string) {
52 if (method_ == kCpuInfoCpuId) {
53 const char* field = CpuId::field(idx);
54 if (field == nullptr) return false;
55 bool contains = (strstr(field, search_string) != nullptr);
56 free(const_cast<char*>(field));
57 return contains;
58 } else {
60 }
61}
62
63const char* CpuInfo::ExtractField(CpuInfoIndices idx) {
64 if (method_ == kCpuInfoCpuId) {
65 return CpuId::field(idx);
66 } else if (method_ == kCpuInfoNone) {
67 if (idx == kCpuInfoHardware) {
68 return "Generic ARM64";
69 }
71 } else {
73 }
74}
75
76bool CpuInfo::HasField(const char* field) {
77 if (method_ == kCpuInfoCpuId) {
78 return (strcmp(field, fields_[kCpuInfoProcessor]) == 0) ||
79 (strcmp(field, fields_[kCpuInfoModel]) == 0) ||
80 (strcmp(field, fields_[kCpuInfoHardware]) == 0) ||
81 (strcmp(field, fields_[kCpuInfoFeatures]) == 0);
82 } else if (method_ == kCpuInfoNone) {
83 return false;
84 } else {
86 }
87}
88
89} // namespace dart
90
91#endif // defined(DART_HOST_OS_WINDOWS)
#define UNREACHABLE()
Definition: assert.h:248
static void Cleanup()
Definition: cpuid.h:25
static void Init()
Definition: cpuid.h:24
static const char * field(CpuInfoIndices idx)
Definition: cpuid.h:26
static void Init()
static void Cleanup()
static bool FieldContains(CpuInfoIndices idx, const char *search_string)
static bool HasField(const char *field)
#define ASSERT(E)
Definition: dart_vm.cc:33
CpuInfoMethod
Definition: cpuinfo.h:25
@ kCpuInfoNone
Definition: cpuinfo.h:33
@ kCpuInfoDefault
Definition: cpuinfo.h:38
@ kCpuInfoCpuId
Definition: cpuinfo.h:27
CpuInfoIndices
Definition: cpuinfo.h:15
@ kCpuInfoFeatures
Definition: cpuinfo.h:19
@ kCpuInfoArchitecture
Definition: cpuinfo.h:20
@ kCpuInfoProcessor
Definition: cpuinfo.h:16
@ kCpuInfoHardware
Definition: cpuinfo.h:18
@ kCpuInfoMax
Definition: cpuinfo.h:21
@ kCpuInfoModel
Definition: cpuinfo.h:17
constexpr bool contains(std::string_view str, std::string_view needle)
Definition: SkStringView.h:41