1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-25 17:58:27 +00:00

cpu detection fixed

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2273 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
arpi 2001-10-19 02:00:45 +00:00
parent f8c68da092
commit a16cebf64a
3 changed files with 70 additions and 31 deletions

View File

@ -16,7 +16,7 @@ PRG_CFG = codec-cfg
#prefix = /usr/local #prefix = /usr/local
BINDIR = ${prefix}/bin BINDIR = ${prefix}/bin
# BINDIR = /usr/local/bin # BINDIR = /usr/local/bin
SRCS = postproc/swscale.c postproc/postprocess.c mp_msg.c open.c parse_es.c ac3-iec958.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demux_mov.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c xa/rle8.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS) SRCS = cpudetect.c postproc/swscale.c postproc/postprocess.c mp_msg.c open.c parse_es.c ac3-iec958.c find_sub.c aviprint.c dec_audio.c dec_video.c aviwrite.c aviheader.c asfheader.c demux_avi.c demux_asf.c demux_mpg.c demux_mov.c demuxer.c stream.c codec-cfg.c subreader.c linux/getch2.c linux/timer-lx.c linux/shmem.c xa/xa_gsm.c xa/rle8.c lirc_mp.c cfgparser.c mixer.c dvdauth.c spudec.c $(STREAM_SRCS)
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall CFLAGS = $(OPTFLAGS) -Iloader -Ilibvo $(CSS_INC) $(EXTRA_INC) # -Wall
A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB) A_LIBS = -Lmp3lib -lMP3 -Llibac3 -lac3 $(ALSA_LIB) $(ESD_LIB)

View File

@ -14,7 +14,7 @@
#include <signal.h> #include <signal.h>
#endif #endif
#define X86_FXSR_MAGIC //#define X86_FXSR_MAGIC
/* Thanks to the FreeBSD project for some of this cpuid code, and /* Thanks to the FreeBSD project for some of this cpuid code, and
* help understanding how to use it. Thanks to the Mesa * help understanding how to use it. Thanks to the Mesa
* team for SSE support detection and more cpu detect code. * team for SSE support detection and more cpu detect code.
@ -25,40 +25,58 @@
CpuCaps gCpuCaps; CpuCaps gCpuCaps;
static void check_os_katmai_support( void ); static void check_os_katmai_support( void );
#if 0 #if 1
// return TRUE if cpuid supported
static int has_cpuid() static int has_cpuid()
{ {
int a, c; int a, c;
__asm __volatile(
"pushl %%ebx;" // code from libavcodec:
/* Test for the CPUID command. If the ID Flag bit in EFLAGS __asm__ __volatile__ (
* (bit 21) is writable, the CPUID command is present */ /* See if CPUID instruction is supported ... */
"pushfl;" /* ... Get copies of EFLAGS into eax and ecx */
"popl %%eax;" "pushf\n\t"
"movl %%ecx, %%eax;" "popl %0\n\t"
"xorl %%eax, 0x00200000;" "movl %0, %1\n\t"
"push %%eax;"
"popfl;" /* ... Toggle the ID bit in one copy and store */
"pushfl;" /* to the EFLAGS reg */
"popl %%eax;" "xorl $0x200000, %0\n\t"
"popl %%ebx" "push %0\n\t"
: "=a" (a), "=c" (c) "popf\n\t"
:
: "cx" /* ... Get the (hopefully modified) EFLAGS */
); "pushf\n\t"
/* FIXME: I have no clue on intel assembly. */ "popl %0\n\t"
return (a==c); : "=a" (a), "=c" (c)
:
: "cc"
);
return (a!=c);
} }
#endif #endif
static void static void
do_cpuid(unsigned int ax, unsigned int *p) do_cpuid(unsigned int ax, unsigned int *p)
{ {
#if 0
__asm __volatile( __asm __volatile(
"cpuid;" "cpuid;"
: "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
: "0" (ax) : "0" (ax)
); );
#else
// code from libavcodec:
__asm __volatile
("movl %%ebx, %%esi\n\t"
"cpuid\n\t"
"xchgl %%ebx, %%esi"
: "=a" (p[0]), "=S" (p[1]),
"=c" (p[2]), "=d" (p[3])
: "0" (ax));
#endif
} }
@ -68,11 +86,14 @@ void GetCpuCaps( CpuCaps *caps)
unsigned int regs2[4]; unsigned int regs2[4];
bzero(caps, sizeof(*caps)); bzero(caps, sizeof(*caps));
printf("CPUid available: %s\n",has_cpuid()?"yes":"no");
/*if (!has_cpuid()) /*if (!has_cpuid())
return;*/ return;*/
do_cpuid(0x00000000, regs); do_cpuid(0x00000000, regs);
printf("CPU vendor name: %.4s%.4s%.4s\n",&regs[1],&regs[3],&regs[2]);
if (regs[0]>0x00000001) { if (regs[0]>0x00000001) {
do_cpuid(0x00000001, regs2); do_cpuid(0x00000001, regs2);
printf("CPU family: %d\n",(regs2[0] >> 8)&0xf);
switch ((regs2[0] >> 8)&0xf) { switch ((regs2[0] >> 8)&0xf) {
case 3: case 3:
caps->cpuType=CPUTYPE_I386; caps->cpuType=CPUTYPE_I386;
@ -90,9 +111,11 @@ void GetCpuCaps( CpuCaps *caps)
printf("Unknown cpu type, default to i386\n"); printf("Unknown cpu type, default to i386\n");
break; break;
} }
caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25;
caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // FIXME: is this ok for non-intel CPUs too? (cyrix,amd)
caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25; // 0x2000000
caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // 0x4000000
/* FIXME: Does SSE2 need more OS support, too? */ /* FIXME: Does SSE2 need more OS support, too? */
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__)
if (caps->hasSSE) if (caps->hasSSE)
@ -106,15 +129,18 @@ void GetCpuCaps( CpuCaps *caps)
/* FIXME: Are MMX2 ops on the same set of processors as SSE? Do they need OS support?*/ /* FIXME: Are MMX2 ops on the same set of processors as SSE? Do they need OS support?*/
caps->hasMMX2 = caps->hasSSE; caps->hasMMX2 = caps->hasSSE;
} }
if (memcmp(&regs[1], "AuthenticAMD", 12)) { if (regs[1] == 0x68747541 && // AuthenticAMD
regs[3] == 0x69746e65 &&
regs[2] == 0x444d4163) {
do_cpuid(0x80000000, regs); do_cpuid(0x80000000, regs);
if (regs[0]>0x80000001) { if (regs[0]>=0x80000001) {
do_cpuid(0x80000001, regs2); do_cpuid(0x80000001, regs2);
/*caps->hasMMX2 = regs[3] & (1 << 23 );*/ caps->hasMMX2 = (regs[3] & (1 << 22 )) >> 22; // 0x400000
caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; //0x80000000
caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30; caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30;
} }
} }
#if 0
printf("cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n", printf("cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n",
gCpuCaps.hasMMX, gCpuCaps.hasMMX,
gCpuCaps.hasMMX2, gCpuCaps.hasMMX2,
@ -122,6 +148,7 @@ void GetCpuCaps( CpuCaps *caps)
gCpuCaps.hasSSE2, gCpuCaps.hasSSE2,
gCpuCaps.has3DNow, gCpuCaps.has3DNow,
gCpuCaps.has3DNowExt ); gCpuCaps.has3DNowExt );
#endif
} }
@ -203,7 +230,8 @@ static void check_os_katmai_support( void )
if ( gCpuCaps.hasSSE ) { if ( gCpuCaps.hasSSE ) {
printf( "Testing OS support for SSE... " ); printf( "Testing OS support for SSE... " );
__asm __volatile ("xorps %%xmm0, %%xmm0"); // __asm __volatile ("xorps %%xmm0, %%xmm0");
__asm __volatile ("xorps %xmm0, %xmm0");
if ( gCpuCaps.hasSSE ) { if ( gCpuCaps.hasSSE ) {
printf( "yes.\n" ); printf( "yes.\n" );
@ -228,7 +256,7 @@ static void check_os_katmai_support( void )
if ( gCpuCaps.hasSSE ) { if ( gCpuCaps.hasSSE ) {
printf( "Testing OS support for SSE unmasked exceptions... " ); printf( "Testing OS support for SSE unmasked exceptions... " );
test_os_katmai_exception_support(); // test_os_katmai_exception_support();
if ( gCpuCaps.hasSSE ) { if ( gCpuCaps.hasSSE ) {
printf( "yes.\n" ); printf( "yes.\n" );

View File

@ -66,6 +66,8 @@ void* mDisplay; // Display* mDisplay;
#include "linux/timer.h" #include "linux/timer.h"
#include "linux/shmem.h" #include "linux/shmem.h"
#include "cpudetect.h"
#ifdef HAVE_LIRC #ifdef HAVE_LIRC
#include "lirc_mp.h" #include "lirc_mp.h"
#endif #endif
@ -472,6 +474,15 @@ int gui_no_filename=0;
mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text); mp_msg(MSGT_CPLAYER,MSGL_INFO,"%s",banner_text);
/* Test for cpu capabilities (and corresponding OS support) for optimizing */
#ifdef ARCH_X86
GetCpuCaps(&gCpuCaps);
mp_msg(MSGT_CPLAYER,MSGL_INFO,"CPUflags: Type: %d MMX: %d MMX2: %d 3DNow: %d 3DNow2: %d SSE: %d SSE2: %d\n",
gCpuCaps.cpuType,gCpuCaps.hasMMX,gCpuCaps.hasMMX2,
gCpuCaps.has3DNow, gCpuCaps.has3DNowExt,
gCpuCaps.hasSSE, gCpuCaps.hasSSE2);
#endif
// this one segfaults if running 'mplayer' (without path containing '/') // this one segfaults if running 'mplayer' (without path containing '/')
// if ( !strcmp( strrchr( argv[0],'/' ),"/gmplayer" ) ) appInit( argc,argv,envp ); // if ( !strcmp( strrchr( argv[0],'/' ),"/gmplayer" ) ) appInit( argc,argv,envp );
if ( argv[0] ) if ( argv[0] )