]> git.sesse.net Git - vlc/blob - src/misc/tests.c
. autod�tection des plugins
[vlc] / src / misc / tests.c
1 /*****************************************************************************
2  * tests.c: several test functions needed by the plugins
3  * Functions are prototyped in tests.h.
4  *****************************************************************************
5  * Copyright (C) 2000 VideoLAN
6  *
7  * Authors: Samuel Hocevar <sam@via.ecp.fr>
8  *
9  * This program 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  * This program 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, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "defs.h"
28
29 #include "config.h"
30 #include "common.h"
31
32 #include "intf_msg.h"
33 #include "tests.h"
34
35 #include "main.h"
36
37 /*****************************************************************************
38  * TestVersion: tests if the given string equals the current version
39  *****************************************************************************/
40 int TestVersion( char * psz_version )
41 {
42     return( !strcmp( psz_version, VERSION ) );
43 }
44
45 /*****************************************************************************
46  * TestProgram: tests if the given string equals the program name
47  *****************************************************************************/
48 int TestProgram( char * psz_program )
49 {
50     return( !strcmp( psz_program, p_main->psz_arg0 ) );
51 }
52
53 /*****************************************************************************
54  * TestMethod: tests if the given method was requested
55  *****************************************************************************/
56 int TestMethod( char * psz_var, char * psz_method )
57 {
58     return( !strcmp( psz_method, main_GetPszVariable( psz_var, "" ) ) );
59 }
60
61 /*****************************************************************************
62  * TestMMX: tests if the processor has MMX support.
63  *****************************************************************************
64  * This function is called if HAVE_MMX is enabled, to check whether the
65  * CPU really supports MMX.
66  *****************************************************************************/
67 int TestMMX( void )
68 {
69 /* FIXME: under beos, gcc does not support the following inline assembly */ 
70 #ifdef SYS_BEOS
71     return( 1 );
72 #else
73
74     int i_reg, i_dummy = 0;
75
76     /* test for a 386 CPU */
77     asm volatile ( "pushfl
78                     popl %%eax
79                     movl %%eax, %%ecx
80                     xorl $0x40000, %%eax
81                     pushl %%eax
82                     popfl
83                     pushfl
84                     popl %%eax
85                     xorl %%ecx, %%eax
86                     andl $0x40000, %%eax"
87                  : "=a" ( i_reg ) );
88
89     if( !i_reg )
90         return( 0 );
91
92     /* test for a 486 CPU */
93     asm volatile ( "movl %%ecx, %%eax
94                     xorl $0x200000, %%eax
95                     pushl %%eax
96                     popfl
97                     pushfl
98                     popl %%eax
99                     xorl %%ecx, %%eax
100                     pushl %%ecx
101                     popfl
102                     andl $0x200000, %%eax"
103                  : "=a" ( i_reg ) );
104
105     if( !i_reg )
106         return( 0 );
107
108     /* the CPU supports the CPUID instruction - get its level */
109     asm volatile ( "cpuid"
110                  : "=a" ( i_reg ),
111                    "=b" ( i_dummy ),
112                    "=c" ( i_dummy ),
113                    "=d" ( i_dummy )
114                  : "a"  ( 0 ),       /* level 0 */
115                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
116
117     /* this shouldn't happen on a normal CPU */
118     if( !i_reg )
119         return( 0 );
120
121     /* test for the MMX flag */
122     asm volatile ( "cpuid
123                     andl $0x00800000, %%edx" /* X86_FEATURE_MMX */
124                  : "=a" ( i_dummy ),
125                    "=b" ( i_dummy ),
126                    "=c" ( i_dummy ),
127                    "=d" ( i_reg )
128                  : "a"  ( 1 ),       /* level 1 */
129                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
130
131     if( !i_reg )
132         return( 0 );
133
134     return( 1 );
135
136 #endif
137 }
138
139