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 "gst_private.h" |
---|
25 | #include <glib.h> |
---|
26 | |
---|
27 | |
---|
28 | #include "gstcpu.h" |
---|
29 | #include "gstinfo.h" |
---|
30 | |
---|
31 | static guint32 _gst_cpu_flags = 0; |
---|
32 | |
---|
33 | #if defined(HAVE_CPU_I386) && defined(__GNUC__) |
---|
34 | #define _gst_cpu_initialize_arch _gst_cpu_initialize_i386 |
---|
35 | gboolean _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist); |
---|
36 | #else |
---|
37 | #define _gst_cpu_initialize_arch _gst_cpu_initialize_none |
---|
38 | gboolean _gst_cpu_initialize_none (gulong * flags, GString * featurelist); |
---|
39 | #endif |
---|
40 | |
---|
41 | |
---|
42 | void |
---|
43 | _gst_cpu_initialize (gboolean opt) |
---|
44 | { |
---|
45 | GString *featurelist = g_string_new (""); |
---|
46 | gulong flags = 0; |
---|
47 | |
---|
48 | if (opt) { |
---|
49 | if (!_gst_cpu_initialize_arch (&flags, featurelist)) |
---|
50 | g_string_append (featurelist, "NONE"); |
---|
51 | } else |
---|
52 | g_string_append (featurelist, "(DISABLED)"); |
---|
53 | |
---|
54 | GST_CAT_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags, |
---|
55 | 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 | #if defined(HAVE_CPU_I386) && defined(__GNUC__) |
---|
66 | static void |
---|
67 | gst_cpuid_i386 (int x, unsigned long *eax, unsigned long *ebx, |
---|
68 | unsigned long *ecx, unsigned long *edx) |
---|
69 | { |
---|
70 | unsigned long regs[4]; |
---|
71 | |
---|
72 | asm ( |
---|
73 | /* GCC-3.2 (and possibly others) don't clobber ebx properly, |
---|
74 | * so we save/restore it directly. */ |
---|
75 | " 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]), |
---|
76 | "=o" (regs |
---|
77 | [3]) |
---|
78 | : "a" (x) |
---|
79 | : "ecx", "edx", "esi"); |
---|
80 | |
---|
81 | *eax = regs[0]; |
---|
82 | *ebx = regs[1]; |
---|
83 | *ecx = regs[2]; |
---|
84 | *edx = regs[3]; |
---|
85 | } |
---|
86 | |
---|
87 | gboolean |
---|
88 | _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist) |
---|
89 | { |
---|
90 | gboolean AMD; |
---|
91 | gulong eax = 0, ebx = 0, ecx = 0, edx = 0; |
---|
92 | |
---|
93 | gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx); |
---|
94 | |
---|
95 | AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65); |
---|
96 | |
---|
97 | gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx); |
---|
98 | |
---|
99 | if (edx & (1 << 23)) { |
---|
100 | _gst_cpu_flags |= GST_CPU_FLAG_MMX; |
---|
101 | g_string_append (featurelist, "MMX "); |
---|
102 | |
---|
103 | if (edx & (1 << 25)) { |
---|
104 | _gst_cpu_flags |= GST_CPU_FLAG_SSE; |
---|
105 | _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT; |
---|
106 | g_string_append (featurelist, "SSE "); |
---|
107 | } |
---|
108 | |
---|
109 | gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx); |
---|
110 | |
---|
111 | if (eax >= 0x80000001) { |
---|
112 | |
---|
113 | gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx); |
---|
114 | |
---|
115 | if (edx & (1 << 31)) { |
---|
116 | _gst_cpu_flags |= GST_CPU_FLAG_3DNOW; |
---|
117 | g_string_append (featurelist, "3DNOW "); |
---|
118 | } |
---|
119 | if (AMD && (edx & (1 << 22))) { |
---|
120 | _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT; |
---|
121 | g_string_append (featurelist, "MMXEXT "); |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | *flags = eax; |
---|
126 | if (_gst_cpu_flags) |
---|
127 | return TRUE; |
---|
128 | return FALSE; |
---|
129 | } |
---|
130 | #endif |
---|
131 | |
---|
132 | GstCPUFlags |
---|
133 | gst_cpu_get_flags (void) |
---|
134 | { |
---|
135 | return _gst_cpu_flags; |
---|
136 | } |
---|