[FFmpeg-devel] [RFC] use av_get_cpu_flags for real runtime CPU detection in swscale
Michael Niedermayer
michaelni
Wed Sep 8 23:42:56 CEST 2010
On Wed, Sep 08, 2010 at 06:17:27PM +0200, Janne Grunau wrote:
> Hi,
>
> attached patch implements runtime CPU detection in libswscale. One minor
> problem is that it changes behaviour on existing code which sets
> individual flags but obviously not the new SWS_CPU_CAPS_FORCE. I think
> it's acceptable since the flags have no effect with
> !CONFIG_RUNTIME_CPUDETECT.
>
> Janne
> swscale.h | 3 ++-
> utils.c | 22 +++++++++++++++++++++-
> 2 files changed, 23 insertions(+), 2 deletions(-)
> c54cc19db9288e0cce8f8de94ec509442ef9b369 swscale_runtime_cpu_detection.diff
> diff --git a/swscale.h b/swscale.h
> index 4e11c9a..ca63796 100644
> --- a/swscale.h
> +++ b/swscale.h
> @@ -30,7 +30,7 @@
> #include "libavutil/avutil.h"
>
> #define LIBSWSCALE_VERSION_MAJOR 0
> -#define LIBSWSCALE_VERSION_MINOR 11
> +#define LIBSWSCALE_VERSION_MINOR 12
> #define LIBSWSCALE_VERSION_MICRO 0
>
> #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \
> @@ -93,6 +93,7 @@ const char *swscale_license(void);
> #define SWS_CPU_CAPS_ALTIVEC 0x10000000
> #define SWS_CPU_CAPS_BFIN 0x01000000
> #define SWS_CPU_CAPS_SSE2 0x02000000
> +#define SWS_CPU_CAPS_FORCE 0x00100000
>
> #define SWS_MAX_REDUCE_CUTOFF 0.002
>
> diff --git a/utils.c b/utils.c
> index e9400f8..9375489 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -44,6 +44,7 @@
> #include "libavutil/avutil.h"
> #include "libavutil/bswap.h"
> #include "libavutil/pixdesc.h"
> +#include "libavutil/cpu.h"
>
> unsigned swscale_version(void)
> {
> @@ -722,7 +723,26 @@ static int handle_jpeg(enum PixelFormat *format)
>
> static int update_flags_cpu(int flags)
> {
> -#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off
> +#if CONFIG_RUNTIME_CPUDETECT
> + int cpuflags;
> +
> + if (!(flags & SWS_CPU_CAPS_FORCE)) {
> + flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN);
> +
> + cpuflags = av_get_cpu_flags();
> +
> + if (ARCH_X86 && cpuflags & AV_CPU_FLAG_MMX)
> + flags |= SWS_CPU_CAPS_MMX;
> + if (ARCH_X86 && cpuflags & AV_CPU_FLAG_MMX2)
> + flags |= SWS_CPU_CAPS_MMX2;
> + if (ARCH_X86 && cpuflags & AV_CPU_FLAG_3DNOW)
> + flags |= SWS_CPU_CAPS_3DNOW;;
> + if (ARCH_X86 && cpuflags & AV_CPU_FLAG_SSE2)
> + flags |= SWS_CPU_CAPS_SSE2;
> + if (ARCH_PPC && cpuflags & AV_CPU_FLAG_ALTIVEC)
> + flags |= SWS_CPU_CAPS_ALTIVEC;
> + }
update_flags_cpu() is called on each sws_getCachedContext() and redoing cpu
detect on each such calls seems hackish
besides a AUTODETECT instead of FORCE would not break API
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100908/e6ac6255/attachment.pgp>
More information about the ffmpeg-devel
mailing list