--- xvid.c 2005/09/13 12:12:15 1.64 +++ xvid.c 2009/06/02 13:06:49 1.81 @@ -19,7 +19,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: xvid.c,v 1.64 2005/09/13 12:12:15 suxen_drol Exp $ + * $Id: xvid.c,v 1.81 2009/06/02 13:06:49 Isibaar Exp $ * ****************************************************************************/ @@ -28,6 +28,21 @@ #include #include +#if !defined(_WIN32) +#include +#endif + +#if defined(__APPLE__) && defined(__MACH__) && !defined(_SC_NPROCESSORS_CONF) +#include +#include +#ifdef MAX +#undef MAX +#endif +#ifdef MIN +#undef MIN +#endif +#endif + #include "xvid.h" #include "decoder.h" #include "encoder.h" @@ -40,6 +55,7 @@ #include "utils/mbfunctions.h" #include "quant/quant.h" #include "motion/motion.h" +#include "motion/gmc.h" #include "motion/sad.h" #include "utils/emms.h" #include "utils/timer.h" @@ -126,7 +142,7 @@ /* detect cpu flags */ static unsigned int -detect_cpu_flags() +detect_cpu_flags(void) { /* enable native assembly optimizations by default */ unsigned int cpu_flags = XVID_CPU_ASM; @@ -136,8 +152,8 @@ 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; + if ((cpu_flags & (XVID_CPU_SSE2|XVID_CPU_SSE3|XVID_CPU_SSE41)) && sigill_check(sse2_os_trigger)) + cpu_flags &= ~(XVID_CPU_SSE2|XVID_CPU_SSE3|XVID_CPU_SSE41); #endif #if defined(ARCH_IS_PPC) @@ -183,7 +199,7 @@ idct = idct_int32; /* Only needed on PPC Altivec archs */ - sadInit = 0; + sadInit = NULL; /* Restore FPU context : emms_c is a nop functions */ emms = emms_c; @@ -256,6 +272,7 @@ yv12_to_yv12 = yv12_to_yv12_c; rgb555_to_yv12 = rgb555_to_yv12_c; rgb565_to_yv12 = rgb565_to_yv12_c; + rgb_to_yv12 = rgb_to_yv12_c; bgr_to_yv12 = bgr_to_yv12_c; bgra_to_yv12 = bgra_to_yv12_c; abgr_to_yv12 = abgr_to_yv12_c; @@ -277,6 +294,7 @@ /* All colorspace transformation functions YV12->User format */ yv12_to_rgb555 = yv12_to_rgb555_c; yv12_to_rgb565 = yv12_to_rgb565_c; + yv12_to_rgb = yv12_to_rgb_c; yv12_to_bgr = yv12_to_bgr_c; yv12_to_bgra = yv12_to_bgra_c; yv12_to_abgr = yv12_to_abgr_c; @@ -306,11 +324,14 @@ sse8_16bit = sse8_16bit_c; sse8_8bit = sse8_8bit_c; -#if defined(ARCH_IS_IA32) + init_GMC(cpu_flags); + +#if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || (cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || - (cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2)) + (cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2) || + (cpu_flags & XVID_CPU_SSE3) || (cpu_flags & XVID_CPU_SSE41)) { /* Restore FPU context : emms_c is a nop functions */ emms = emms_mmx; @@ -328,15 +349,15 @@ /* Quantization related functions */ quant_h263_intra = quant_h263_intra_mmx; - quant_h263_inter = quant_h263_inter_mmx; + quant_h263_inter = quant_h263_inter_mmx; dequant_h263_intra = dequant_h263_intra_mmx; dequant_h263_inter = dequant_h263_inter_mmx; - quant_mpeg_intra = quant_mpeg_intra_mmx; quant_mpeg_inter = quant_mpeg_inter_mmx; dequant_mpeg_intra = dequant_mpeg_intra_mmx; dequant_mpeg_inter = dequant_mpeg_inter_mmx; + /* Block related functions */ transfer_8to16copy = transfer_8to16copy_mmx; transfer_16to8copy = transfer_16to8copy_mmx; @@ -374,9 +395,13 @@ image_brightness = image_brightness_mmx; /* image input xxx_to_yv12 related functions */ + yv12_to_yv12 = yv12_to_yv12_mmx; + bgr_to_yv12 = bgr_to_yv12_mmx; + rgb_to_yv12 = rgb_to_yv12_mmx; bgra_to_yv12 = bgra_to_yv12_mmx; + rgba_to_yv12 = rgba_to_yv12_mmx; yuyv_to_yv12 = yuyv_to_yv12_mmx; uyvy_to_yv12 = uyvy_to_yv12_mmx; @@ -412,6 +437,7 @@ yuyv_to_yv12 = yuyv_to_yv12_3dn; uyvy_to_yv12 = uyvy_to_yv12_3dn; + } @@ -435,19 +461,18 @@ interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_xmm; interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_xmm; - /* Quantization */ - quant_mpeg_intra = quant_mpeg_intra_xmm; + /* Quantization */ quant_mpeg_inter = quant_mpeg_inter_xmm; dequant_h263_intra = dequant_h263_intra_xmm; dequant_h263_inter = dequant_h263_inter_xmm; - /* Buffer transfer */ + /* Buffer transfer */ transfer_8to16sub2 = transfer_8to16sub2_xmm; transfer_8to16sub2ro = transfer_8to16sub2ro_xmm; /* Colorspace transformation */ - yv12_to_yv12 = yv12_to_yv12_xmm; + /* yv12_to_yv12 = yv12_to_yv12_xmm; */ /* appears to be slow on many machines */ yuyv_to_yv12 = yuyv_to_yv12_xmm; uyvy_to_yv12 = uyvy_to_yv12_xmm; @@ -499,7 +524,7 @@ interpolate8x4_halfpel_v = interpolate8x4_halfpel_v_3dne; interpolate8x4_halfpel_hv = interpolate8x4_halfpel_hv_3dne; - /* Quantization */ + /* Quantization */ quant_h263_intra = quant_h263_intra_3dne; /* cmov only */ quant_h263_inter = quant_h263_inter_3dne; dequant_mpeg_intra = dequant_mpeg_intra_3dne; /* cmov only */ @@ -507,9 +532,7 @@ dequant_h263_intra = dequant_h263_intra_3dne; dequant_h263_inter = dequant_h263_inter_3dne; - /* ME functions */ - calc_cbp = calc_cbp_3dne; - + /* ME functions */ sad16 = sad16_3dne; sad8 = sad8_3dne; sad16bi = sad16bi_3dne; @@ -517,7 +540,7 @@ dev16 = dev16_3dne; } } - + if ((cpu_flags & XVID_CPU_SSE2)) { calc_cbp = calc_cbp_sse2; @@ -534,11 +557,20 @@ /* DCT operators */ fdct = fdct_sse2_skal; - /* idct = idct_sse2_skal; */ /* Is now IEEE1180 and Walken compliant. Disabled until fully tested. */ + idct = idct_sse2_skal; /* Is now IEEE1180 and Walken compliant. */ /* postprocessing */ image_brightness = image_brightness_sse2; + + } + + if ((cpu_flags & XVID_CPU_SSE3)) { + + /* SAD operators */ + sad16 = sad16_sse3; + dev16 = dev16_sse3; } + #endif /* ARCH_IS_IA32 */ #if defined(ARCH_IS_IA64) @@ -629,74 +661,6 @@ } #endif -#if defined(ARCH_IS_X86_64) - /* For now, only XVID_CPU_ASM is looked for, so user can still - * disable asm usage the usual way. When Intel EMT64 cpus will - * be out, maybe we'll have to check more precisely what cpu - * features there really are. */ - if (cpu_flags & XVID_CPU_ASM) { - /* SIMD state flusher */ - emms = emms_3dn; - - /* DCT operators */ - fdct = fdct_skal_x86_64; - idct = idct_x86_64; - - /* SAD operators */ - sad16 = sad16_x86_64; - sad8 = sad8_x86_64; - sad16bi = sad16bi_x86_64; - sad8bi = sad8bi_x86_64; - dev16 = dev16_x86_64; - sad16v = sad16v_x86_64; - sse8_16bit = sse8_16bit_x86_64; - sse8_8bit = sse8_8bit_x86_64; - - /* Interpolation operators */ - interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_x86_64; - interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_x86_64; - interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_x86_64; - - interpolate8x8_halfpel_add = interpolate8x8_halfpel_add_x86_64; - interpolate8x8_halfpel_h_add = interpolate8x8_halfpel_h_add_x86_64; - interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_x86_64; - interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_x86_64; - - interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_x86_64; - interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_x86_64; - - interpolate8x8_avg2 = interpolate8x8_avg2_x86_64; - interpolate8x8_avg4 = interpolate8x8_avg4_x86_64; - - /* Quantization related functions */ - quant_h263_intra = quant_h263_intra_x86_64; - quant_h263_inter = quant_h263_inter_x86_64; - dequant_h263_intra = dequant_h263_intra_x86_64; - dequant_h263_inter = dequant_h263_inter_x86_64; - quant_mpeg_intra = quant_mpeg_intra_x86_64; - quant_mpeg_inter = quant_mpeg_inter_x86_64; - dequant_mpeg_intra = dequant_mpeg_intra_x86_64; - dequant_mpeg_inter = dequant_mpeg_inter_x86_64; - - /* Block related functions */ - transfer_8to16copy = transfer_8to16copy_x86_64; - transfer_16to8copy = transfer_16to8copy_x86_64; - transfer_8to16sub = transfer_8to16sub_x86_64; - transfer_8to16subro = transfer_8to16subro_x86_64; - transfer_8to16sub2 = transfer_8to16sub2_x86_64; - transfer_8to16sub2ro= transfer_8to16sub2ro_x86_64; - transfer_16to8add = transfer_16to8add_x86_64; - transfer8x8_copy = transfer8x8_copy_x86_64; - - /* Qpel stuff */ - xvid_QP_Funcs = &xvid_QP_Funcs_x86_64; - xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_x86_64; - - /* Interlacing Functions */ - MBFieldTest = MBFieldTest_x86_64; - } -#endif - #if defined(_DEBUG) xvid_debug = init->debug; #endif @@ -712,13 +676,37 @@ return XVID_ERR_VERSION; info->actual_version = XVID_VERSION; - info->build = "xvid-1.1.0-beta2"; + info->build = "xvid-1.3.0-dev"; info->cpu_flags = detect_cpu_flags(); + info->num_threads = 0; /* single-thread */ + +#if defined(_WIN32) + + { + SYSTEM_INFO siSysInfo; + GetSystemInfo(&siSysInfo); + info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */ + } + +#elif defined(_SC_NPROCESSORS_CONF) /* should be available on Apple too actually */ + + info->num_threads = sysconf(_SC_NPROCESSORS_CONF); + +#elif defined(__APPLE__) && defined(__MACH__) + + { + size_t len; + int mib[2], ncpu; + + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + len = sizeof(ncpu); + if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0) + info -> num_threads = ncpu; + else + info -> num_threads = 1; + } -#if defined(_SMP) && defined(WIN32) - info->num_threads = pthread_num_processors_np();; -#else - info->num_threads = 0; #endif return 0;