fix doc build fix autogen
[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 *, unsigned long *);
36 gboolean _gst_cpu_initialize_i386 (gulong *flags, GString *featurelist);
37 #else
38 #define _gst_cpu_initialize_arch _gst_cpu_initialize_none
39 gboolean _gst_cpu_initialize_none (gulong *flags, GString *featurelist);
40 #endif
41
42
43 void
44 _gst_cpu_initialize (gboolean opt)
45 {
46   GString *featurelist = g_string_new ("");
47   gulong flags = 0;
48   
49   if (opt) {
50     if (!_gst_cpu_initialize_arch (&flags, featurelist))
51       g_string_append (featurelist, "NONE");
52   } else
53     g_string_append (featurelist, "(DISABLED)");
54
55   GST_CAT_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags, featurelist->str);
56   g_string_free (featurelist, TRUE);
57 }
58
59 gboolean
60 _gst_cpu_initialize_none (gulong *flags, GString *featurelist)
61 {
62   return FALSE;
63 }
64
65 #ifdef HAVE_CPU_I386
66 gboolean
67 _gst_cpu_initialize_i386 (gulong *flags, GString *featurelist)
68 {
69   gboolean AMD;
70   gulong eax = 0, ebx = 0, ecx = 0, edx = 0;
71
72   gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
73
74   AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
75
76   gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx);
77
78   if (edx & (1 << 23)) {
79     _gst_cpu_flags |= GST_CPU_FLAG_MMX;
80     g_string_append (featurelist, "MMX ");
81
82     if (edx & (1 << 25)) {
83       _gst_cpu_flags |= GST_CPU_FLAG_SSE;
84       _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
85       g_string_append (featurelist, "SSE ");
86     }
87
88     gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx);
89
90     if (eax >= 0x80000001) {
91
92       gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx);
93
94       if (edx & (1 << 31)) {
95         _gst_cpu_flags |= GST_CPU_FLAG_3DNOW;
96         g_string_append (featurelist, "3DNOW ");
97       }
98       if (AMD && (edx & (1 << 22))) {
99         _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
100         g_string_append (featurelist, "MMXEXT ");
101       }
102     }
103   }
104   *flags = eax;
105   if (_gst_cpu_flags)
106     return TRUE;
107   return FALSE;
108 }
109 #endif
110
111 GstCPUFlags
112 gst_cpu_get_flags (void)
113 {
114   return _gst_cpu_flags;
115 }