shithub: openh264

Download patch

ref: f2a14600a5667ff20a20fc4a212d2b8e445b7099
parent: 1834cb3aca34a001a1854ce223c6c3f1ade57c21
author: volvet <[email protected]>
date: Fri Jan 10 10:32:35 EST 2014

check cpuid max level before use cpuid.4

--- 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;
   }
@@ -139,9 +141,17 @@
         *pNumberOfLogicProcessors = 1;
       }
     } else if( !strcmp((const str_t*)chVenderName, CPU_Vender_INTEL) ){
-      uiFeatureC = 0;
-      WelsCPUId(0x4, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
-      *pNumberOfLogicProcessors = ((uiFeatureA&0xfc000000)>>26) + 1;
+      if( uiMaxCpuidLevel >= 4 ){
+        uiFeatureC = 0;
+        WelsCPUId(0x4, &uiFeatureA, &uiFeatureB, &uiFeatureC, &uiFeatureD);
+        *pNumberOfLogicProcessors = ((uiFeatureA&0xfc000000)>>26) + 1;
+      } else {
+        if( uiCPU & WELS_CPU_HTT){
+          *pNumberOfLogicProcessors = (uiFeatureB & 0x00ff0000) >> 16; // feature bits: 23-16 on returned EBX
+        } else {
+          *pNumberOfLogicProcessors = 1;
+        }
+      }
     } else {
       //FIXME:  other cpus
       *pNumberOfLogicProcessors = 1;