28 |
#include <string.h> |
#include <string.h> |
29 |
#include <time.h> |
#include <time.h> |
30 |
|
|
31 |
|
#if !defined(_WIN32) |
32 |
|
#include <unistd.h> |
33 |
|
#endif |
34 |
|
|
35 |
|
#if defined(__APPLE__) && defined(__MACH__) && !defined(_SC_NPROCESSORS_CONF) |
36 |
|
#include <sys/types.h> |
37 |
|
#include <sys/sysctl.h> |
38 |
|
#ifdef MAX |
39 |
|
#undef MAX |
40 |
|
#endif |
41 |
|
#ifdef MIN |
42 |
|
#undef MIN |
43 |
|
#endif |
44 |
|
#endif |
45 |
|
|
46 |
|
#if defined(__amigaos4__) |
47 |
|
#include <exec/exec.h> |
48 |
|
#include <proto/exec.h> |
49 |
|
#endif |
50 |
|
|
51 |
#include "xvid.h" |
#include "xvid.h" |
52 |
#include "decoder.h" |
#include "decoder.h" |
53 |
#include "encoder.h" |
#include "encoder.h" |
60 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
61 |
#include "quant/quant.h" |
#include "quant/quant.h" |
62 |
#include "motion/motion.h" |
#include "motion/motion.h" |
63 |
|
#include "motion/gmc.h" |
64 |
#include "motion/sad.h" |
#include "motion/sad.h" |
65 |
#include "utils/emms.h" |
#include "utils/emms.h" |
66 |
#include "utils/timer.h" |
#include "utils/timer.h" |
74 |
|
|
75 |
#if (defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)) && defined(_MSC_VER) |
#if (defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)) && defined(_MSC_VER) |
76 |
# include <windows.h> |
# include <windows.h> |
77 |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || defined(ARCH_IS_PPC) |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || (defined(ARCH_IS_PPC) && !defined(__amigaos4__)) |
78 |
# include <signal.h> |
# include <signal.h> |
79 |
# include <setjmp.h> |
# include <setjmp.h> |
80 |
|
|
87 |
} |
} |
88 |
#endif |
#endif |
89 |
|
|
|
|
|
90 |
/* |
/* |
91 |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
92 |
* signalled |
* signalled |
109 |
} |
} |
110 |
return(0); |
return(0); |
111 |
} |
} |
112 |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || defined(ARCH_IS_PPC) |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || (defined(ARCH_IS_PPC) && !defined(__amigaos4__)) |
113 |
static int |
static int |
114 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
115 |
{ |
{ |
156 |
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
if ((cpu_flags & XVID_CPU_SSE) && sigill_check(sse_os_trigger)) |
157 |
cpu_flags &= ~XVID_CPU_SSE; |
cpu_flags &= ~XVID_CPU_SSE; |
158 |
|
|
159 |
if ((cpu_flags & XVID_CPU_SSE2) && sigill_check(sse2_os_trigger)) |
if ((cpu_flags & (XVID_CPU_SSE2|XVID_CPU_SSE3|XVID_CPU_SSE41)) && sigill_check(sse2_os_trigger)) |
160 |
cpu_flags &= ~XVID_CPU_SSE2; |
cpu_flags &= ~(XVID_CPU_SSE2|XVID_CPU_SSE3|XVID_CPU_SSE41); |
161 |
#endif |
#endif |
162 |
|
|
163 |
#if defined(ARCH_IS_PPC) |
#if defined(ARCH_IS_PPC) |
164 |
|
#if defined(__amigaos4__) |
165 |
|
{ |
166 |
|
uint32_t vector_unit = VECTORTYPE_NONE; |
167 |
|
IExec->GetCPUInfoTags(GCIT_VectorUnit, &vector_unit, TAG_END); |
168 |
|
if (vector_unit == VECTORTYPE_ALTIVEC) { |
169 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
170 |
|
} |
171 |
|
} |
172 |
|
#else |
173 |
if (!sigill_check(altivec_trigger)) |
if (!sigill_check(altivec_trigger)) |
174 |
cpu_flags |= XVID_CPU_ALTIVEC; |
cpu_flags |= XVID_CPU_ALTIVEC; |
175 |
#endif |
#endif |
176 |
|
#endif |
177 |
|
|
178 |
return cpu_flags; |
return cpu_flags; |
179 |
} |
} |
286 |
yv12_to_yv12 = yv12_to_yv12_c; |
yv12_to_yv12 = yv12_to_yv12_c; |
287 |
rgb555_to_yv12 = rgb555_to_yv12_c; |
rgb555_to_yv12 = rgb555_to_yv12_c; |
288 |
rgb565_to_yv12 = rgb565_to_yv12_c; |
rgb565_to_yv12 = rgb565_to_yv12_c; |
289 |
|
rgb_to_yv12 = rgb_to_yv12_c; |
290 |
bgr_to_yv12 = bgr_to_yv12_c; |
bgr_to_yv12 = bgr_to_yv12_c; |
291 |
bgra_to_yv12 = bgra_to_yv12_c; |
bgra_to_yv12 = bgra_to_yv12_c; |
292 |
abgr_to_yv12 = abgr_to_yv12_c; |
abgr_to_yv12 = abgr_to_yv12_c; |
308 |
/* All colorspace transformation functions YV12->User format */ |
/* All colorspace transformation functions YV12->User format */ |
309 |
yv12_to_rgb555 = yv12_to_rgb555_c; |
yv12_to_rgb555 = yv12_to_rgb555_c; |
310 |
yv12_to_rgb565 = yv12_to_rgb565_c; |
yv12_to_rgb565 = yv12_to_rgb565_c; |
311 |
|
yv12_to_rgb = yv12_to_rgb_c; |
312 |
yv12_to_bgr = yv12_to_bgr_c; |
yv12_to_bgr = yv12_to_bgr_c; |
313 |
yv12_to_bgra = yv12_to_bgra_c; |
yv12_to_bgra = yv12_to_bgra_c; |
314 |
yv12_to_abgr = yv12_to_abgr_c; |
yv12_to_abgr = yv12_to_abgr_c; |
338 |
sse8_16bit = sse8_16bit_c; |
sse8_16bit = sse8_16bit_c; |
339 |
sse8_8bit = sse8_8bit_c; |
sse8_8bit = sse8_8bit_c; |
340 |
|
|
341 |
#if defined(ARCH_IS_IA32) |
init_GMC(cpu_flags); |
342 |
|
|
343 |
|
#if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) |
344 |
|
|
345 |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
346 |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
347 |
(cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2)) |
(cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2) || |
348 |
|
(cpu_flags & XVID_CPU_SSE3) || (cpu_flags & XVID_CPU_SSE41)) |
349 |
{ |
{ |
350 |
/* Restore FPU context : emms_c is a nop functions */ |
/* Restore FPU context : emms_c is a nop functions */ |
351 |
emms = emms_mmx; |
emms = emms_mmx; |
366 |
quant_h263_inter = quant_h263_inter_mmx; |
quant_h263_inter = quant_h263_inter_mmx; |
367 |
dequant_h263_intra = dequant_h263_intra_mmx; |
dequant_h263_intra = dequant_h263_intra_mmx; |
368 |
dequant_h263_inter = dequant_h263_inter_mmx; |
dequant_h263_inter = dequant_h263_inter_mmx; |
|
|
|
369 |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
370 |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
371 |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
372 |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
373 |
|
|
374 |
|
|
375 |
/* Block related functions */ |
/* Block related functions */ |
376 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
377 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
409 |
image_brightness = image_brightness_mmx; |
image_brightness = image_brightness_mmx; |
410 |
|
|
411 |
/* image input xxx_to_yv12 related functions */ |
/* image input xxx_to_yv12 related functions */ |
412 |
|
|
413 |
yv12_to_yv12 = yv12_to_yv12_mmx; |
yv12_to_yv12 = yv12_to_yv12_mmx; |
414 |
|
|
415 |
bgr_to_yv12 = bgr_to_yv12_mmx; |
bgr_to_yv12 = bgr_to_yv12_mmx; |
416 |
|
rgb_to_yv12 = rgb_to_yv12_mmx; |
417 |
bgra_to_yv12 = bgra_to_yv12_mmx; |
bgra_to_yv12 = bgra_to_yv12_mmx; |
418 |
|
rgba_to_yv12 = rgba_to_yv12_mmx; |
419 |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
420 |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
421 |
|
|
451 |
|
|
452 |
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
453 |
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
454 |
|
|
455 |
} |
} |
456 |
|
|
457 |
|
|
476 |
interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_xmm; |
interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_xmm; |
477 |
|
|
478 |
/* Quantization */ |
/* Quantization */ |
|
quant_mpeg_intra = quant_mpeg_intra_xmm; |
|
479 |
quant_mpeg_inter = quant_mpeg_inter_xmm; |
quant_mpeg_inter = quant_mpeg_inter_xmm; |
480 |
|
|
481 |
dequant_h263_intra = dequant_h263_intra_xmm; |
dequant_h263_intra = dequant_h263_intra_xmm; |
486 |
transfer_8to16sub2ro = transfer_8to16sub2ro_xmm; |
transfer_8to16sub2ro = transfer_8to16sub2ro_xmm; |
487 |
|
|
488 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
489 |
yv12_to_yv12 = yv12_to_yv12_xmm; |
/* yv12_to_yv12 = yv12_to_yv12_xmm; */ /* appears to be slow on many machines */ |
490 |
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
491 |
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
492 |
|
|
547 |
dequant_h263_inter = dequant_h263_inter_3dne; |
dequant_h263_inter = dequant_h263_inter_3dne; |
548 |
|
|
549 |
/* ME functions */ |
/* ME functions */ |
|
calc_cbp = calc_cbp_3dne; |
|
|
|
|
550 |
sad16 = sad16_3dne; |
sad16 = sad16_3dne; |
551 |
sad8 = sad8_3dne; |
sad8 = sad8_3dne; |
552 |
sad16bi = sad16bi_3dne; |
sad16bi = sad16bi_3dne; |
571 |
|
|
572 |
/* DCT operators */ |
/* DCT operators */ |
573 |
fdct = fdct_sse2_skal; |
fdct = fdct_sse2_skal; |
574 |
/* idct = idct_sse2_skal; */ /* Is now IEEE1180 and Walken compliant. Disabled until fully tested. */ |
idct = idct_sse2_skal; /* Is now IEEE1180 and Walken compliant. */ |
575 |
|
|
576 |
/* postprocessing */ |
/* postprocessing */ |
577 |
image_brightness = image_brightness_sse2; |
image_brightness = image_brightness_sse2; |
578 |
|
|
579 |
} |
} |
580 |
|
|
581 |
|
if ((cpu_flags & XVID_CPU_SSE3)) { |
582 |
|
|
583 |
|
/* SAD operators */ |
584 |
|
sad16 = sad16_sse3; |
585 |
|
dev16 = dev16_sse3; |
586 |
|
} |
587 |
|
|
588 |
#endif /* ARCH_IS_IA32 */ |
#endif /* ARCH_IS_IA32 */ |
589 |
|
|
590 |
#if defined(ARCH_IS_IA64) |
#if defined(ARCH_IS_IA64) |
675 |
} |
} |
676 |
#endif |
#endif |
677 |
|
|
|
#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_mmx; |
|
|
|
|
|
/* 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 |
|
|
|
|
678 |
#if defined(_DEBUG) |
#if defined(_DEBUG) |
679 |
xvid_debug = init->debug; |
xvid_debug = init->debug; |
680 |
#endif |
#endif |
690 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
691 |
|
|
692 |
info->actual_version = XVID_VERSION; |
info->actual_version = XVID_VERSION; |
693 |
info->build = "xvid-1.1.2"; |
info->build = "xvid-1.3.0-dev"; |
694 |
info->cpu_flags = detect_cpu_flags(); |
info->cpu_flags = detect_cpu_flags(); |
695 |
|
info->num_threads = 0; /* single-thread */ |
696 |
|
|
697 |
|
#if defined(_WIN32) |
698 |
|
|
699 |
|
{ |
700 |
|
SYSTEM_INFO siSysInfo; |
701 |
|
GetSystemInfo(&siSysInfo); |
702 |
|
info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */ |
703 |
|
} |
704 |
|
|
705 |
|
#elif defined(_SC_NPROCESSORS_CONF) /* should be available on Apple too actually */ |
706 |
|
|
707 |
|
info->num_threads = sysconf(_SC_NPROCESSORS_CONF); |
708 |
|
|
709 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
710 |
|
|
711 |
|
{ |
712 |
|
size_t len; |
713 |
|
int mib[2], ncpu; |
714 |
|
|
715 |
|
mib[0] = CTL_HW; |
716 |
|
mib[1] = HW_NCPU; |
717 |
|
len = sizeof(ncpu); |
718 |
|
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0) |
719 |
|
info -> num_threads = ncpu; |
720 |
|
else |
721 |
|
info -> num_threads = 1; |
722 |
|
} |
723 |
|
|
724 |
|
#elif defined(__amigaos4__) |
725 |
|
|
726 |
|
{ |
727 |
|
uint32_t num_threads = 1; |
728 |
|
IExec->GetCPUInfoTags(GCIT_NumberOfCPUs, &num_threads, TAG_END); |
729 |
|
info->num_threads = num_threads; |
730 |
|
} |
731 |
|
|
|
#if defined(_SMP) && defined(WIN32) |
|
|
info->num_threads = pthread_num_processors_np();; |
|
|
#else |
|
|
info->num_threads = 0; |
|
732 |
#endif |
#endif |
733 |
|
|
734 |
return 0; |
return 0; |