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.
26 #include "gst_private.h"
31 static guint32 _gst_cpu_flags = 0;
34 #define _gst_cpu_initialize_arch _gst_cpu_initialize_i386
35 void gst_cpuid_i386 (int, unsigned long *, unsigned long *, unsigned long *,
37 gboolean _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist);
39 #define _gst_cpu_initialize_arch _gst_cpu_initialize_none
40 gboolean _gst_cpu_initialize_none (gulong * flags, GString * featurelist);
45 _gst_cpu_initialize (gboolean opt)
47 GString *featurelist = g_string_new ("");
51 if (!_gst_cpu_initialize_arch (&flags, featurelist))
52 g_string_append (featurelist, "NONE");
54 g_string_append (featurelist, "(DISABLED)");
56 GST_CAT_INFO (GST_CAT_GST_INIT, "CPU features: (%08lx) %s", flags,
58 g_string_free (featurelist, TRUE);
62 _gst_cpu_initialize_none (gulong * flags, GString * featurelist)
69 _gst_cpu_initialize_i386 (gulong * flags, GString * featurelist)
72 gulong eax = 0, ebx = 0, ecx = 0, edx = 0;
74 gst_cpuid_i386 (0, &eax, &ebx, &ecx, &edx);
76 AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
78 gst_cpuid_i386 (1, &eax, &ebx, &ecx, &edx);
80 if (edx & (1 << 23)) {
81 _gst_cpu_flags |= GST_CPU_FLAG_MMX;
82 g_string_append (featurelist, "MMX ");
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 ");
90 gst_cpuid_i386 (0x80000000, &eax, &ebx, &ecx, &edx);
92 if (eax >= 0x80000001) {
94 gst_cpuid_i386 (0x80000001, &eax, &ebx, &ecx, &edx);
96 if (edx & (1 << 31)) {
97 _gst_cpu_flags |= GST_CPU_FLAG_3DNOW;
98 g_string_append (featurelist, "3DNOW ");
100 if (AMD && (edx & (1 << 22))) {
101 _gst_cpu_flags |= GST_CPU_FLAG_MMXEXT;
102 g_string_append (featurelist, "MMXEXT ");
114 gst_cpu_get_flags (void)
116 return _gst_cpu_flags;