2002-11-08 00:02:15 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
|
|
|
|
#ifdef BUILD_MMX
|
|
|
|
#include "evas_mmx.h"
|
|
|
|
#endif
|
|
|
|
|
2004-04-18 18:27:37 -07:00
|
|
|
#include <setjmp.h>
|
|
|
|
|
2004-10-20 09:36:12 -07:00
|
|
|
#ifndef WIN32
|
2004-04-18 18:27:37 -07:00
|
|
|
static sigjmp_buf detect_buf;
|
2004-10-20 09:36:12 -07:00
|
|
|
#endif
|
|
|
|
|
2003-03-10 20:39:58 -08:00
|
|
|
static int cpu_feature_mask = 0;
|
|
|
|
|
2004-10-20 09:36:12 -07:00
|
|
|
#ifndef WIN32
|
2003-09-19 21:42:45 -07:00
|
|
|
static void evas_common_cpu_catch_ill(int sig);
|
|
|
|
|
|
|
|
static void
|
|
|
|
evas_common_cpu_catch_ill(int sig)
|
2003-03-10 20:39:58 -08:00
|
|
|
{
|
2004-04-18 18:27:37 -07:00
|
|
|
siglongjmp(detect_buf, 1);
|
2003-03-10 20:39:58 -08:00
|
|
|
}
|
2004-10-20 09:36:12 -07:00
|
|
|
#endif
|
2003-03-10 20:39:58 -08:00
|
|
|
|
2003-12-09 17:12:13 -08:00
|
|
|
#if ( \
|
|
|
|
defined __i386__ || \
|
|
|
|
defined __386__ || \
|
|
|
|
defined __X86__ || \
|
|
|
|
defined _M_IX86 || \
|
|
|
|
defined i386)
|
2003-03-10 20:39:58 -08:00
|
|
|
void
|
|
|
|
evas_common_cpu_mmx_test(void)
|
|
|
|
{
|
2003-03-13 20:57:09 -08:00
|
|
|
#ifdef BUILD_MMX
|
2003-03-10 20:39:58 -08:00
|
|
|
pxor_r2r(mm4, mm4);
|
2003-03-13 20:57:09 -08:00
|
|
|
#endif
|
2003-03-10 20:39:58 -08:00
|
|
|
}
|
|
|
|
|
2003-09-10 01:52:18 -07:00
|
|
|
void
|
|
|
|
evas_common_cpu_mmx2_test(void)
|
|
|
|
{
|
|
|
|
#ifdef BUILD_MMX
|
2003-09-19 21:48:19 -07:00
|
|
|
char data[16];
|
2003-09-19 21:42:45 -07:00
|
|
|
|
2003-09-19 21:48:19 -07:00
|
|
|
data[0] = 0;
|
2003-09-19 21:42:45 -07:00
|
|
|
mmx_r2m(movntq, mm0, data);
|
2003-09-19 21:48:19 -07:00
|
|
|
data[0] = 0;
|
2003-09-10 01:52:18 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-03-10 20:39:58 -08:00
|
|
|
void
|
|
|
|
evas_common_cpu_sse_test(void)
|
|
|
|
{
|
2004-04-04 20:38:34 -07:00
|
|
|
#ifdef BUILD_SSE
|
|
|
|
int blah[2500];
|
2003-09-07 04:24:48 -07:00
|
|
|
|
2004-04-04 20:38:34 -07:00
|
|
|
prefetch(blah + 1200);
|
2003-09-07 04:24:48 -07:00
|
|
|
#endif
|
2003-03-10 20:39:58 -08:00
|
|
|
}
|
|
|
|
#endif /* __i386__ */
|
|
|
|
|
|
|
|
#ifdef __POWERPC__
|
|
|
|
#ifdef __VEC__
|
|
|
|
void
|
|
|
|
evas_common_cpu_altivec_test(void)
|
|
|
|
{
|
|
|
|
vector unsigned int zero;
|
2003-09-19 21:42:45 -07:00
|
|
|
|
2003-03-10 20:39:58 -08:00
|
|
|
zero = vec_splat_u32(0);
|
|
|
|
}
|
|
|
|
#endif /* __VEC__ */
|
|
|
|
#endif /* __POWERPC__ */
|
|
|
|
|
|
|
|
#ifdef __SPARC__
|
|
|
|
void
|
|
|
|
evas_common_cpu_vis_test(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* __SPARC__ */
|
|
|
|
|
|
|
|
int
|
|
|
|
evas_common_cpu_feature_test(void (*feature)(void))
|
|
|
|
{
|
2004-10-20 09:36:12 -07:00
|
|
|
#ifndef WIN32
|
2003-03-10 20:39:58 -08:00
|
|
|
int enabled = 1;
|
|
|
|
struct sigaction act, oact;
|
|
|
|
|
2003-09-19 21:42:45 -07:00
|
|
|
act.sa_handler = evas_common_cpu_catch_ill;
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
sigemptyset(&act.sa_mask);
|
2003-03-10 20:39:58 -08:00
|
|
|
sigaction(SIGILL, &act, &oact);
|
2004-04-18 18:27:37 -07:00
|
|
|
if (sigsetjmp(detect_buf, 1))
|
2003-09-19 21:42:45 -07:00
|
|
|
{
|
|
|
|
sigaction(SIGILL, &oact, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
feature();
|
2003-03-10 20:39:58 -08:00
|
|
|
sigaction(SIGILL, &oact, NULL);
|
|
|
|
return enabled;
|
2004-10-20 09:36:12 -07:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2003-03-10 20:39:58 -08:00
|
|
|
}
|
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
void
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_cpu_init(void)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2003-03-10 20:56:46 -08:00
|
|
|
static int called = 0;
|
2003-03-10 20:39:58 -08:00
|
|
|
|
2003-03-10 20:56:46 -08:00
|
|
|
if (called) return;
|
|
|
|
called = 1;
|
2003-12-09 17:12:13 -08:00
|
|
|
#if ( \
|
|
|
|
defined __i386__ || \
|
|
|
|
defined __386__ || \
|
|
|
|
defined __X86__ || \
|
|
|
|
defined _M_IX86 || \
|
|
|
|
defined i386)
|
2003-06-10 07:52:16 -07:00
|
|
|
#ifdef BUILD_MMX
|
2003-03-10 21:04:33 -08:00
|
|
|
cpu_feature_mask |= CPU_FEATURE_MMX *
|
|
|
|
evas_common_cpu_feature_test(evas_common_cpu_mmx_test);
|
2003-09-19 21:42:45 -07:00
|
|
|
evas_common_cpu_end_opt();
|
2003-09-10 01:52:18 -07:00
|
|
|
cpu_feature_mask |= CPU_FEATURE_MMX2 *
|
|
|
|
evas_common_cpu_feature_test(evas_common_cpu_mmx2_test);
|
2003-09-19 21:42:45 -07:00
|
|
|
evas_common_cpu_end_opt();
|
2003-06-10 07:52:16 -07:00
|
|
|
#ifdef BUILD_SSE
|
2003-03-10 21:06:43 -08:00
|
|
|
cpu_feature_mask |= CPU_FEATURE_SSE *
|
2003-03-10 21:04:33 -08:00
|
|
|
evas_common_cpu_feature_test(evas_common_cpu_sse_test);
|
2003-09-19 21:42:45 -07:00
|
|
|
evas_common_cpu_end_opt();
|
2003-06-10 07:52:16 -07:00
|
|
|
#endif /* BUILD_SSE */
|
|
|
|
#endif /* BUILD_MMX */
|
2003-03-10 20:39:58 -08:00
|
|
|
#endif /* __i386__ */
|
|
|
|
#ifdef __POWERPC__
|
|
|
|
#ifdef __VEC__
|
2003-03-10 21:04:33 -08:00
|
|
|
cpu_feature_mask |= CPU_FEATURE_ALTIVEC *
|
2003-03-10 21:07:46 -08:00
|
|
|
evas_common_cpu_feature_test(evas_common_cpu_altivec_test);
|
2003-09-19 21:42:45 -07:00
|
|
|
evas_common_cpu_end_opt();
|
2003-03-10 20:39:58 -08:00
|
|
|
#endif /* __VEC__ */
|
|
|
|
#endif /* __POWERPC__ */
|
|
|
|
#ifdef __SPARC__
|
2003-03-10 21:04:33 -08:00
|
|
|
cpu_feature_mask |= CPU_FEATURE_VIS *
|
2003-03-10 21:07:46 -08:00
|
|
|
evas_common_cpu_feature_test(evas_common_cpu_vis_test);
|
2003-09-07 04:24:48 -07:00
|
|
|
evas_common_cpu_end_opt();
|
2003-09-19 21:42:45 -07:00
|
|
|
#endif /* __SPARC__ */
|
2003-03-10 20:39:58 -08:00
|
|
|
}
|
|
|
|
|
2003-12-09 20:10:55 -08:00
|
|
|
int
|
2003-03-10 20:39:58 -08:00
|
|
|
evas_common_cpu_has_feature(unsigned int feature)
|
|
|
|
{
|
2003-03-10 20:59:49 -08:00
|
|
|
return (cpu_feature_mask & feature);
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_cpu_have_cpuid(void)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
#ifdef BUILD_MMX
|
|
|
|
unsigned int have_cpu_id;
|
|
|
|
|
|
|
|
have_cpu_id = 0;
|
|
|
|
have_cpuid(have_cpu_id);
|
|
|
|
return have_cpu_id;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_cpu_can_do(int *mmx, int *sse, int *sse2)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
static int do_mmx = 0, do_sse = 0, do_sse2 = 0, done = 0;
|
2003-09-07 04:24:48 -07:00
|
|
|
|
|
|
|
if (!done)
|
|
|
|
{
|
|
|
|
# ifdef HARD_CODED_P3
|
|
|
|
cpu_feature_mask |= CPU_FEATURE_MMX;
|
|
|
|
cpu_feature_mask |= CPU_FEATURE_SSE;
|
2002-11-08 00:02:15 -08:00
|
|
|
#endif
|
2003-09-07 04:24:48 -07:00
|
|
|
#ifdef HARD_CODED_P2
|
|
|
|
cpu_feature_mask |= CPU_FEATURE_MMX;
|
2002-11-08 00:02:15 -08:00
|
|
|
#endif
|
2003-09-07 04:24:48 -07:00
|
|
|
if (cpu_feature_mask & CPU_FEATURE_MMX) do_mmx = 1;
|
2003-09-10 01:52:18 -07:00
|
|
|
if (cpu_feature_mask & CPU_FEATURE_MMX2) do_mmx = 2;
|
2003-09-07 04:24:48 -07:00
|
|
|
if (cpu_feature_mask & CPU_FEATURE_SSE) do_sse = 1;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2003-09-07 04:24:48 -07:00
|
|
|
// printf("%i %i %i\n", do_mmx, do_sse, do_sse2);
|
2002-11-08 00:02:15 -08:00
|
|
|
*mmx = do_mmx;
|
|
|
|
*sse = do_sse;
|
|
|
|
*sse2 = do_sse2;
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef BUILD_MMX
|
|
|
|
void
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_cpu_end_opt(void)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2003-09-10 01:52:18 -07:00
|
|
|
if (cpu_feature_mask &
|
|
|
|
(CPU_FEATURE_MMX | CPU_FEATURE_MMX2))
|
2003-09-07 04:24:48 -07:00
|
|
|
{
|
|
|
|
emms();
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
2002-11-13 21:38:10 -08:00
|
|
|
evas_common_cpu_end_opt(void)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|