]> git.sesse.net Git - vlc/blob - include/tests.h
* Compile Altivec modules on Darwin. [MacOS X port]
[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: Samuel Hocevar <sam@zoy.org>
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 #define CPU_CAPABILITY_ALTIVEC 1<<16
31
32 /*****************************************************************************
33  * TestVersion: tests if the given string equals the current version
34  *****************************************************************************/
35 int TestVersion( char * psz_version );
36 int TestProgram( char * psz_program );
37 int TestMethod( char * psz_var, char * psz_method );
38 int TestCPU( int i_capabilities );
39
40 /*****************************************************************************
41  * CPUCapabilities: list the processors MMX support and other capabilities
42  *****************************************************************************
43  * This function is called to list extensions the CPU may have.
44  *****************************************************************************/
45 static __inline__ int CPUCapabilities( void )
46 {
47 #ifdef SYS_BEOS
48     return( CPU_CAPABILITY_NONE
49             | CPU_CAPABILITY_486
50             | CPU_CAPABILITY_586
51             | CPU_CAPABILITY_MMX );
52 #else
53     int           i_capabilities = CPU_CAPABILITY_NONE;
54 #ifdef __i386__
55     unsigned int  i_eax, i_ebx, i_ecx, i_edx;
56     boolean_t     b_amd;
57
58 #define cpuid( a )                 \
59     asm volatile ( "cpuid"         \
60                  : "=a" ( i_eax ), \
61                    "=b" ( i_ebx ), \
62                    "=c" ( i_ecx ), \
63                    "=d" ( i_edx )  \
64                  : "a"  ( a )      \
65                  : "cc" );         \
66
67     /* test for a 486 CPU */
68     asm volatile ( "pushfl
69                     popl %%eax
70                     movl %%eax, %%ebx
71                     xorl $0x200000, %%eax
72                     pushl %%eax
73                     popfl
74                     pushfl
75                     popl %%eax"
76                  : "=a" ( i_eax ),
77                    "=b" ( i_ebx )
78                  :
79                  : "cc" );
80
81     if( i_eax == i_ebx )
82     {
83         return( i_capabilities );
84     }
85
86     i_capabilities |= CPU_CAPABILITY_486;
87
88     /* the CPU supports the CPUID instruction - get its level */
89     cpuid( 0x00000000 );
90
91     if( !i_eax )
92     {
93         return( i_capabilities );
94     }
95
96     /* FIXME: this isn't correct, since some 486s have cpuid */
97     i_capabilities |= CPU_CAPABILITY_586;
98
99     /* borrowed from mpeg2dec */
100     b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
101                     && ( i_edx == 0x69746e65 );
102
103     /* test for the MMX flag */
104     cpuid( 0x00000001 );
105
106     if( ! (i_edx & 0x00800000) )
107     {
108         return( i_capabilities );
109     }
110
111     i_capabilities |= CPU_CAPABILITY_MMX;
112
113     if( i_edx & 0x02000000 )
114     {
115         i_capabilities |= CPU_CAPABILITY_MMXEXT;
116     }
117     
118     /* test for additional capabilities */
119     cpuid( 0x80000000 );
120
121     if( i_eax < 0x80000001 )
122     {
123         return( i_capabilities );
124     }
125
126     /* list these additional capabilities */
127     cpuid( 0x80000001 );
128
129     if( i_edx & 0x80000000 )
130     {
131         i_capabilities |= CPU_CAPABILITY_3DNOW;
132     }
133
134     if( b_amd && ( i_edx & 0x00400000 ) )
135     {
136         i_capabilities |= CPU_CAPABILITY_MMXEXT;
137     }
138 #endif /* __i386__ */
139
140     return( i_capabilities );
141 #endif /* SYS_BEOS */
142 }
143