]> git.sesse.net Git - vlc/blob - src/misc/tests.c
. fixed PPC .deb build
[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 #ifndef __i386__
70     return( 0 );
71 #else
72 /* FIXME: under beos, gcc does not support the following inline assembly */ 
73 #ifdef SYS_BEOS
74     return( 1 );
75 #else
76
77     int i_reg, i_dummy = 0;
78
79     /* test for a 386 CPU */
80     asm volatile ( "pushfl
81                     popl %%eax
82                     movl %%eax, %%ecx
83                     xorl $0x40000, %%eax
84                     pushl %%eax
85                     popfl
86                     pushfl
87                     popl %%eax
88                     xorl %%ecx, %%eax
89                     andl $0x40000, %%eax"
90                  : "=a" ( i_reg ) );
91
92     if( !i_reg )
93         return( 0 );
94
95     /* test for a 486 CPU */
96     asm volatile ( "movl %%ecx, %%eax
97                     xorl $0x200000, %%eax
98                     pushl %%eax
99                     popfl
100                     pushfl
101                     popl %%eax
102                     xorl %%ecx, %%eax
103                     pushl %%ecx
104                     popfl
105                     andl $0x200000, %%eax"
106                  : "=a" ( i_reg ) );
107
108     if( !i_reg )
109         return( 0 );
110
111     /* the CPU supports the CPUID instruction - get its level */
112     asm volatile ( "cpuid"
113                  : "=a" ( i_reg ),
114                    "=b" ( i_dummy ),
115                    "=c" ( i_dummy ),
116                    "=d" ( i_dummy )
117                  : "a"  ( 0 ),       /* level 0 */
118                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
119
120     /* this shouldn't happen on a normal CPU */
121     if( !i_reg )
122         return( 0 );
123
124     /* test for the MMX flag */
125     asm volatile ( "cpuid
126                     andl $0x00800000, %%edx" /* X86_FEATURE_MMX */
127                  : "=a" ( i_dummy ),
128                    "=b" ( i_dummy ),
129                    "=c" ( i_dummy ),
130                    "=d" ( i_reg )
131                  : "a"  ( 1 ),       /* level 1 */
132                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
133
134     if( !i_reg )
135         return( 0 );
136
137     return( 1 );
138 #endif
139 #endif
140 }
141
142