--- xvid.c 2002/06/26 15:59:51 1.23 +++ xvid.c 2002/07/23 12:59:57 1.33 @@ -27,6 +27,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************/ + /***************************************************************************** * * History @@ -36,7 +37,7 @@ * - 22.12.2001 API change: added xvid_init() - Isibaar * - 16.12.2001 inital version; (c)2001 peter ross * - * $Id: xvid.c,v 1.23 2002/06/26 15:59:51 ia64p Exp $ + * $Id: xvid.c,v 1.33 2002/07/23 12:59:57 suxen_drol Exp $ * ****************************************************************************/ @@ -51,11 +52,79 @@ #include "utils/mem_transfer.h" #include "quant/quant_h263.h" #include "quant/quant_mpeg4.h" +#include "motion/motion.h" #include "motion/sad.h" #include "utils/emms.h" #include "utils/timer.h" #include "bitstream/mbcoding.h" +#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) + +#ifdef WIN32 +#include +#else +#include +#include +#endif + + +#ifndef WIN32 + +static jmp_buf mark; + +static void +sigill_handler(int signal) +{ + longjmp(mark, 1); +} +#endif + + +/* +calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled +return values: +-1 : could not determine +0 : SIGILL was *not* signalled +1 : SIGILL was signalled +*/ + +int +sigill_check(void (*func)()) +{ +#ifdef WIN32 + _try { + func(); + } + _except(EXCEPTION_EXECUTE_HANDLER) { + + if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION) + return 1; + } + return 0; +#else + void * old_handler; + int jmpret; + + + old_handler = signal(SIGILL, sigill_handler); + if (old_handler == SIG_ERR) + { + return -1; + } + + jmpret = setjmp(mark); + if (jmpret == 0) + { + func(); + } + + signal(SIGILL, old_handler); + + return jmpret; +#endif +} +#endif + /***************************************************************************** * XviD Init Entry point * @@ -87,21 +156,33 @@ /* Inform the client the core build - unused because we're still alpha */ init_param->core_build = 1000; - if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) - { - init_param->cpu_flags = check_cpu_features(); - return XVID_ERR_OK; - } - /* Do we have to force CPU features ? */ - if ((init_param->cpu_flags & XVID_CPU_FORCE) > 0) { + if ((init_param->cpu_flags & XVID_CPU_FORCE)) { + cpu_flags = init_param->cpu_flags; + } else { cpu_flags = check_cpu_features(); + +#if defined(ARCH_X86) && defined(EXPERIMENTAL_SSE2_CODE) + if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) + cpu_flags &= ~XVID_CPU_SSE; + + if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) + cpu_flags &= ~XVID_CPU_SSE2; +#endif + } + + if ((init_param->cpu_flags & XVID_CPU_CHKONLY)) + { init_param->cpu_flags = cpu_flags; + return XVID_ERR_OK; } + init_param->cpu_flags = cpu_flags; + + /* Initialize the function pointers */ idct_int32_init(); init_vlc_tables(); @@ -164,9 +245,12 @@ /* Functions used in motion estimation algorithms */ calc_cbp = calc_cbp_c; sad16 = sad16_c; - sad16bi = sad16bi_c; sad8 = sad8_c; + sad16bi = sad16bi_c; + sad8bi = sad8bi_c; dev16 = dev16_c; + + Halfpel8_Refine = Halfpel8_Refine_c; #ifdef ARCH_X86 if ((cpu_flags & XVID_CPU_MMX) > 0) { @@ -220,10 +304,21 @@ calc_cbp = calc_cbp_mmx; sad16 = sad16_mmx; sad8 = sad8_mmx; + sad16bi = sad16bi_mmx; + sad8bi = sad8bi_mmx; dev16 = dev16_mmx; } + /* these 3dnow functions are faster than mmx, but slower than xmm. */ + if ((cpu_flags & XVID_CPU_3DNOW) > 0) { + + /* ME functions */ + sad16bi = sad16bi_3dn; + sad8bi = sad8bi_3dn; + } + + if ((cpu_flags & XVID_CPU_MMXEXT) > 0) { /* Inverse DCT */ @@ -234,6 +329,10 @@ interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; + /* Quantization */ + dequant_intra = dequant_intra_xmm; + dequant_inter = dequant_inter_xmm; + /* Buffer transfer */ transfer_8to16sub2 = transfer_8to16sub2_xmm; @@ -243,6 +342,8 @@ /* ME functions */ sad16 = sad16_xmm; sad8 = sad8_xmm; + sad16bi = sad16bi_xmm; + sad8bi = sad8bi_xmm; dev16 = dev16_xmm; } @@ -258,6 +359,8 @@ if ((cpu_flags & XVID_CPU_SSE2) > 0) { #ifdef EXPERIMENTAL_SSE2_CODE + calc_cbp = calc_cbp_sse2; + /* Quantization */ quant_intra = quant_intra_sse2; dequant_intra = dequant_intra_sse2; @@ -265,7 +368,6 @@ dequant_inter = dequant_inter_sse2; /* ME */ - calc_cbp = calc_cbp_sse2; sad16 = sad16_sse2; dev16 = dev16_sse2; @@ -289,6 +391,7 @@ sad16bi = sad16bi_ia64; sad8 = sad8_ia64; dev16 = dev16_ia64; + Halfpel8_Refine = Halfpel8_Refine_ia64; quant_intra = quant_intra_ia64; dequant_intra = dequant_intra_ia64; quant_inter = quant_inter_ia64;