]> git.sesse.net Git - vlc/blob - include/tests.h
. merged the YUV plugins in the same directory to avoid too much code
[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_MMX     1<<0
25 #define CPU_CAPABILITY_3DNOW   1<<1
26 #define CPU_CAPABILITY_MMXEXT  1<<2
27
28 #define cpuid( a, eax, ebx, ecx, edx ) \
29     asm volatile ( "pushl %%ebx      \n\
30                     cpuid            \n\
31                     popl %%ebx"        \
32                  : "=a" ( eax ),       \
33                    "=c" ( ecx ),       \
34                    "=d" ( edx )        \
35                  : "a"  ( a )          \
36                  : "cc" );
37
38 /*****************************************************************************
39  * TestVersion: tests if the given string equals the current version
40  *****************************************************************************/
41 int TestVersion( char * psz_version );
42 int TestProgram( char * psz_program );
43 int TestMethod( char * psz_var, char * psz_method );
44
45 /*****************************************************************************
46  * TestCPU: tests if the processor has MMX support and other capabilities
47  *****************************************************************************
48  * This function is called to check extensions the CPU may have.
49  *****************************************************************************/
50 static __inline__ int TestCPU( void )
51 {
52 #ifndef __i386__
53     return( CPU_CAPABILITY_NONE );
54 #else
55     int i_reg, i_dummy = 0;
56
57     /* test for a 386 CPU */
58     asm volatile ( "pushfl
59                     popl %%eax
60                     movl %%eax, %%ecx
61                     xorl $0x40000, %%eax
62                     pushl %%eax
63                     popfl
64                     pushfl
65                     popl %%eax
66                     xorl %%ecx, %%eax
67                     andl $0x40000, %%eax"
68                  : "=a" ( i_reg ) );
69
70     if( !i_reg )
71     {
72         return( CPU_CAPABILITY_NONE );
73     }
74
75     /* test for a 486 CPU */
76     asm volatile ( "movl %%ecx, %%eax
77                     xorl $0x200000, %%eax
78                     pushl %%eax
79                     popfl
80                     pushfl
81                     popl %%eax
82                     xorl %%ecx, %%eax
83                     pushl %%ecx
84                     popfl
85                     andl $0x200000, %%eax"
86                  : "=a" ( i_reg ) );
87
88     if( !i_reg )
89     {
90         return( CPU_CAPABILITY_NONE );
91     }
92
93     /* the CPU supports the CPUID instruction - get its level */
94     cpuid( 0, i_reg, i_dummy, i_dummy, i_dummy );
95
96     if( !i_reg )
97     {
98         return( CPU_CAPABILITY_NONE );
99     }
100
101     /* test for the MMX flag */
102     cpuid( 1, i_dummy, i_dummy, i_dummy, i_reg );
103
104     if( ! (i_reg & 0x00800000) )
105     {
106         return( CPU_CAPABILITY_NONE );
107     }
108
109     return( CPU_CAPABILITY_MMX );
110 #endif
111 }
112