55#include " vm/globals.h"
66#if !defined(DART_HOST_OS_MACOS)
77#include " vm/cpuid.h"
8+ #include " vm/flags.h"
9+ #include " vm/os.h"
810
911#if defined(HOST_ARCH_IA32) || defined(HOST_ARCH_X64)
1012// GetCpuId() on Windows, __get_cpuid() on Linux
1719
1820namespace dart {
1921
22+ DEFINE_FLAG (bool , trace_cpuid, false , " Trace CPU ID discovery" )
23+
2024bool CpuId::sse2_ = false ;
2125bool CpuId::sse41_ = false ;
2226bool CpuId::popcnt_ = false ;
@@ -41,20 +45,44 @@ void CpuId::Init() {
4145 uint32_t info[4 ] = {static_cast <uint32_t >(-1 )};
4246
4347 GetCpuId (0 , info);
48+ if (FLAG_trace_cpuid) {
49+ for (intptr_t i = 0 ; i < 3 ; i++) {
50+ OS::PrintErr (" cpuid(0) info[%" Pd " ]: %0x\n " , i, info[i]);
51+ }
52+ }
53+
4454 char * id_string = reinterpret_cast <char *>(malloc (3 * sizeof (int32_t )));
4555
4656 // Yes, these are supposed to be out of order.
4757 *reinterpret_cast <uint32_t *>(id_string) = info[1 ];
4858 *reinterpret_cast <uint32_t *>(id_string + 4 ) = info[3 ];
4959 *reinterpret_cast <uint32_t *>(id_string + 8 ) = info[2 ];
5060 CpuId::id_string_ = id_string;
61+ if (FLAG_trace_cpuid) {
62+ OS::PrintErr (" id_string: %s\n " , id_string);
63+ }
5164
5265 GetCpuId (1 , info);
66+ if (FLAG_trace_cpuid) {
67+ for (intptr_t i = 0 ; i < 3 ; i++) {
68+ OS::PrintErr (" cpuid(1) info[%" Pd " ]: %0x\n " , i, info[i]);
69+ }
70+ }
5371 CpuId::sse41_ = (info[2 ] & (1 << 19 )) != 0 ;
5472 CpuId::sse2_ = (info[3 ] & (1 << 26 )) != 0 ;
5573 CpuId::popcnt_ = (info[2 ] & (1 << 23 )) != 0 ;
74+ if (FLAG_trace_cpuid) {
75+ OS::PrintErr (" sse41? %s sse2? %s popcnt? %s\n " ,
76+ CpuId::sse41_ ? " yes" : " no" , CpuId::sse2_ ? " yes" : " no" ,
77+ CpuId::popcnt_ ? " yes" : " no" );
78+ }
5679
5780 GetCpuId (0x80000001 , info);
81+ if (FLAG_trace_cpuid) {
82+ for (intptr_t i = 0 ; i < 3 ; i++) {
83+ OS::PrintErr (" cpuid(0x80000001) info[%" Pd " ]: %0x\n " , i, info[i]);
84+ }
85+ }
5886 CpuId::abm_ = (info[2 ] & (1 << 5 )) != 0 ;
5987
6088 // Brand string returned by CPUID is expected to be nullptr-terminated,
@@ -66,9 +94,18 @@ void CpuId::Init() {
6694 char * brand_string = reinterpret_cast <char *>(calloc (3 * sizeof (info) + 1 , 1 ));
6795 for (uint32_t i = 0 ; i < 2 ; i++) {
6896 GetCpuId (0x80000002U + i, info);
97+ if (FLAG_trace_cpuid) {
98+ for (intptr_t j = 0 ; j < 3 ; j++) {
99+ OS::PrintErr (" cpuid(0x80000002U + %u) info[%" Pd " ]: %0x\n " , i, j,
100+ info[j]);
101+ }
102+ }
69103 memmove (&brand_string[i * sizeof (info)], &info, sizeof (info));
70104 }
71105 CpuId::brand_string_ = brand_string;
106+ if (FLAG_trace_cpuid) {
107+ OS::PrintErr (" brand_string: %s\n " , brand_string_);
108+ }
72109}
73110
74111void CpuId::Cleanup () {
0 commit comments