]> git.sesse.net Git - vlc/blob - modules/codec/xvmc/cpu_accel.c
0ce16af3e8bde1b1f7647b8972a3c54d4e20d99f
[vlc] / modules / codec / xvmc / cpu_accel.c
1 /* $Id$
2  * cpu_accel.c
3  * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
4  * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5  *
6  * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7  * See http://libmpeg2.sourceforge.net/ for updates.
8  *
9  * mpeg2dec is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * mpeg2dec is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #include <inttypes.h>
25
26 #include "mpeg2.h"
27 #include "attributes.h"
28 #include "mpeg2_internal.h"
29
30 static inline uint32_t arch_accel( void )
31 {
32     uint32_t eax, ebx, ecx, edx;
33     int AMD;
34     uint32_t caps;
35
36 #if !defined(PIC) && !defined(__PIC__)
37 #define cpuid(op,eax,ebx,ecx,edx) \
38     __asm__ ("cpuid"        \
39          : "=a" (eax),      \
40            "=b" (ebx),      \
41            "=c" (ecx),      \
42            "=d" (edx)       \
43          : "a" (op)         \
44          : "cc")
45 #else /* PIC version : save ebx */
46 #define cpuid(op,eax,ebx,ecx,edx) \
47     __asm__ ("push %%ebx\n\t"   \
48          "cpuid\n\t"            \
49          "movl %%ebx,%1\n\t"    \
50          "pop %%ebx"        \
51          : "=a" (eax),      \
52            "=r" (ebx),      \
53            "=c" (ecx),      \
54            "=d" (edx)       \
55          : "a" (op)         \
56          : "cc")
57 #endif
58
59     __asm__ ("pushf\n\t"
60         "pushf\n\t"
61         "pop %0\n\t"
62         "movl %0,%1\n\t"
63         "xorl $0x200000,%0\n\t"
64         "push %0\n\t"
65         "popf\n\t"
66         "pushf\n\t"
67         "pop %0\n\t"
68         "popf"
69         : "=r" (eax),
70           "=r" (ebx)
71         :
72         : "cc");
73
74     if (eax == ebx) /* no cpuid */
75         return 0;
76
77     cpuid (0x00000000, eax, ebx, ecx, edx);
78     if (!eax) /* vendor string only */
79         return 0;
80
81     AMD = (ebx == 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
82
83     cpuid (0x00000001, eax, ebx, ecx, edx);
84     if (! (edx & 0x00800000))   /* no MMX */
85         return 0;
86
87     caps = MPEG2_ACCEL_X86_MMX;
88     if (edx & 0x02000000)       /* SSE - identical to AMD MMX extensions */
89         caps = MPEG2_ACCEL_X86_MMX | MPEG2_ACCEL_X86_MMXEXT;
90
91     cpuid (0x80000000, eax, ebx, ecx, edx);
92     if (eax < 0x80000001)       /* no extended capabilities */
93         return caps;
94
95     cpuid (0x80000001, eax, ebx, ecx, edx);
96
97     if (edx & 0x80000000)
98         caps |= MPEG2_ACCEL_X86_3DNOW;
99
100     if (AMD && (edx & 0x00400000))      /* AMD MMX extensions */
101         caps |= MPEG2_ACCEL_X86_MMXEXT;
102
103     return caps;
104 }
105
106 uint32_t mpeg2_detect_accel (void)
107 {
108     uint32_t accel;
109
110     accel = 0;
111     accel = arch_accel ();
112
113     return accel;
114 }