From fda9e21f433bf092e521bf0a7eac03bba7c57c38 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 28 Sep 2003 14:39:52 +0000 Subject: [PATCH] fixes #120345 add disable-cpu-opt Original commit message from CVS: fixes #120345 add disable-cpu-opt --- common | 2 +- configure.ac | 14 +++++++++ gst/gst.c | 9 +++++- gst/gstcpu.c | 76 ++++++++++++++++++++++++--------------------- gst/gstcpu.h | 2 +- gst/gsttrashstack.h | 2 +- 6 files changed, 65 insertions(+), 40 deletions(-) diff --git a/common b/common index b4a839c99c..b7abb510aa 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit b4a839c99c0bf2d4903824426ef3cc0d4b0ad992 +Subproject commit b7abb510aa14e8692df39ea8c2c758e37d8a8d8a diff --git a/configure.ac b/configure.ac index f122cbae61..92eb93a73d 100644 --- a/configure.ac +++ b/configure.ac @@ -229,6 +229,16 @@ AC_HELP_STRING([--enable-atomic],[use atomic reference counting header]), esac], [USE_ATOMIC_H=$HAVE_ATOMIC_H]) dnl Default value +AC_ARG_ENABLE(fast-stack-trash, +AC_HELP_STRING([--enable-fast-stack-trash],[use fast memory allocator (i586 or above)]), +[case "${enableval}" in + yes) USE_FAST_STACK_TRASH=yes;; + noset) USE_FAST_STACK_TRASH=no;; + no) USE_FAST_STACK_TRASH=no;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-atomic) ;; +esac], +[USE_FAST_STACK_TRASH=yes]) dnl Default value + AC_ARG_ENABLE(plugin-builddir, AC_HELP_STRING([--enable-plugin-builddir],[allow tests/demos to use non-installed plugins]), [case "${enableval}" in @@ -340,6 +350,10 @@ if test "x$USE_ATOMIC_H" = xyes; then AC_DEFINE(HAVE_ATOMIC_H, 1, [Define if atomic.h header file is available]) fi +if test "x$USE_FAST_STACK_TRASH" = xyes; then + AC_DEFINE(USE_FAST_STACK_TRASH, 1, [Define if we should use i586 optimized stack functions]) +fi + dnl test if we have pthread_attr_setstack; if not use the older calls AC_CHECK_LIB(pthread, pthread_attr_setstack, AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACK, 1, diff --git a/gst/gst.c b/gst/gst.c index a3cdb14889..90688d4979 100644 --- a/gst/gst.c +++ b/gst/gst.c @@ -43,6 +43,8 @@ static GstRegistry *_user_registry; static gboolean _gst_registry_fixed = FALSE; static gboolean _gst_use_threads = TRUE; +static gboolean _gst_enable_cpu_opt = TRUE; + static gboolean gst_initialized = FALSE; /* this will be set in popt callbacks when a problem has been encountered */ static gboolean _gst_initialization_failure = FALSE; @@ -82,6 +84,7 @@ enum { ARG_DEBUG_MASK, ARG_MASK, ARG_MASK_HELP, + ARG_DISABLE_CPU_OPT, ARG_PLUGIN_SPEW, ARG_PLUGIN_PATH, ARG_PLUGIN_LOAD, @@ -105,6 +108,7 @@ static const struct poptOption options[] = { {"gst-debug-mask", NUL, POPT_ARG_INT|POPT_ARGFLAG_STRIP, NULL, ARG_DEBUG_MASK, "debugging bitmask", "MASK"}, {"gst-mask", NUL, POPT_ARG_INT|POPT_ARGFLAG_STRIP, NULL, ARG_MASK, "bitmask for both info and debugging", "MASK"}, {"gst-mask-help", NUL, POPT_ARG_NONE|POPT_ARGFLAG_STRIP, NULL, ARG_MASK_HELP, "how to set the level of diagnostic output (-mask values)", NULL}, + {"gst-disable-cpu-opt",NUL, POPT_ARG_NONE|POPT_ARGFLAG_STRIP, NULL, ARG_DISABLE_CPU_OPT,"Disable accelerated CPU instructions", NULL}, {"gst-plugin-spew", NUL, POPT_ARG_NONE|POPT_ARGFLAG_STRIP, NULL, ARG_PLUGIN_SPEW, "enable verbose plugin loading diagnostics", NULL}, {"gst-plugin-path", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_PLUGIN_PATH, "'" G_SEARCHPATH_SEPARATOR_S "'--separated path list for loading plugins", "PATHS"}, {"gst-plugin-load", NUL, POPT_ARG_STRING|POPT_ARGFLAG_STRIP, NULL, ARG_PLUGIN_LOAD, "comma-separated list of plugins to preload in addition to the list stored in env variable GST_PLUGIN_PATH", "PLUGINS"}, @@ -497,7 +501,7 @@ init_post (void) /* register core plugins */ _gst_plugin_register_static (&plugin_desc); - _gst_cpu_initialize (); + _gst_cpu_initialize (_gst_enable_cpu_opt); _gst_props_initialize (); _gst_caps_initialize (); _gst_plugin_initialize (); @@ -610,6 +614,9 @@ init_popt_callback (poptContext context, enum poptCallbackReason reason, case ARG_MASK_HELP: gst_mask_help (); exit (0); + case ARG_DISABLE_CPU_OPT: + _gst_enable_cpu_opt = FALSE; + break; case ARG_PLUGIN_SPEW: break; case ARG_PLUGIN_PATH: diff --git a/gst/gstcpu.c b/gst/gstcpu.c index b5d48b0b1a..0b4c36356d 100644 --- a/gst/gstcpu.c +++ b/gst/gstcpu.c @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans + * 2003 Colin Walters * * gstcpu.c: CPU detection and architecture-specific routines * @@ -25,78 +26,81 @@ #include "gst_private.h" #include "gstcpu.h" -static guint32 _gst_cpu_flags; +static guint32 _gst_cpu_flags = 0; #ifdef HAVE_CPU_I386 +#define _gst_cpu_initialize_arch _gst_cpu_initialize_i386 void gst_cpuid_i386 (int, unsigned long *, unsigned long *, unsigned long *, unsigned long *); -#define gst_cpuid gst_cpuid_i386 #else -#define gst_cpuid(o,a,b,c,d) (void)(a);(void)(b);(void)(c); +#define _gst_cpu_initialize_arch _gst_cpu_initialize_none #endif -static gchar * -stringcat (gchar * a, gchar * b) -{ - gchar *c; - - if (a) { - c = g_strconcat (a, b, NULL); - g_free (a); - } - else { - c = g_strdup (b); - } - return c; -} - +gboolean _gst_cpu_initialize_i386 (gulong *flags, GString *featurelist); void -_gst_cpu_initialize (void) +_gst_cpu_initialize (gboolean opt) { - gchar *featurelist = NULL; - gboolean AMD; + GString *featurelist = g_string_new (""); + gulong flags = 0; + + if (opt) { + if (!_gst_cpu_initialize_arch (&flags, featurelist)) + g_string_append (featurelist, "NONE"); + } else + g_string_append (featurelist, "(DISABLED)"); + GST_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags, featurelist->str); + g_string_free (featurelist, TRUE); +} + +gboolean +_gst_cpu_initialize_none (gulong *flags, GString *featurelist) +{ + return FALSE; +} + +gboolean +_gst_cpu_initialize_i386 (gulong *flags, GString *featurelist) +{ + gboolean AMD; gulong eax = 0, ebx = 0, ecx = 0, edx = 0; - gst_cpuid (0, &eax, &ebx, &ecx, &edx); + gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx); AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65); - gst_cpuid (1, &eax, &ebx, &ecx, &edx); + gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx); if (edx & (1 << 23)) { _gst_cpu_flags |= GST_CPU_FLAG_MMX; - featurelist = stringcat (featurelist, "MMX "); + g_string_append (featurelist, "MMX "); if (edx & (1 << 25)) { _gst_cpu_flags |= GST_CPU_FLAG_SSE; _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT; - featurelist = stringcat (featurelist, "SSE "); + g_string_append (featurelist, "SSE "); } - gst_cpuid (0x80000000, &eax, &ebx, &ecx, &edx); + gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx); if (eax >= 0x80000001) { - gst_cpuid (0x80000001, &eax, &ebx, &ecx, &edx); + gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx); if (edx & (1 << 31)) { _gst_cpu_flags |= GST_CPU_FLAG_3DNOW; - featurelist = stringcat (featurelist, "3DNOW "); + g_string_append (featurelist, "3DNOW "); } if (AMD && (edx & (1 << 22))) { _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT; - featurelist = stringcat (featurelist, "MMXEXT "); + g_string_append (featurelist, "MMXEXT "); } } } - - if (!_gst_cpu_flags) { - featurelist = stringcat (featurelist, "NONE"); - } - - GST_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", edx, featurelist); - g_free (featurelist); + *flags = eax; + if (_gst_cpu_flags) + return TRUE; + return FALSE; } GstCPUFlags diff --git a/gst/gstcpu.h b/gst/gstcpu.h index 8ce6b661d8..627b91c1b4 100644 --- a/gst/gstcpu.h +++ b/gst/gstcpu.h @@ -31,7 +31,7 @@ typedef enum { GST_CPU_FLAG_3DNOW = (1<<3) } GstCPUFlags; -void _gst_cpu_initialize (void); +void _gst_cpu_initialize (gboolean useopt); GstCPUFlags gst_cpu_get_flags (void); diff --git a/gst/gsttrashstack.h b/gst/gsttrashstack.h index b2914753bc..8915168c3a 100644 --- a/gst/gsttrashstack.h +++ b/gst/gsttrashstack.h @@ -51,7 +51,7 @@ GST_INLINE_FUNC gpointer gst_trash_stack_pop (GstTrashStack *stack); #if defined (GST_CAN_INLINE) || defined (__GST_TRASH_STACK_C__) -#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 +#if defined (USE_FAST_STACK_TRASH) && defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 #ifdef GST_CONFIG_NO_SMP #define SMP_LOCK ""