From b6ae92d827bd47bd42b945dbe8f723e150a64bda Mon Sep 17 00:00:00 2001 From: rbdpngn Date: Tue, 11 Mar 2003 04:39:58 +0000 Subject: [PATCH] Generic runtime cpu feature testing. This is not used much yet, and shouldn't break anything. Please review and shout if you see problems. SVN revision: 6761 --- legacy/evas/src/lib/engines/common/evas_cpu.c | 92 +++++++++++++++++++ legacy/evas/src/lib/include/evas_common.h | 12 +++ 2 files changed, 104 insertions(+) diff --git a/legacy/evas/src/lib/engines/common/evas_cpu.c b/legacy/evas/src/lib/engines/common/evas_cpu.c index e5b9884e23..57da9f01ed 100644 --- a/legacy/evas/src/lib/engines/common/evas_cpu.c +++ b/legacy/evas/src/lib/engines/common/evas_cpu.c @@ -4,9 +4,101 @@ #include "evas_mmx.h" #endif +static jmp_buf detect_buf; +static int cpu_feature_mask = 0; + +void +evas_common_cpu_catch_ill(void) +{ + longjmp(detect_buf, 1); +} + +#ifdef __i386__ +void +evas_common_cpu_mmx_test(void) +{ + pxor_r2r(mm4, mm4); + evas_common_cpu_end_opt(); +} + +void +evas_common_cpu_sse_test(void) +{ +} +#endif /* __i386__ */ + +#ifdef __POWERPC__ +#ifdef __VEC__ +void +evas_common_cpu_altivec_test(void) +{ + vector unsigned int zero; + 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)) +{ + int enabled = 1; + struct sigaction act, oact; + + sigaction(SIGILL, &act, &oact); + if (setjmp(detect_buf)) + enabled = 0; + else + feature(); + sigaction(SIGILL, &oact, NULL); + + return enabled; +} + void evas_common_cpu_init(void) { + int enabled; + +#ifdef __i386__ + + if (evas_common_cpu_feature_test(evas_common_cpu_mmx_test)) + cpu_feature_mask |= CPU_FEATURE_MMX; + + if (evas_common_cpu_feature_test(evas_common_cpu_sse_test)) + cpu_feature_mask |= CPU_FEATURE_SSE; + +#endif /* __i386__ */ + +#ifdef __POWERPC__ +#ifdef __VEC__ + + if (evas_common_cpu_feature_test(evas_common_cpu_altivec_test)) + cpu_feature_mask |= CPU_FEATURE_ALTIVEC; + +#endif /* __VEC__ */ +#endif /* __POWERPC__ */ + +#ifdef __SPARC__ + + if (evas_common_cpu_feature_test(evas_common_cpu_vis_test)) + cpu_feature_mask |= CPU_FEATURE_VIS; + +#endif /* __SPARC__ */ + + printf("Cpu mask set to %08x\n", cpu_feature_mask); +} + +inline int +evas_common_cpu_has_feature(unsigned int feature) +{ + return (cpu_feature_mask & feature); } int diff --git a/legacy/evas/src/lib/include/evas_common.h b/legacy/evas/src/lib/include/evas_common.h index 3ee03b2044..848fa46539 100644 --- a/legacy/evas/src/lib/include/evas_common.h +++ b/legacy/evas/src/lib/include/evas_common.h @@ -110,6 +110,8 @@ #include #include #include +#include +#include #ifdef _WIN32_WCE #include @@ -193,6 +195,16 @@ typedef enum _Convert_Pal_Mode PAL_MODE_LAST } Convert_Pal_Mode; +typedef enum _CPU_Features +{ + CPU_FEATURE_C = 0, + CPU_FEATURE_MMX = (1 << 0), + CPU_FEATURE_SSE = (1 << 1), + CPU_FEATURE_ALTIVEC = (1 << 2), + CPU_FEATURE_VIS = (1 << 3), + CPU_FEATURE_VIS2 = (1 << 4) +} CPU_Features; + /*****************************************************************************/ struct _Evas_Object_List