]> git.sesse.net Git - vlc/blob - include/tests.h
47bc8b1a2751bdc5b5afb41410c8f4e263f10fff
[vlc] / include / tests.h
1 /*****************************************************************************
2  * tests.h: several test functions needed by the plugins
3  *****************************************************************************
4  * Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program 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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 #define CPU_CAPABILITY_NONE    0
24 #define CPU_CAPABILITY_486     1<<0
25 #define CPU_CAPABILITY_586     1<<1
26 #define CPU_CAPABILITY_PPRO    1<<2
27 #define CPU_CAPABILITY_MMX     1<<3
28 #define CPU_CAPABILITY_3DNOW   1<<4
29 #define CPU_CAPABILITY_MMXEXT  1<<5
30
31 /*****************************************************************************
32  * TestVersion: tests if the given string equals the current version
33  *****************************************************************************/
34 int TestVersion( char * psz_version );
35 int TestProgram( char * psz_program );
36 int TestMethod( char * psz_var, char * psz_method );
37 int TestCPU( int i_capabilities );
38
39 /*****************************************************************************
40  * CPUCapabilities: list the processors MMX support and other capabilities
41  *****************************************************************************
42  * This function is called to list extensions the CPU may have.
43  *****************************************************************************/
44 static __inline__ int CPUCapabilities( void )
45 {
46 #ifdef SYS_BEOS
47     return( CPU_CAPABILITY_NONE
48             | CPU_CAPABILITY_486
49             | CPU_CAPABILITY_586
50             | CPU_CAPABILITY_MMX );
51 #else
52     int           i_capabilities = CPU_CAPABILITY_NONE;
53 #ifdef __i386__
54     unsigned int  i_eax, i_ebx, i_ecx, i_edx;
55     boolean_t     b_amd;
56
57 #define cpuid( a )                 \
58     asm volatile ( "cpuid"         \
59                  : "=a" ( i_eax ), \
60                    "=b" ( i_ebx ), \
61                    "=c" ( i_ecx ), \
62                    "=d" ( i_edx )  \
63                  : "a"  ( a )      \
64                  : "cc" );         \
65
66     /* test for a 486 CPU */
67     asm volatile ( "pushfl
68                     popl %%eax
69                     movl %%eax, %%ebx
70                     xorl $0x200000, %%eax
71                     pushl %%eax
72                     popfl
73                     pushfl
74                     popl %%eax"
75                  : "=a" ( i_eax ),
76                    "=b" ( i_ebx )
77                  :
78                  : "cc" );
79
80     if( i_eax == i_ebx )
81     {
82         return( i_capabilities );
83     }
84
85     i_capabilities |= CPU_CAPABILITY_486;
86
87     /* the CPU supports the CPUID instruction - get its level */
88     cpuid( 0x00000000 );
89
90     if( !i_eax )
91     {
92         return( i_capabilities );
93     }
94
95     /* FIXME: this isn't correct, since some 486s have cpuid */
96     i_capabilities |= CPU_CAPABILITY_586;
97
98     /* borrowed from mpeg2dec */
99     b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
100                     && ( i_edx == 0x69746e65 );
101
102     /* test for the MMX flag */
103     cpuid( 0x00000001 );
104
105     if( ! (i_edx & 0x00800000) )
106     {
107         return( i_capabilities );
108     }
109
110     i_capabilities |= CPU_CAPABILITY_MMX;
111
112     if( i_edx & 0x02000000 )
113     {
114         i_capabilities |= CPU_CAPABILITY_MMXEXT;
115     }
116     
117     /* test for additional capabilities */
118     cpuid( 0x80000000 );
119
120     if( i_eax < 0x80000001 )
121     {
122         return( i_capabilities );
123     }
124
125     /* list these additional capabilities */
126     cpuid( 0x80000001 );
127
128     if( i_edx & 0x80000000 )
129     {
130         i_capabilities |= CPU_CAPABILITY_3DNOW;
131     }
132
133     if( b_amd && ( i_edx & 0x00400000 ) )
134     {
135         i_capabilities |= CPU_CAPABILITY_MMXEXT;
136     }
137 #endif /* __i386__ */
138
139     return( i_capabilities );
140 #endif /* SYS_BEOS */
141 }
142