2001-10-19 02:40:19 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "cpudetect.h"
|
2002-05-02 13:00:16 +02:00
|
|
|
#include "mp_msg.h"
|
2001-10-19 02:40:19 +02:00
|
|
|
|
2001-11-27 00:08:48 +01:00
|
|
|
CpuCaps gCpuCaps;
|
|
|
|
|
2001-12-28 19:03:03 +01:00
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2006-11-01 19:41:25 +01:00
|
|
|
#ifdef ARCH_X86
|
2001-10-19 02:40:19 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2002-11-07 00:54:29 +01:00
|
|
|
#include <string.h>
|
2001-10-19 02:40:19 +02:00
|
|
|
|
2004-04-06 19:08:02 +02:00
|
|
|
#if defined (__NetBSD__) || defined(__OpenBSD__)
|
2002-12-07 22:04:54 +01:00
|
|
|
#include <sys/param.h>
|
2002-12-23 02:24:42 +01:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <machine/cpu.h>
|
2002-12-07 22:04:54 +01:00
|
|
|
#endif
|
|
|
|
|
2008-02-24 13:05:20 +01:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
|
2001-10-19 02:40:19 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-19 14:25:18 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2008-02-24 19:09:28 +01:00
|
|
|
#ifdef __OS2__
|
|
|
|
#define INCL_DOS
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
|
|
|
|
2006-03-01 00:24:38 +01:00
|
|
|
#ifdef __AMIGAOS4__
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
/* Thanks to the FreeBSD project for some of this cpuid code, and
|
|
|
|
* help understanding how to use it. Thanks to the Mesa
|
|
|
|
* team for SSE support detection and more cpu detect code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* I believe this code works. However, it has only been used on a PII and PIII */
|
|
|
|
|
|
|
|
static void check_os_katmai_support( void );
|
|
|
|
|
2001-10-19 04:00:45 +02:00
|
|
|
#if 1
|
|
|
|
// return TRUE if cpuid supported
|
2006-02-09 15:08:03 +01:00
|
|
|
static int has_cpuid(void)
|
2001-10-19 02:40:19 +02:00
|
|
|
{
|
2004-10-21 13:55:20 +02:00
|
|
|
long a, c;
|
2001-10-19 04:00:45 +02:00
|
|
|
|
|
|
|
// code from libavcodec:
|
|
|
|
__asm__ __volatile__ (
|
|
|
|
/* See if CPUID instruction is supported ... */
|
|
|
|
/* ... Get copies of EFLAGS into eax and ecx */
|
|
|
|
"pushf\n\t"
|
2004-10-21 13:55:20 +02:00
|
|
|
"pop %0\n\t"
|
|
|
|
"mov %0, %1\n\t"
|
2001-10-19 04:00:45 +02:00
|
|
|
|
|
|
|
/* ... Toggle the ID bit in one copy and store */
|
|
|
|
/* to the EFLAGS reg */
|
2004-10-21 13:55:20 +02:00
|
|
|
"xor $0x200000, %0\n\t"
|
2001-10-19 04:00:45 +02:00
|
|
|
"push %0\n\t"
|
|
|
|
"popf\n\t"
|
|
|
|
|
|
|
|
/* ... Get the (hopefully modified) EFLAGS */
|
|
|
|
"pushf\n\t"
|
2004-10-21 13:55:20 +02:00
|
|
|
"pop %0\n\t"
|
2001-10-19 04:00:45 +02:00
|
|
|
: "=a" (a), "=c" (c)
|
|
|
|
:
|
|
|
|
: "cc"
|
|
|
|
);
|
|
|
|
|
|
|
|
return (a!=c);
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_cpuid(unsigned int ax, unsigned int *p)
|
|
|
|
{
|
2001-10-19 04:00:45 +02:00
|
|
|
#if 0
|
2001-10-19 02:40:19 +02:00
|
|
|
__asm __volatile(
|
|
|
|
"cpuid;"
|
|
|
|
: "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3])
|
|
|
|
: "0" (ax)
|
|
|
|
);
|
2001-10-19 04:00:45 +02:00
|
|
|
#else
|
|
|
|
// code from libavcodec:
|
|
|
|
__asm __volatile
|
2004-10-21 13:55:20 +02:00
|
|
|
("mov %%"REG_b", %%"REG_S"\n\t"
|
2001-10-19 04:00:45 +02:00
|
|
|
"cpuid\n\t"
|
2004-10-21 13:55:20 +02:00
|
|
|
"xchg %%"REG_b", %%"REG_S
|
2001-12-09 18:03:04 +01:00
|
|
|
: "=a" (p[0]), "=S" (p[1]),
|
2001-10-19 04:00:45 +02:00
|
|
|
"=c" (p[2]), "=d" (p[3])
|
|
|
|
: "0" (ax));
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCpuCaps( CpuCaps *caps)
|
|
|
|
{
|
|
|
|
unsigned int regs[4];
|
|
|
|
unsigned int regs2[4];
|
2001-11-27 00:08:48 +01:00
|
|
|
|
2001-12-24 11:35:43 +01:00
|
|
|
memset(caps, 0, sizeof(*caps));
|
2003-01-09 19:39:09 +01:00
|
|
|
caps->isX86=1;
|
|
|
|
caps->cl_size=32; /* default */
|
2001-10-19 16:02:12 +02:00
|
|
|
if (!has_cpuid()) {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"CPUID not supported!??? (maybe an old 486?)\n");
|
2001-10-19 16:02:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
do_cpuid(0x00000000, regs); // get _max_ cpuid level and vendor name
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V,"CPU vendor name: %.4s%.4s%.4s max cpuid level: %d\n",
|
2001-12-28 19:03:03 +01:00
|
|
|
(char*) (regs+1),(char*) (regs+3),(char*) (regs+2), regs[0]);
|
2001-10-19 16:02:12 +02:00
|
|
|
if (regs[0]>=0x00000001)
|
2001-10-19 15:01:31 +02:00
|
|
|
{
|
2006-05-17 23:10:11 +02:00
|
|
|
char *tmpstr, *ptmpstr;
|
2003-01-09 19:39:09 +01:00
|
|
|
unsigned cl_size;
|
2001-11-27 00:08:48 +01:00
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
do_cpuid(0x00000001, regs2);
|
2001-10-20 04:35:31 +02:00
|
|
|
|
2001-10-19 16:02:12 +02:00
|
|
|
caps->cpuType=(regs2[0] >> 8)&0xf;
|
2006-05-17 23:10:11 +02:00
|
|
|
caps->cpuModel=(regs2[0] >> 4)&0xf;
|
2005-10-04 23:06:07 +02:00
|
|
|
|
|
|
|
// see AMD64 Architecture Programmer's Manual, Volume 3: General-purpose and
|
|
|
|
// System Instructions, Table 3-2: Effective family computation, page 120.
|
2001-10-19 16:02:12 +02:00
|
|
|
if(caps->cpuType==0xf){
|
2005-10-04 23:06:07 +02:00
|
|
|
// use extended family (P4, IA64, K8)
|
|
|
|
caps->cpuType=0xf+((regs2[0]>>20)&255);
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
2006-05-17 23:10:11 +02:00
|
|
|
if(caps->cpuType==0xf || caps->cpuType==6)
|
|
|
|
caps->cpuModel |= ((regs2[0]>>16)&0xf) << 4;
|
|
|
|
|
2001-12-09 18:03:04 +01:00
|
|
|
caps->cpuStepping=regs2[0] & 0xf;
|
2001-10-19 16:02:12 +02:00
|
|
|
|
|
|
|
// general feature flags:
|
2003-09-20 01:52:41 +02:00
|
|
|
caps->hasTSC = (regs2[3] & (1 << 8 )) >> 8; // 0x0000010
|
2001-10-19 04:00:45 +02:00
|
|
|
caps->hasMMX = (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
|
|
|
|
caps->hasSSE = (regs2[3] & (1 << 25 )) >> 25; // 0x2000000
|
|
|
|
caps->hasSSE2 = (regs2[3] & (1 << 26 )) >> 26; // 0x4000000
|
2001-10-19 16:02:12 +02:00
|
|
|
caps->hasMMX2 = caps->hasSSE; // SSE cpus supports mmxext too
|
2003-01-09 19:39:09 +01:00
|
|
|
cl_size = ((regs2[1] >> 8) & 0xFF)*8;
|
|
|
|
if(cl_size) caps->cl_size = cl_size;
|
2003-09-20 01:52:41 +02:00
|
|
|
|
2006-05-17 23:10:11 +02:00
|
|
|
ptmpstr=tmpstr=GetCpuFriendlyName(regs, regs2);
|
2006-06-25 19:37:58 +02:00
|
|
|
while(*ptmpstr == ' ') // strip leading spaces
|
2006-05-17 23:10:11 +02:00
|
|
|
ptmpstr++;
|
2006-06-25 19:37:58 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: %s ", ptmpstr);
|
2003-09-20 01:52:41 +02:00
|
|
|
free(tmpstr);
|
2006-05-17 23:10:11 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"(Family: %d, Model: %d, Stepping: %d)\n",
|
|
|
|
caps->cpuType, caps->cpuModel, caps->cpuStepping);
|
2003-09-20 01:52:41 +02:00
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
2001-10-19 16:02:12 +02:00
|
|
|
do_cpuid(0x80000000, regs);
|
|
|
|
if (regs[0]>=0x80000001) {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V,"extended cpuid-level: %d\n",regs[0]&0x7FFFFFFF);
|
2001-10-19 16:02:12 +02:00
|
|
|
do_cpuid(0x80000001, regs2);
|
2001-12-28 19:23:35 +01:00
|
|
|
caps->hasMMX |= (regs2[3] & (1 << 23 )) >> 23; // 0x0800000
|
|
|
|
caps->hasMMX2 |= (regs2[3] & (1 << 22 )) >> 22; // 0x400000
|
2001-10-19 16:02:12 +02:00
|
|
|
caps->has3DNow = (regs2[3] & (1 << 31 )) >> 31; //0x80000000
|
|
|
|
caps->has3DNowExt = (regs2[3] & (1 << 30 )) >> 30;
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
2003-01-09 19:39:09 +01:00
|
|
|
if(regs[0]>=0x80000006)
|
|
|
|
{
|
|
|
|
do_cpuid(0x80000006, regs2);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V,"extended cache-info: %d\n",regs2[2]&0x7FFFFFFF);
|
|
|
|
caps->cl_size = regs2[2] & 0xFF;
|
|
|
|
}
|
2005-11-07 17:16:14 +01:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V,"Detected cache-line size is %u bytes\n",caps->cl_size);
|
2001-10-19 04:00:45 +02:00
|
|
|
#if 0
|
2002-05-02 13:00:16 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n",
|
2001-10-19 02:40:19 +02:00
|
|
|
gCpuCaps.hasMMX,
|
|
|
|
gCpuCaps.hasMMX2,
|
|
|
|
gCpuCaps.hasSSE,
|
|
|
|
gCpuCaps.hasSSE2,
|
|
|
|
gCpuCaps.has3DNow,
|
|
|
|
gCpuCaps.has3DNowExt );
|
2001-10-19 04:00:45 +02:00
|
|
|
#endif
|
2001-10-19 02:40:19 +02:00
|
|
|
|
2001-10-19 16:02:12 +02:00
|
|
|
/* FIXME: Does SSE2 need more OS support, too? */
|
2008-02-24 19:04:34 +01:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|
|
|
|
|| defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) \
|
2008-02-24 19:09:28 +01:00
|
|
|
|| defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) \
|
|
|
|
|| defined(__OS2__)
|
2001-10-19 16:02:12 +02:00
|
|
|
if (caps->hasSSE)
|
|
|
|
check_os_katmai_support();
|
|
|
|
if (!caps->hasSSE)
|
|
|
|
caps->hasSSE2 = 0;
|
|
|
|
#else
|
|
|
|
caps->hasSSE=0;
|
|
|
|
caps->hasSSE2 = 0;
|
|
|
|
#endif
|
2001-11-27 00:08:48 +01:00
|
|
|
// caps->has3DNow=1;
|
|
|
|
// caps->hasMMX2 = 0;
|
|
|
|
// caps->hasMMX = 0;
|
2001-10-19 16:02:12 +02:00
|
|
|
|
2008-02-24 19:21:41 +01:00
|
|
|
#ifndef RUNTIME_CPUDETECT
|
2002-02-24 02:24:18 +01:00
|
|
|
#ifndef HAVE_MMX
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->hasMMX) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"MMX supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->hasMMX=0;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_MMX2
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->hasMMX2) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"MMX2 supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->hasMMX2=0;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_SSE
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->hasSSE) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"SSE supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->hasSSE=0;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_SSE2
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->hasSSE2) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"SSE2 supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->hasSSE2=0;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_3DNOW
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->has3DNow) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"3DNow supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->has3DNow=0;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_3DNOWEX
|
2002-05-20 02:55:50 +02:00
|
|
|
if(caps->has3DNowExt) mp_msg(MSGT_CPUDETECT,MSGL_WARN,"3DNowExt supported but disabled\n");
|
2002-02-24 02:24:18 +01:00
|
|
|
caps->has3DNowExt=0;
|
|
|
|
#endif
|
2008-02-24 19:21:41 +01:00
|
|
|
#endif // RUNTIME_CPUDETECT
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
|
|
|
|
2001-10-20 04:35:31 +02:00
|
|
|
|
|
|
|
#define CPUID_EXTFAMILY ((regs2[0] >> 20)&0xFF) /* 27..20 */
|
|
|
|
#define CPUID_EXTMODEL ((regs2[0] >> 16)&0x0F) /* 19..16 */
|
|
|
|
#define CPUID_TYPE ((regs2[0] >> 12)&0x04) /* 13..12 */
|
|
|
|
#define CPUID_FAMILY ((regs2[0] >> 8)&0x0F) /* 11..08 */
|
|
|
|
#define CPUID_MODEL ((regs2[0] >> 4)&0x0F) /* 07..04 */
|
|
|
|
#define CPUID_STEPPING ((regs2[0] >> 0)&0x0F) /* 03..00 */
|
|
|
|
|
|
|
|
char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]){
|
|
|
|
#include "cputable.h" /* get cpuname and cpuvendors */
|
2006-05-17 23:10:11 +02:00
|
|
|
char vendor[13];
|
2001-10-20 13:16:47 +02:00
|
|
|
char *retname;
|
2004-10-13 11:37:32 +02:00
|
|
|
int i;
|
2001-10-20 04:35:31 +02:00
|
|
|
|
2006-07-01 05:56:13 +02:00
|
|
|
if (NULL==(retname=malloc(256))) {
|
2002-05-02 13:00:16 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_FATAL,"Error: GetCpuFriendlyName() not enough memory\n");
|
2001-10-20 13:16:47 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-12-28 19:03:03 +01:00
|
|
|
sprintf(vendor,"%.4s%.4s%.4s",(char*)(regs+1),(char*)(regs+3),(char*)(regs+2));
|
2001-11-27 00:08:48 +01:00
|
|
|
|
2006-05-17 23:10:11 +02:00
|
|
|
do_cpuid(0x80000000,regs);
|
|
|
|
if (regs[0] >= 0x80000004)
|
|
|
|
{
|
|
|
|
// CPU has built-in namestring
|
|
|
|
retname[0] = '\0';
|
|
|
|
for (i = 0x80000002; i <= 0x80000004; i++)
|
|
|
|
{
|
|
|
|
do_cpuid(i, regs);
|
|
|
|
strncat(retname, (char*)regs, 16);
|
|
|
|
}
|
|
|
|
return retname;
|
|
|
|
}
|
|
|
|
|
2001-10-20 04:35:31 +02:00
|
|
|
for(i=0; i<MAX_VENDORS; i++){
|
|
|
|
if(!strcmp(cpuvendors[i].string,vendor)){
|
|
|
|
if(cpuname[i][CPUID_FAMILY][CPUID_MODEL]){
|
2004-10-13 11:37:32 +02:00
|
|
|
snprintf(retname,255,"%s %s",cpuvendors[i].name,cpuname[i][CPUID_FAMILY][CPUID_MODEL]);
|
2001-10-20 04:35:31 +02:00
|
|
|
} else {
|
2004-10-13 11:37:32 +02:00
|
|
|
snprintf(retname,255,"unknown %s %d. Generation CPU",cpuvendors[i].name,CPUID_FAMILY);
|
2002-05-02 13:00:16 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"unknown %s CPU:\n",cpuvendors[i].name);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Vendor: %s\n",cpuvendors[i].string);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Type: %d\n",CPUID_TYPE);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Family: %d (ext: %d)\n",CPUID_FAMILY,CPUID_EXTFAMILY);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Model: %d (ext: %d)\n",CPUID_MODEL,CPUID_EXTMODEL);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Stepping: %d\n",CPUID_STEPPING);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN,"Please send the above info along with the exact CPU name"
|
2001-10-20 04:35:31 +02:00
|
|
|
"to the MPlayer-Developers, so we can add it to the list!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-12 22:56:25 +01:00
|
|
|
retname[255] = 0;
|
2001-10-20 04:35:31 +02:00
|
|
|
|
|
|
|
//printf("Detected CPU: %s\n", retname);
|
|
|
|
return retname;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CPUID_EXTFAMILY
|
|
|
|
#undef CPUID_EXTMODEL
|
|
|
|
#undef CPUID_TYPE
|
|
|
|
#undef CPUID_FAMILY
|
|
|
|
#undef CPUID_MODEL
|
|
|
|
#undef CPUID_STEPPING
|
|
|
|
|
|
|
|
|
2007-09-14 16:19:22 +02:00
|
|
|
#if defined(__linux__) && defined(_POSIX_SOURCE) && !defined(ARCH_X86_64)
|
2001-10-19 02:40:19 +02:00
|
|
|
static void sigill_handler_sse( int signal, struct sigcontext sc )
|
|
|
|
{
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "SIGILL, " );
|
2001-10-19 02:40:19 +02:00
|
|
|
|
|
|
|
/* Both the "xorps %%xmm0,%%xmm0" and "divps %xmm0,%%xmm1"
|
|
|
|
* instructions are 3 bytes long. We must increment the instruction
|
|
|
|
* pointer manually to avoid repeated execution of the offending
|
|
|
|
* instruction.
|
|
|
|
*
|
|
|
|
* If the SIGILL is caused by a divide-by-zero when unmasked
|
|
|
|
* exceptions aren't supported, the SIMD FPU status and control
|
|
|
|
* word will be restored at the end of the test, so we don't need
|
|
|
|
* to worry about doing it here. Besides, we may not be able to...
|
|
|
|
*/
|
|
|
|
sc.eip += 3;
|
|
|
|
|
|
|
|
gCpuCaps.hasSSE=0;
|
|
|
|
}
|
2007-09-14 15:49:28 +02:00
|
|
|
#endif /* __linux__ && _POSIX_SOURCE */
|
2001-10-19 02:40:19 +02:00
|
|
|
|
2003-07-19 14:25:18 +02:00
|
|
|
#ifdef WIN32
|
|
|
|
LONG CALLBACK win32_sig_handler_sse(EXCEPTION_POINTERS* ep)
|
|
|
|
{
|
|
|
|
if(ep->ExceptionRecord->ExceptionCode==EXCEPTION_ILLEGAL_INSTRUCTION){
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "SIGILL, " );
|
|
|
|
ep->ContextRecord->Eip +=3;
|
|
|
|
gCpuCaps.hasSSE=0;
|
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2008-02-24 19:09:28 +01:00
|
|
|
#ifdef __OS2__
|
|
|
|
ULONG _System os2_sig_handler_sse( PEXCEPTIONREPORTRECORD p1,
|
|
|
|
PEXCEPTIONREGISTRATIONRECORD p2,
|
|
|
|
PCONTEXTRECORD p3,
|
|
|
|
PVOID p4 )
|
|
|
|
{
|
|
|
|
if(p1->ExceptionNum == XCPT_ILLEGAL_INSTRUCTION){
|
|
|
|
mp_msg(MSGT_CPUDETECT, MSGL_V, "SIGILL, ");
|
|
|
|
|
|
|
|
p3->ctx_RegEip += 3;
|
|
|
|
gCpuCaps.hasSSE = 0;
|
|
|
|
|
|
|
|
return XCPT_CONTINUE_EXECUTION;
|
|
|
|
}
|
|
|
|
return XCPT_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
/* If we're running on a processor that can do SSE, let's see if we
|
|
|
|
* are allowed to or not. This will catch 2.4.0 or later kernels that
|
|
|
|
* haven't been configured for a Pentium III but are running on one,
|
|
|
|
* and RedHat patched 2.2 kernels that have broken exception handling
|
|
|
|
* support for user space apps that do SSE.
|
|
|
|
*/
|
2006-10-05 02:12:04 +02:00
|
|
|
|
2007-01-10 15:56:23 +01:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
2006-10-05 02:12:04 +02:00
|
|
|
#define SSE_SYSCTL_NAME "hw.instruction_sse"
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#define SSE_SYSCTL_NAME "hw.optional.sse"
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 02:40:19 +02:00
|
|
|
static void check_os_katmai_support( void )
|
|
|
|
{
|
2005-01-10 19:33:51 +01:00
|
|
|
#ifdef ARCH_X86_64
|
|
|
|
gCpuCaps.hasSSE=1;
|
|
|
|
gCpuCaps.hasSSE2=1;
|
2007-01-10 15:56:23 +01:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
|
2001-10-19 02:40:19 +02:00
|
|
|
int has_sse=0, ret;
|
|
|
|
size_t len=sizeof(has_sse);
|
|
|
|
|
2006-10-05 02:12:04 +02:00
|
|
|
ret = sysctlbyname(SSE_SYSCTL_NAME, &has_sse, &len, NULL, 0);
|
2001-10-19 02:40:19 +02:00
|
|
|
if (ret || !has_sse)
|
|
|
|
gCpuCaps.hasSSE=0;
|
|
|
|
|
2004-04-06 19:08:02 +02:00
|
|
|
#elif defined(__NetBSD__) || defined (__OpenBSD__)
|
|
|
|
#if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
|
2002-12-23 02:24:42 +01:00
|
|
|
int has_sse, has_sse2, ret, mib[2];
|
|
|
|
size_t varlen;
|
|
|
|
|
|
|
|
mib[0] = CTL_MACHDEP;
|
|
|
|
mib[1] = CPU_SSE;
|
|
|
|
varlen = sizeof(has_sse);
|
|
|
|
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
|
|
|
|
ret = sysctl(mib, 2, &has_sse, &varlen, NULL, 0);
|
|
|
|
if (ret < 0 || !has_sse) {
|
|
|
|
gCpuCaps.hasSSE=0;
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
|
|
|
|
} else {
|
|
|
|
gCpuCaps.hasSSE=1;
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
mib[1] = CPU_SSE2;
|
|
|
|
varlen = sizeof(has_sse2);
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE2... " );
|
|
|
|
ret = sysctl(mib, 2, &has_sse2, &varlen, NULL, 0);
|
|
|
|
if (ret < 0 || !has_sse2) {
|
|
|
|
gCpuCaps.hasSSE2=0;
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
|
|
|
|
} else {
|
|
|
|
gCpuCaps.hasSSE2=1;
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "yes!\n" );
|
2002-12-07 22:04:54 +01:00
|
|
|
}
|
|
|
|
#else
|
2002-12-23 02:24:42 +01:00
|
|
|
gCpuCaps.hasSSE = 0;
|
2002-12-07 22:04:54 +01:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN, "No OS support for SSE, disabling to be safe.\n" );
|
|
|
|
#endif
|
2003-07-19 14:25:18 +02:00
|
|
|
#elif defined(WIN32)
|
|
|
|
LPTOP_LEVEL_EXCEPTION_FILTER exc_fil;
|
|
|
|
if ( gCpuCaps.hasSSE ) {
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
|
|
|
|
exc_fil = SetUnhandledExceptionFilter(win32_sig_handler_sse);
|
|
|
|
__asm __volatile ("xorps %xmm0, %xmm0");
|
|
|
|
SetUnhandledExceptionFilter(exc_fil);
|
|
|
|
if ( gCpuCaps.hasSSE ) mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" );
|
|
|
|
else mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
|
|
|
|
}
|
2008-02-24 19:09:28 +01:00
|
|
|
#elif defined(__OS2__)
|
|
|
|
EXCEPTIONREGISTRATIONRECORD RegRec = { 0, &os2_sig_handler_sse };
|
|
|
|
if ( gCpuCaps.hasSSE ) {
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
|
|
|
|
DosSetExceptionHandler( &RegRec );
|
|
|
|
__asm __volatile ("xorps %xmm0, %xmm0");
|
|
|
|
DosUnsetExceptionHandler( &RegRec );
|
|
|
|
if ( gCpuCaps.hasSSE ) mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" );
|
|
|
|
else mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
|
|
|
|
}
|
2001-10-19 02:40:19 +02:00
|
|
|
#elif defined(__linux__)
|
2007-09-14 15:49:28 +02:00
|
|
|
#if defined(_POSIX_SOURCE)
|
2001-10-19 02:40:19 +02:00
|
|
|
struct sigaction saved_sigill;
|
|
|
|
|
|
|
|
/* Save the original signal handlers.
|
|
|
|
*/
|
|
|
|
sigaction( SIGILL, NULL, &saved_sigill );
|
|
|
|
|
|
|
|
signal( SIGILL, (void (*)(int))sigill_handler_sse );
|
|
|
|
|
|
|
|
/* Emulate test for OSFXSR in CR4. The OS will set this bit if it
|
|
|
|
* supports the extended FPU save and restore required for SSE. If
|
|
|
|
* we execute an SSE instruction on a PIII and get a SIGILL, the OS
|
|
|
|
* doesn't support Streaming SIMD Exceptions, even if the processor
|
|
|
|
* does.
|
|
|
|
*/
|
|
|
|
if ( gCpuCaps.hasSSE ) {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Testing OS support for SSE... " );
|
2001-10-19 02:40:19 +02:00
|
|
|
|
2001-10-19 04:00:45 +02:00
|
|
|
// __asm __volatile ("xorps %%xmm0, %%xmm0");
|
|
|
|
__asm __volatile ("xorps %xmm0, %xmm0");
|
2001-10-19 02:40:19 +02:00
|
|
|
|
|
|
|
if ( gCpuCaps.hasSSE ) {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "yes.\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
} else {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "no!\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the original signal handlers.
|
|
|
|
*/
|
|
|
|
sigaction( SIGILL, &saved_sigill, NULL );
|
|
|
|
|
|
|
|
/* If we've gotten to here and the XMM CPUID bit is still set, we're
|
|
|
|
* safe to go ahead and hook out the SSE code throughout Mesa.
|
|
|
|
*/
|
|
|
|
if ( gCpuCaps.hasSSE ) {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Tests of OS support for SSE passed.\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
} else {
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_V, "Tests of OS support for SSE failed!\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* We can't use POSIX signal handling to test the availability of
|
|
|
|
* SSE, so we disable it by default.
|
|
|
|
*/
|
2002-05-02 13:00:16 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Cannot test OS support for SSE, disabling to be safe.\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
gCpuCaps.hasSSE=0;
|
2007-09-14 15:49:28 +02:00
|
|
|
#endif /* _POSIX_SOURCE */
|
2001-10-19 02:40:19 +02:00
|
|
|
#else
|
|
|
|
/* Do nothing on other platforms for now.
|
|
|
|
*/
|
2002-05-20 02:55:50 +02:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_WARN, "Cannot test OS support for SSE, leaving disabled.\n" );
|
2001-10-19 02:40:19 +02:00
|
|
|
gCpuCaps.hasSSE=0;
|
|
|
|
#endif /* __linux__ */
|
|
|
|
}
|
2006-11-01 19:41:25 +01:00
|
|
|
#else /* ARCH_X86 */
|
2001-11-27 00:08:48 +01:00
|
|
|
|
2007-12-11 21:27:13 +01:00
|
|
|
#ifdef __APPLE__
|
2003-01-18 20:29:46 +01:00
|
|
|
#include <sys/sysctl.h>
|
2007-12-11 23:29:22 +01:00
|
|
|
#elif __AMIGAOS4__
|
|
|
|
/* nothing */
|
|
|
|
#else
|
2003-01-18 20:29:46 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
static sigjmp_buf jmpbuf;
|
|
|
|
static volatile sig_atomic_t canjump = 0;
|
|
|
|
|
|
|
|
static void sigill_handler (int sig)
|
|
|
|
{
|
|
|
|
if (!canjump) {
|
|
|
|
signal (sig, SIG_DFL);
|
|
|
|
raise (sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
canjump = 0;
|
|
|
|
siglongjmp (jmpbuf, 1);
|
|
|
|
}
|
2007-12-11 21:27:13 +01:00
|
|
|
#endif /* __APPLE__ */
|
2003-01-18 20:29:46 +01:00
|
|
|
|
2001-11-27 00:08:48 +01:00
|
|
|
void GetCpuCaps( CpuCaps *caps)
|
|
|
|
{
|
|
|
|
caps->cpuType=0;
|
2006-05-17 23:10:11 +02:00
|
|
|
caps->cpuModel=0;
|
2001-12-09 18:03:04 +01:00
|
|
|
caps->cpuStepping=0;
|
2001-11-27 00:08:48 +01:00
|
|
|
caps->hasMMX=0;
|
|
|
|
caps->hasMMX2=0;
|
|
|
|
caps->has3DNow=0;
|
|
|
|
caps->has3DNowExt=0;
|
|
|
|
caps->hasSSE=0;
|
|
|
|
caps->hasSSE2=0;
|
|
|
|
caps->isX86=0;
|
2003-01-18 20:29:46 +01:00
|
|
|
caps->hasAltiVec = 0;
|
|
|
|
#ifdef HAVE_ALTIVEC
|
2007-12-11 21:27:13 +01:00
|
|
|
#ifdef __APPLE__
|
2003-01-18 20:29:46 +01:00
|
|
|
/*
|
|
|
|
rip-off from ffmpeg altivec detection code.
|
|
|
|
this code also appears on Apple's AltiVec pages.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int sels[2] = {CTL_HW, HW_VECTORUNIT};
|
|
|
|
int has_vu = 0;
|
|
|
|
size_t len = sizeof(has_vu);
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
|
|
|
|
|
|
|
|
if (err == 0)
|
|
|
|
if (has_vu != 0)
|
|
|
|
caps->hasAltiVec = 1;
|
|
|
|
}
|
2007-12-11 23:31:57 +01:00
|
|
|
#elif __AMIGAOS4__
|
2006-03-01 00:24:38 +01:00
|
|
|
ULONG result = 0;
|
|
|
|
|
|
|
|
GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
|
|
|
|
if (result == VECTORTYPE_ALTIVEC)
|
|
|
|
caps->hasAltiVec = 1;
|
|
|
|
#else
|
2003-01-18 20:29:46 +01:00
|
|
|
/* no Darwin, do it the brute-force way */
|
|
|
|
/* this is borrowed from the libmpeg2 library */
|
|
|
|
{
|
|
|
|
signal (SIGILL, sigill_handler);
|
|
|
|
if (sigsetjmp (jmpbuf, 1)) {
|
|
|
|
signal (SIGILL, SIG_DFL);
|
|
|
|
} else {
|
|
|
|
canjump = 1;
|
|
|
|
|
|
|
|
asm volatile ("mtspr 256, %0\n\t"
|
2003-01-27 22:47:25 +01:00
|
|
|
"vand %%v0, %%v0, %%v0"
|
2003-01-18 20:29:46 +01:00
|
|
|
:
|
|
|
|
: "r" (-1));
|
|
|
|
|
|
|
|
signal (SIGILL, SIG_DFL);
|
|
|
|
caps->hasAltiVec = 1;
|
|
|
|
}
|
|
|
|
}
|
2007-12-11 21:27:13 +01:00
|
|
|
#endif /* __APPLE__ */
|
2003-02-07 22:58:09 +01:00
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"AltiVec %sfound\n", (caps->hasAltiVec ? "" : "not "));
|
2003-01-18 20:29:46 +01:00
|
|
|
#endif /* HAVE_ALTIVEC */
|
2004-02-17 00:44:05 +01:00
|
|
|
|
|
|
|
#ifdef ARCH_IA64
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: Intel Itanium\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_SPARC
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: Sun Sparc\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_ARMV4L
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: ARM\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_POWERPC
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: PowerPC\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_ALPHA
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: Digital Alpha\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_SGI_MIPS
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: SGI MIPS\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_PA_RISC
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: Hewlett-Packard PA-RISC\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_S390
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: IBM S/390\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_S390X
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO,"CPU: IBM S/390X\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ARCH_VAX
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO, "CPU: Digital VAX\n" );
|
|
|
|
#endif
|
2007-12-11 23:37:36 +01:00
|
|
|
|
|
|
|
#ifdef ARCH_XTENSA
|
|
|
|
mp_msg(MSGT_CPUDETECT,MSGL_INFO, "CPU: Tensilica Xtensa\n" );
|
|
|
|
#endif
|
2001-11-27 00:08:48 +01:00
|
|
|
}
|
|
|
|
#endif /* !ARCH_X86 */
|