@@ -20,6 +20,7 @@ CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
20
20
const char * CpuInfo::fields_[kCpuInfoMax ] = {};
21
21
22
22
void CpuInfo::Init () {
23
+ #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
23
24
method_ = kCpuInfoCpuId ;
24
25
25
26
// Initialize the CpuId information.
@@ -30,28 +31,55 @@ void CpuInfo::Init() {
30
31
fields_[kCpuInfoHardware ] = " Hardware" ;
31
32
fields_[kCpuInfoFeatures ] = " Features" ;
32
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
33
41
}
34
42
35
43
void CpuInfo::Cleanup () {
36
- CpuId::Cleanup ();
44
+ if (method_ == kCpuInfoCpuId ) {
45
+ CpuId::Cleanup ();
46
+ } else {
47
+ ASSERT (method_ == kCpuInfoNone );
48
+ }
37
49
}
38
50
39
51
bool CpuInfo::FieldContains (CpuInfoIndices idx, const char * search_string) {
40
- ASSERT (method_ != kCpuInfoDefault );
41
- return strstr (CpuId::field (idx), search_string);
52
+ if (method_ == kCpuInfoCpuId ) {
53
+ return CpuId::field (idx);
54
+ } else {
55
+ UNREACHABLE ();
56
+ }
42
57
}
43
58
44
59
const char * CpuInfo::ExtractField (CpuInfoIndices idx) {
45
- ASSERT (method_ != kCpuInfoDefault );
46
- return CpuId::field (idx);
60
+ if (method_ == kCpuInfoCpuId ) {
61
+ return CpuId::field (idx);
62
+ } else if (method_ == kCpuInfoNone ) {
63
+ if (idx == kCpuInfoHardware ) {
64
+ return " Generic ARM64" ;
65
+ }
66
+ UNREACHABLE ();
67
+ } else {
68
+ UNREACHABLE ();
69
+ }
47
70
}
48
71
49
72
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 );
73
+ if (method_ == kCpuInfoCpuId ) {
74
+ return (strcmp (field, fields_[kCpuInfoProcessor ]) == 0 ) ||
75
+ (strcmp (field, fields_[kCpuInfoModel ]) == 0 ) ||
76
+ (strcmp (field, fields_[kCpuInfoHardware ]) == 0 ) ||
77
+ (strcmp (field, fields_[kCpuInfoFeatures ]) == 0 );
78
+ } else if (method_ == kCpuInfoNone ) {
79
+ return false ;
80
+ } else {
81
+ UNREACHABLE ();
82
+ }
55
83
}
56
84
57
85
} // namespace dart
0 commit comments