From 23a7ef6c475281eb78a0e1eebf309bede34c815d Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Wed, 27 Feb 2013 10:59:06 +0100 Subject: [PATCH] codec/rfx: use sysinfo to detect sse2/neon This also moves (sse2) detection code out of the client into the decoder. --- client/X11/xfreerdp.c | 52 ------------------------------------- include/freerdp/codec/rfx.h | 1 - libfreerdp/codec/rfx.c | 7 ----- libfreerdp/codec/rfx_neon.c | 36 +------------------------ libfreerdp/codec/rfx_sse2.c | 5 ++++ 5 files changed, 6 insertions(+), 95 deletions(-) diff --git a/client/X11/xfreerdp.c b/client/X11/xfreerdp.c index dc7aba819..acab01abc 100644 --- a/client/X11/xfreerdp.c +++ b/client/X11/xfreerdp.c @@ -762,46 +762,6 @@ BOOL xf_pre_connect(freerdp* instance) return TRUE; } -void cpuid(unsigned info, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) -{ -#ifdef __GNUC__ -#if defined(__i386__) || defined(__x86_64__) - __asm volatile - ( - /* The EBX (or RBX register on x86_64) is used for the PIC base address - and must not be corrupted by our inline assembly. */ -#if defined(__i386__) - "mov %%ebx, %%esi;" - "cpuid;" - "xchg %%ebx, %%esi;" -#else - "mov %%rbx, %%rsi;" - "cpuid;" - "xchg %%rbx, %%rsi;" -#endif - : "=a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (info) - ); -#endif -#endif -} - -UINT32 xf_detect_cpu() -{ - unsigned int eax, ebx, ecx, edx = 0; - UINT32 cpu_opt = 0; - - cpuid(1, &eax, &ebx, &ecx, &edx); - - if (edx & (1<<26)) - { - DEBUG_MSG("SSE2 detected"); - cpu_opt |= CPU_SSE2; - } - - return cpu_opt; -} - /** * Callback given to freerdp_connect() to perform post-connection operations. * It will be called only if the connection was initialized properly, and will continue the initialization based on the @@ -809,9 +769,6 @@ UINT32 xf_detect_cpu() */ BOOL xf_post_connect(freerdp* instance) { -#ifdef WITH_SSE2 - UINT32 cpu; -#endif xfInfo* xfi; XGCValues gcv; rdpCache* cache; @@ -866,15 +823,6 @@ BOOL xf_post_connect(freerdp* instance) } } -#ifdef WITH_SSE2 - /* detect only if needed */ - cpu = xf_detect_cpu(); - if (rfx_context) - rfx_context_set_cpu_opt(rfx_context, cpu); - if (nsc_context) - nsc_context_set_cpu_opt(nsc_context, cpu); -#endif - xfi->width = instance->settings->DesktopWidth; xfi->height = instance->settings->DesktopHeight; diff --git a/include/freerdp/codec/rfx.h b/include/freerdp/codec/rfx.h index e2e9b6c85..2e99607b2 100644 --- a/include/freerdp/codec/rfx.h +++ b/include/freerdp/codec/rfx.h @@ -113,7 +113,6 @@ typedef struct _RFX_CONTEXT RFX_CONTEXT; FREERDP_API RFX_CONTEXT* rfx_context_new(void); FREERDP_API void rfx_context_free(RFX_CONTEXT* context); -FREERDP_API void rfx_context_set_cpu_opt(RFX_CONTEXT* context, UINT32 cpu_opt); FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format); FREERDP_API void rfx_context_reset(RFX_CONTEXT* context); diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 3f30cbd22..f105e648b 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -238,13 +238,6 @@ RFX_CONTEXT* rfx_context_new(void) return context; } -void rfx_context_set_cpu_opt(RFX_CONTEXT* context, UINT32 cpu_opt) -{ - /* enable SIMD CPU acceleration if detected */ - if (cpu_opt & CPU_SSE2) - RFX_INIT_SIMD(context); -} - void rfx_context_free(RFX_CONTEXT* context) { free(context->quants); diff --git a/libfreerdp/codec/rfx_neon.c b/libfreerdp/codec/rfx_neon.c index 40683b91b..fec028ba9 100644 --- a/libfreerdp/codec/rfx_neon.c +++ b/libfreerdp/codec/rfx_neon.c @@ -252,43 +252,9 @@ void rfx_dwt_2d_decode_NEON(INT16 * buffer, INT16 * dwt_buffer) rfx_dwt_2d_decode_block_NEON(buffer, dwt_buffer, 32); } -int isNeonSupported() -{ -#if ANDROID - if (android_getCpuFamily() != ANDROID_CPU_FAMILY_ARM) - { - DEBUG_RFX("NEON optimization disabled - No ARM CPU found"); - return 0; - } - - UINT64 features = android_getCpuFeatures(); - - if ((features & ANDROID_CPU_ARM_FEATURE_ARMv7)) - { - if (features & ANDROID_CPU_ARM_FEATURE_NEON) - { - DEBUG_RFX("NEON optimization enabled!"); - return FALSE; - } - DEBUG_RFX("NEON optimization disabled - CPU not NEON capable"); - } - else - { - DEBUG_RFX("NEON optimization disabled - No ARMv7 CPU found"); - } - - return FALSE; -#elif defined(__APPLE) - /* assume NEON support on iOS devices */ - return TRUE; -#else - return FALSE; -#endif -} - void rfx_init_neon(RFX_CONTEXT * context) { - if (isNeonSupported()) + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) { DEBUG_RFX("Using NEON optimizations"); diff --git a/libfreerdp/codec/rfx_sse2.c b/libfreerdp/codec/rfx_sse2.c index ac7e1f21f..fccd1e866 100644 --- a/libfreerdp/codec/rfx_sse2.c +++ b/libfreerdp/codec/rfx_sse2.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -490,6 +491,10 @@ static void rfx_dwt_2d_encode_sse2(INT16* buffer, INT16* dwt_buffer) void rfx_init_sse2(RFX_CONTEXT* context) { + + if (!IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) + return; + DEBUG_RFX("Using SSE2 optimizations"); IF_PROFILER(context->priv->prof_rfx_quantization_decode->name = "rfx_quantization_decode_sse2");