@@ -20,6 +20,7 @@ CpuInfoMethod CpuInfo::method_ = kCpuInfoDefault;
2020const char * CpuInfo::fields_[kCpuInfoMax ] = {};
2121
2222void CpuInfo::Init () {
23+ #if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
2324 method_ = kCpuInfoCpuId ;
2425
2526 // Initialize the CpuId information.
@@ -30,28 +31,55 @@ void CpuInfo::Init() {
3031 fields_[kCpuInfoHardware ] = " Hardware" ;
3132 fields_[kCpuInfoFeatures ] = " Features" ;
3233 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
3341}
3442
3543void CpuInfo::Cleanup () {
36- CpuId::Cleanup ();
44+ if (method_ == kCpuInfoCpuId ) {
45+ CpuId::Cleanup ();
46+ } else {
47+ ASSERT (method_ == kCpuInfoNone );
48+ }
3749}
3850
3951bool 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+ }
4257}
4358
4459const 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+ }
4770}
4871
4972bool 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+ }
5583}
5684
5785} // namespace dart
0 commit comments