2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2003 Colin Walters <walters@verbum.org>
6 * gstcpu.c: CPU detection and architecture-specific routines
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #include "gst_private.h"
31 static GStaticMutex _cpu_mutex = G_STATIC_MUTEX_INIT;
32 static guint32 _gst_cpu_flags = 0;
34 #if defined(HAVE_CPU_I386) && defined(__GNUC__)
35 #define _gst_cpu_initialize_arch _gst_cpu_initialize_i386
36 gboolean _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist);
38 #define _gst_cpu_initialize_arch _gst_cpu_initialize_none
39 gboolean _gst_cpu_initialize_none (gulong * flags, GString * featurelist);
44 _gst_cpu_initialize (gboolean opt)
46 GString *featurelist = g_string_new ("");
50 if (!_gst_cpu_initialize_arch (&flags, featurelist))
51 g_string_append (featurelist, "NONE");
53 g_string_append (featurelist, "(DISABLED)");
55 GST_CAT_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags,
57 g_string_free (featurelist, TRUE);
61 _gst_cpu_initialize_none (gulong * flags, GString * featurelist)
66 #if defined(HAVE_CPU_I386) && defined(__GNUC__)
68 gst_cpuid_i386 (int x, unsigned long *eax, unsigned long *ebx,
69 unsigned long *ecx, unsigned long *edx)
71 unsigned long regs[4];
74 /* GCC-3.2 (and possibly others) don't clobber ebx properly,
75 * so we save/restore it directly. */
76 " movl %%ebx, %%esi\n" " cpuid\n" " movl %%eax, %0\n" " movl %%ebx, %1\n" " movl %%ecx, %2\n" " movl %%edx, %3\n" " movl %%esi, %%ebx\n":"=o" (regs[0]), "=o" (regs[1]), "=o" (regs[2]),
80 : "ecx", "edx", "esi");
89 _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist)
92 gulong eax = 0, ebx = 0, ecx = 0, edx = 0;
95 g_static_mutex_lock (&_cpu_mutex);
96 gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
98 AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
100 gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx);
102 if (edx & (1 << 23)) {
103 _gst_cpu_flags |= GST_CPU_FLAG_MMX;
104 g_string_append (featurelist, "MMX ");
106 if (edx & (1 << 25)) {
107 _gst_cpu_flags |= GST_CPU_FLAG_SSE;
108 _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
109 g_string_append (featurelist, "SSE ");
112 gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx);
114 if (eax >= 0x80000001) {
116 gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx);
118 if (edx & (1 << 31)) {
119 _gst_cpu_flags |= GST_CPU_FLAG_3DNOW;
120 g_string_append (featurelist, "3DNOW ");
122 if (AMD && (edx & (1 << 22))) {
123 _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
124 g_string_append (featurelist, "MMXEXT ");
131 g_static_mutex_unlock (&_cpu_mutex);
138 gst_cpu_get_flags (void)
142 g_static_mutex_lock (&_cpu_mutex);
143 res = _gst_cpu_flags;
144 g_static_mutex_unlock (&_cpu_mutex);