From 8d2a4dfbeccdab801083c7223e7c48dcbe6e0843 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 12 Sep 2000 18:13:48 +0000 Subject: [PATCH] Added CPU detection. Original commit message from CVS: Added CPU detection. Added SSE optimisation to mpeg_play Modified the mpeg2 decoder and gstidct to use cpu detection. Cleanups in the mpeg1 and mpeg2 decoders. --- gst/Makefile.am | 3 +++ gst/gst.c | 1 + gst/gst.h | 2 +- gst/gstcpu.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ gst/gstcpu.h | 33 ++++++++++++++++++++++++++++++ gst/gstcpuid_i386.s | 45 +++++++++++++++++++++++++++++++++++++++++ libs/idct/gstidct.c | 11 +++++++--- 7 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 gst/gstcpu.c create mode 100644 gst/gstcpu.h create mode 100644 gst/gstcpuid_i386.s diff --git a/gst/Makefile.am b/gst/Makefile.am index 3ee474cff8..25d533f318 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -15,6 +15,8 @@ libgst_la_SOURCES = \ gstbuffer.c \ gstbufferpool.c \ gstclock.c \ + gstcpu.c \ + gstcpuid_i386.s \ gstelement.c \ gstelementfactory.c \ gstbin.c \ @@ -42,6 +44,7 @@ libgstinclude_HEADERS = \ gstbuffer.h \ gstbufferpool.h \ gstclock.h \ + gstcpu.h \ gstelement.h \ gstbin.h \ gstpipeline.h \ diff --git a/gst/gst.c b/gst/gst.c index c41153dfe4..96ff0c76f1 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -36,6 +36,7 @@ void gst_init(int *argc,char **argv[]) { gtk_init(argc,argv); + _gst_cpu_initialize(); _gst_type_initialize(); _gst_plugin_initialize(); _gst_buffer_initialize(); diff --git a/gst/gst.h b/gst/gst.h index 5ac3c681fe..ca0331fbd2 100644 --- a/gst/gst.h +++ b/gst/gst.h @@ -30,8 +30,8 @@ #include #include #include +#include #include - #include #include #include diff --git a/gst/gstcpu.c b/gst/gstcpu.c new file mode 100644 index 0000000000..22e5abb828 --- /dev/null +++ b/gst/gstcpu.c @@ -0,0 +1,49 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include "config.h" +#include "gstcpu.h" + +static guint32 _gst_cpu_flags; + +#ifdef __i386__ +void gst_cpuid_i386(int,long *,long *,long *,long *); +#define gst_cpuid gst_cpuid_i386 + +#else +#define gst_cpuid(o,a,b,c,d) +#endif + +void _gst_cpu_initialize(void) +{ + long eax=0, ebx=0, ecx=0, edx=0; + + gst_cpuid(1, &eax, &ebx, &ecx, &edx); + + if (edx & (1<<23)) _gst_cpu_flags |= GST_CPU_FLAG_MMX; + if (edx & (1<<25)) _gst_cpu_flags |= GST_CPU_FLAG_SSE; + + g_print("CPU features (%08x)\n", _gst_cpu_flags); +} + +guint32 gst_cpu_get_flags(void) +{ + return _gst_cpu_flags; +} diff --git a/gst/gstcpu.h b/gst/gstcpu.h new file mode 100644 index 0000000000..e8ebd3ee50 --- /dev/null +++ b/gst/gstcpu.h @@ -0,0 +1,33 @@ +/* Gnome-Streamer + * Copyright (C) <1999> Erik Walthinsen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_CPU_H__ +#define __GST_CPU_H__ + +#include + +#define GST_CPU_FLAG_MMX (1 << 0) +#define GST_CPU_FLAG_SSE (1 << 1) + +void _gst_cpu_initialize(); + +guint32 gst_cpu_get_flags(); + +#endif /* __GST_CPU_H__ */ diff --git a/gst/gstcpuid_i386.s b/gst/gstcpuid_i386.s new file mode 100644 index 0000000000..5600c8eaa4 --- /dev/null +++ b/gst/gstcpuid_i386.s @@ -0,0 +1,45 @@ + .text +.globl gst_cpuid_i386 + .type gst_cpuid_i386,@function +gst_cpuid_i386: + pushl %ebp + movl %esp,%ebp + pushl %edi + pushl %ebx + pushl %ecx + pushl %edx + movl 8(%ebp),%eax + cpuid + movl 12(%ebp),%edi + test %edi,%edi + jz L1 + movl %eax,(%edi) +L1: movl 16(%ebp),%edi + test %edi,%edi + jz L2 + movl %ebx,(%edi) +L2: movl 20(%ebp),%edi + test %edi,%edi + jz L3 + movl %ecx,(%edi) +L3: movl 24(%ebp),%edi + test %edi,%edi + jz L4 + movl %edx,(%edi) +L4: popl %edx + popl %ecx + popl %ebx + popl %edi + movl %ebp,%esp + popl %ebp + ret + +/ doesn't work in user mode (MSRs are privileged) +.globl siddisable +siddisable: + movl 0x119,%ecx + rdmsr + orl 0x200000,%eax + wrmsr + ret + diff --git a/libs/idct/gstidct.c b/libs/idct/gstidct.c index 9f7d60f0da..4b1807993a 100644 --- a/libs/idct/gstidct.c +++ b/libs/idct/gstidct.c @@ -20,6 +20,7 @@ #include +#include #include "gstidct.h" #include "dct.h" @@ -33,10 +34,14 @@ GstIDCT *gst_idct_new(GstIDCTMethod method) if (method == GST_IDCT_DEFAULT) { #ifdef HAVE_LIBMMX - method = GST_IDCT_MMX32; -#else - method = GST_IDCT_FAST_INT; + if (gst_cpu_get_flags() & GST_CPU_FLAG_MMX) { + method = GST_IDCT_MMX; + } + else #endif + { + method = GST_IDCT_FAST_INT; + } } new->convert_sparse = gst_idct_int_sparse_idct;