don't mix tabs and spaces
[platform/upstream/gstreamer.git] / gst / gstcpu.c
1 /* GStreamer
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>
5  *
6  * gstcpu.c: CPU detection and architecture-specific routines
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #include <glib.h>
25
26 #include "gst_private.h"
27
28 #include "gstcpu.h"
29 #include "gstinfo.h"
30
31 static guint32 _gst_cpu_flags = 0;
32
33 #ifdef HAVE_CPU_I386
34 #define _gst_cpu_initialize_arch _gst_cpu_initialize_i386
35 void gst_cpuid_i386 (int, unsigned long *, unsigned long *, unsigned long *,
36     unsigned long *);
37 gboolean _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist);
38 #else
39 #define _gst_cpu_initialize_arch _gst_cpu_initialize_none
40 gboolean _gst_cpu_initialize_none (gulong * flags, GString * featurelist);
41 #endif
42
43
44 void
45 _gst_cpu_initialize (gboolean opt)
46 {
47   GString *featurelist = g_string_new ("");
48   gulong flags = 0;
49
50   if (opt) {
51     if (!_gst_cpu_initialize_arch (&flags, featurelist))
52       g_string_append (featurelist, "NONE");
53   } else
54     g_string_append (featurelist, "(DISABLED)");
55
56   GST_CAT_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags,
57       featurelist->str);
58   g_string_free (featurelist, TRUE);
59 }
60
61 gboolean
62 _gst_cpu_initialize_none (gulong * flags, GString * featurelist)
63 {
64   return FALSE;
65 }
66
67 #ifdef HAVE_CPU_I386
68 gboolean
69 _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist)
70 {
71   gboolean AMD;
72   gulong eax = 0, ebx = 0, ecx = 0, edx = 0;
73
74   gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
75
76   AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
77
78   gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx);
79
80   if (edx & (1 << 23)) {
81     _gst_cpu_flags |= GST_CPU_FLAG_MMX;
82     g_string_append (featurelist, "MMX ");
83
84     if (edx & (1 << 25)) {
85       _gst_cpu_flags |= GST_CPU_FLAG_SSE;
86       _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
87       g_string_append (featurelist, "SSE ");
88     }
89
90     gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx);
91
92     if (eax >= 0x80000001) {
93
94       gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx);
95
96       if (edx & (1 << 31)) {
97         _gst_cpu_flags |= GST_CPU_FLAG_3DNOW;
98         g_string_append (featurelist, "3DNOW ");
99       }
100       if (AMD && (edx & (1 << 22))) {
101         _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
102         g_string_append (featurelist, "MMXEXT ");
103       }
104     }
105   }
106   *flags = eax;
107   if (_gst_cpu_flags)
108     return TRUE;
109   return FALSE;
110 }
111 #endif
112
113 GstCPUFlags
114 gst_cpu_get_flags (void)
115 {
116   return _gst_cpu_flags;
117 }