tests.h 4.36 KB
Newer Older
1 2 3 4 5
/*****************************************************************************
 * tests.h: several test functions needed by the plugins
 *****************************************************************************
 * Copyright (C) 1996, 1997, 1998, 1999, 2000 VideoLAN
 *
6
 * Authors: Samuel Hocevar <sam@zoy.org>
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

23
#define CPU_CAPABILITY_NONE    0
24 25 26 27 28 29
#define CPU_CAPABILITY_486     1<<0
#define CPU_CAPABILITY_586     1<<1
#define CPU_CAPABILITY_PPRO    1<<2
#define CPU_CAPABILITY_MMX     1<<3
#define CPU_CAPABILITY_3DNOW   1<<4
#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 36
int TestProgram( char * psz_program );
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 47 48 49 50 51
#ifdef SYS_BEOS
    return( CPU_CAPABILITY_NONE
            | CPU_CAPABILITY_486
            | CPU_CAPABILITY_586
            | CPU_CAPABILITY_MMX );
#else
52
    int           i_capabilities = CPU_CAPABILITY_NONE;
53
#ifdef __i386__
54 55
    unsigned int  i_eax, i_ebx, i_ecx, i_edx;
    boolean_t     b_amd;
56 57 58 59 60 61 62 63 64

#define cpuid( a )                 \
    asm volatile ( "cpuid"         \
                 : "=a" ( i_eax ), \
                   "=b" ( i_ebx ), \
                   "=c" ( i_ecx ), \
                   "=d" ( i_edx )  \
                 : "a"  ( a )      \
                 : "cc" );         \
65

66
    /* test for a 486 CPU */
67 68
    asm volatile ( "pushfl
                    popl %%eax
69 70
                    movl %%eax, %%ebx
                    xorl $0x200000, %%eax
71 72 73
                    pushl %%eax
                    popfl
                    pushfl
74 75 76 77 78
                    popl %%eax"
                 : "=a" ( i_eax ),
                   "=b" ( i_ebx )
                 :
                 : "cc" );
79

80
    if( i_eax == i_ebx )
81
    {
82
        return( i_capabilities );
83 84
    }

85 86 87 88
    i_capabilities |= CPU_CAPABILITY_486;

    /* the CPU supports the CPUID instruction - get its level */
    cpuid( 0x00000000 );
89

90
    if( !i_eax )
91
    {
92
        return( i_capabilities );
93 94
    }

95 96 97 98 99 100 101 102 103
    /* FIXME: this isn't correct, since some 486s have cpuid */
    i_capabilities |= CPU_CAPABILITY_586;

    /* borrowed from mpeg2dec */
    b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
                    && ( i_edx == 0x69746e65 );

    /* test for the MMX flag */
    cpuid( 0x00000001 );
104

105
    if( ! (i_edx & 0x00800000) )
106
    {
107
        return( i_capabilities );
108 109
    }

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    i_capabilities |= CPU_CAPABILITY_MMX;

    if( i_edx & 0x02000000 )
    {
        i_capabilities |= CPU_CAPABILITY_MMXEXT;
    }
    
    /* test for additional capabilities */
    cpuid( 0x80000000 );

    if( i_eax < 0x80000001 )
    {
        return( i_capabilities );
    }

    /* list these additional capabilities */
    cpuid( 0x80000001 );

    if( i_edx & 0x80000000 )
    {
        i_capabilities |= CPU_CAPABILITY_3DNOW;
    }
132

133
    if( b_amd && ( i_edx & 0x00400000 ) )
134
    {
135
        i_capabilities |= CPU_CAPABILITY_MMXEXT;
136
    }
137
#endif /* __i386__ */
138

139
    return( i_capabilities );
140
#endif /* SYS_BEOS */
141
}
142