]> git.sesse.net Git - vlc/blob - include/tests.h
. a few changes in the CPU extensions detection code, borrowed from the
[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     int         i_capabilities = CPU_CAPABILITY_NONE;
47 #ifdef __i386__
48     int         i_eax, i_ebx, i_ecx, i_edx;
49     boolean_t   b_amd;
50
51 #define cpuid( a )                 \
52     asm volatile ( "cpuid"         \
53                  : "=a" ( i_eax ), \
54                    "=b" ( i_ebx ), \
55                    "=c" ( i_ecx ), \
56                    "=d" ( i_edx )  \
57                  : "a"  ( a )      \
58                  : "cc" );         \
59
60     /* test for a 486 CPU */
61     asm volatile ( "pushfl
62                     popl %%eax
63                     movl %%eax, %%ebx
64                     xorl $0x200000, %%eax
65                     pushl %%eax
66                     popfl
67                     pushfl
68                     popl %%eax"
69                  : "=a" ( i_eax ),
70                    "=b" ( i_ebx )
71                  :
72                  : "cc" );
73
74     if( i_eax == i_ebx )
75     {
76         return( i_capabilities );
77     }
78
79     i_capabilities |= CPU_CAPABILITY_486;
80
81     /* the CPU supports the CPUID instruction - get its level */
82     cpuid( 0x00000000 );
83
84     if( !i_eax )
85     {
86         return( i_capabilities );
87     }
88
89     /* FIXME: this isn't correct, since some 486s have cpuid */
90     i_capabilities |= CPU_CAPABILITY_586;
91
92     /* borrowed from mpeg2dec */
93     b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
94                     && ( i_edx == 0x69746e65 );
95
96     /* test for the MMX flag */
97     cpuid( 0x00000001 );
98
99     if( ! (i_edx & 0x00800000) )
100     {
101         return( i_capabilities );
102     }
103
104     i_capabilities |= CPU_CAPABILITY_MMX;
105
106     if( i_edx & 0x02000000 )
107     {
108         i_capabilities |= CPU_CAPABILITY_MMXEXT;
109     }
110     
111     /* test for additional capabilities */
112     cpuid( 0x80000000 );
113
114     if( i_eax < 0x80000001 )
115     {
116         return( i_capabilities );
117     }
118
119     /* list these additional capabilities */
120     cpuid( 0x80000001 );
121
122     if( i_edx & 0x80000000 )
123     {
124         i_capabilities |= CPU_CAPABILITY_3DNOW;
125     }
126
127     if( b_amd && ( i_edx & 0x00400000 ) )
128     {
129         i_capabilities |= CPU_CAPABILITY_MMXEXT;
130     }
131 #endif /* __i386__ */
132
133     return( i_capabilities );
134 }
135