ref: 4a8a9aabc1f2183bfac542c88148ef3d55bfbe3a
parent: f02d0aa6677216b78d3e1150d82e237b5608a0a1
parent: ccaef9fc6d95b3494a85db46c07f23756f487e0c
author: Ethan Hugg <[email protected]>
date: Sat Jan 11 06:29:45 EST 2014
Merge pull request #122 from volvet/core_number_detect_fix Core number detect fix
--- a/codec/common/cpu.cpp
+++ b/codec/common/cpu.cpp
@@ -55,6 +55,7 @@
uint32_t uiFeatureA = 0, uiFeatureB = 0, uiFeatureC = 0, uiFeatureD = 0;
int32_t CacheLineSize = 0;
int8_t chVenderName[16] = { 0 };
+ uint32_t uiMaxCpuidLevel = 0;
if (!WelsCPUIdVerify()) {
/* cpuid is not supported in cpu */
@@ -62,7 +63,8 @@
}
WelsCPUId (0, &uiFeatureA, (uint32_t*)&chVenderName[0], (uint32_t*)&chVenderName[8], (uint32_t*)&chVenderName[4]);
- if (uiFeatureA == 0) {
+ uiMaxCpuidLevel = uiFeatureA;
+ if (uiMaxCpuidLevel == 0) {
/* maximum input value for basic cpuid information */
return 0;
}
@@ -90,7 +92,8 @@
/* CMOV instruction checking */
uiCPU |= WELS_CPU_CMOV;
}
- if (!strcmp ((const str_t*)chVenderName, CPU_Vender_INTEL)) { // confirmed_safe_unsafe_usage
+ if ((!strcmp ((const str_t*)chVenderName, CPU_Vender_INTEL)) ||
+ (!strcmp((const str_t*)chVenderName, CPU_Vender_AMD)) ) { // confirmed_safe_unsafe_usage
if (uiFeatureD & 0x10000000) {
/* Multi-Threading checking: contains of multiple logic processors */
uiCPU |= WELS_CPU_HTT;
@@ -130,9 +133,21 @@
uiCPU |= WELS_CPU_MOVBE;
}
- if (pNumberOfLogicProcessors != NULL) {
- // HTT enabled on chip
- *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX
+ if( pNumberOfLogicProcessors != NULL ){
+ if( uiCPU & WELS_CPU_HTT){
+ *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX
+ } else {
+ *pNumberOfLogicProcessors = 1;
+ }
+ if( !strcmp((const str_t*)chVenderName, CPU_Vender_INTEL) ){
+ if( uiMaxCpuidLevel >= 4 ){
+ uiFeatureC = 0;
+ WelsCPUId(0x4, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
+ if( uiFeatureA != 0 ){
+ *pNumberOfLogicProcessors = ((uiFeatureA&0xfc000000)>>26) + 1;
+ }
+ }
+ }
}
WelsCPUId (0x80000000, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
--- a/codec/common/cpuid.asm
+++ b/codec/common/cpuid.asm
@@ -85,6 +85,7 @@
push rdx
mov eax, ecx
+ mov rcx, [r9]
cpuid
mov [r9], ecx
mov [r8], ebx
@@ -102,10 +103,11 @@
push rcx
push rdx
- mov eax, edi
+ mov eax, edi
+ mov rcx, [rcx]
cpuid
mov [r8], edx
- pop rdx
+ pop rdx
pop r8
mov [r8], ecx
mov [rdx], ebx
@@ -121,6 +123,8 @@
push edi
mov eax, [esp+12] ; operating index
+ mov edi, [esp+24]
+ mov ecx, [edi]
cpuid ; cpuid
; processing various information return