/******************************************************************************/ #include "stdafx.h" /*#if ANDROID #include #include #endif*/ namespace EE{ /******************************************************************************/ CPU Cpu; /******************************************************************************/ void CPU::set() { // disable denormals (multiplying denormals on Intel i7-3632QM 2.2 Ghz is 16x slower compared to normal values) #if !(WINDOWS && ARM) && !IOS && !ANDROID && !WEB _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); #endif } #if MAC void __cpuid(int regs[4], int cpuid_leaf) { int eax, ebx, ecx, edx; asm( #if !X64 "pushl %%ebx;\n\t" #endif "movl %4, %%eax;\n\t" "cpuid;\n\t" "movl %%eax, %0;\n\t" "movl %%ebx, %1;\n\t" "movl %%ecx, %2;\n\t" "movl %%edx, %3;\n\t" #if !X64 "popl %%ebx;\n\t" #endif :"=m" (eax), "=m" (ebx), "=m" (ecx), "=m" (edx) :"r" (cpuid_leaf) :"%eax", #if X64 "%ebx", #endif "%ecx", "%edx"); regs[0]=eax; regs[1]=ebx; regs[2]=ecx; regs[3]=edx; } #elif LINUX #undef __cpuid static void __cpuid(int regs[4], int cpuid_leaf) { __get_cpuid(cpuid_leaf, (unsigned int*)®s[0], (unsigned int*)®s[1], (unsigned int*)®s[2], (unsigned int*)®s[3]); } #elif ANDROID static ULong GetBits(CChar8 *text) // sample: "0,1-3" { ULong out=0; CalcValue val; for(; text; ) { text=TextValue(text, val); if(!val.type)break; Int a=val.asInt(); if(text && *text=='-') // range { text=TextValue(text+1, val); if(!val.type)break; // skip '-' Int b=val.asInt(); for(Int i=a; i<=b; i++)out|=(ULong(1)< 8 if(t=TextPos(data, "Processor", false, true))t+=9; // Length("Processor") -> 9, if "Hardware" not available, then try using "Processor", because in the past sample output was: "Processor: ARMv7 Processor rev 9 (v7l)" if(t) { for(; *t==' ' || *t==':' || *t=='\t'; ) t++; // skip spaces for(; *t!='\0' && *t!='\n' ; )_name+=*t++; } } // get threads - do not rely on '_SC_NPROCESSORS_CONF' or '_SC_NPROCESSORS_ONLN' as they both may return not all threads (if some are switched off due to power saving), 'sysctl' is not available on Android UnixReadFile("/sys/devices/system/cpu/present" , data, SIZE(data)); ULong cpu_present =GetBits(data); // sample output: "0-3", "0,1-2" (no spaces, values separated with commas, ranges or single values, ranges inclusive) UnixReadFile("/sys/devices/system/cpu/possible", data, SIZE(data)); ULong cpu_possible=GetBits(data); ULong mask=(cpu_present&cpu_possible); REP(64)if(mask&(ULong(1)<