Unify the interface for the different variants of WelsCPUFeatureDetect

The caller of the function should not need to know exactly which
implementation of it is being used.

For the variants that don't support detecting the number of cores,
the pNumberOfLogicProcessors parameter can be left untouched
and the caller will use a higher level API for finding it out.

This simplifies all the calling code, and simplifies adding
more implementations of cpu feature detection.
This commit is contained in:
Martin Storsjö 2014-03-01 01:43:11 +02:00
parent 73cc5862ba
commit 9cf34e7615
5 changed files with 14 additions and 33 deletions

View File

@ -212,9 +212,7 @@ void WelsCPURestore (const uint32_t kuiCPU) {
void WelsXmmRegEmptyOp(void * pSrc) { void WelsXmmRegEmptyOp(void * pSrc) {
} }
#endif #elif defined(HAVE_NEON) //For supporting both android platform and iOS platform
#if defined(HAVE_NEON)//For supporting both android platform and iOS platform
#if defined(ANDROID_NDK) #if defined(ANDROID_NDK)
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
{ {
@ -242,10 +240,8 @@ uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
return uiCPU; return uiCPU;
} }
#endif #elif defined(APPLE_IOS)
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors)
#if defined(APPLE_IOS)
uint32_t WelsCPUFeatureDetectIOS() //Need to be updated for the new device of APPLE
{ {
uint32_t uiCPU = 0; uint32_t uiCPU = 0;
struct utsname sSystemInfo; struct utsname sSystemInfo;
@ -262,7 +258,17 @@ uint32_t WelsCPUFeatureDetectIOS() //Need to be updated for the new device of AP
} }
return uiCPU; return uiCPU;
} }
#else /* HAVE_NEON enabled but no runtime detection */
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
return 0;
}
#endif #endif
#else /* Neither X86_ASM nor HAVE_NEON */
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors) {
return 0;
}
#endif #endif

View File

@ -62,8 +62,6 @@ int32_t WelsCPUSupportFMA (uint32_t eax, uint32_t ecx);
void WelsEmms(); void WelsEmms();
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors);
/* /*
* clear FPU registers states for potential float based calculation if support * clear FPU registers states for potential float based calculation if support
*/ */
@ -80,18 +78,8 @@ void WelsXmmRegLoad(void * src);
void WelsXmmRegEmptyOp(void * pSrc); void WelsXmmRegEmptyOp(void * pSrc);
#if defined(HAVE_NEON)
#if defined(ANDROID_NDK)
uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors); uint32_t WelsCPUFeatureDetect (int32_t* pNumberOfLogicProcessors);
#endif
#if defined(APPLE_IOS)
uint32_t WelsCPUFeatureDetectIOS();
#endif
#endif
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif//__cplusplus #endif//__cplusplus

View File

@ -144,16 +144,7 @@ void WelsDecoderDefaults (PWelsDecoderContext pCtx) {
pCtx->bAuReadyFlag = 0; // au data is not ready pCtx->bAuReadyFlag = 0; // au data is not ready
#if defined(X86_ASM)
pCtx->uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores); pCtx->uiCpuFlag = WelsCPUFeatureDetect (&iCpuCores);
#elif defined(HAVE_NEON)
#if defined(ANDROID_NDK)
pCtx->uiCpuFlag = WelsCPUFeatureDetect(&iCpuCores);
#endif
#if defined(APPLE_IOS)
pCtx->uiCpuFlag = WelsCPUFeatureDetectIOS();
#endif
#endif
pCtx->iImgWidthInPixel = 0; pCtx->iImgWidthInPixel = 0;
pCtx->iImgHeightInPixel = 0; // alloc picture data when picture size is available pCtx->iImgHeightInPixel = 0; // alloc picture data when picture size is available

View File

@ -1933,8 +1933,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
} }
// for cpu features detection, Only detect once?? // for cpu features detection, Only detect once??
#ifdef X86_ASM
uiCpuFeatureFlags = WelsCPUFeatureDetect (&uiCpuCores); // detect cpu capacity features uiCpuFeatureFlags = WelsCPUFeatureDetect (&uiCpuCores); // detect cpu capacity features
#ifdef X86_ASM
if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_128) if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_128)
iCacheLineSize = 128; iCacheLineSize = 128;
else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_64) else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_64)

View File

@ -87,11 +87,7 @@ EResult DestroySpecificVpInterface (IWelsVP* pCtx) {
CVpFrameWork::CVpFrameWork (uint32_t uiThreadsNum, EResult& eReturn) { CVpFrameWork::CVpFrameWork (uint32_t uiThreadsNum, EResult& eReturn) {
int32_t iCoreNum = 1; int32_t iCoreNum = 1;
#ifndef X86_ASM
uint32_t uiCPUFlag = 0;
#else
uint32_t uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum); uint32_t uiCPUFlag = WelsCPUFeatureDetect (&iCoreNum);
#endif
for (int32_t i = 0; i < MAX_STRATEGY_NUM; i++) { for (int32_t i = 0; i < MAX_STRATEGY_NUM; i++) {
IStrategy* pStrategy = m_pStgChain[i]; IStrategy* pStrategy = m_pStgChain[i];