37 |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
* - 22.12.2001 API change: added xvid_init() - Isibaar |
38 |
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
39 |
* |
* |
40 |
* $Id: xvid.c,v 1.33.2.18 2002-12-19 00:37:56 Isibaar Exp $ |
* $Id: xvid.c,v 1.33.2.19 2002-12-30 10:49:17 suxen_drol Exp $ |
41 |
* |
* |
42 |
****************************************************************************/ |
****************************************************************************/ |
43 |
|
|
580 |
} |
} |
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
void fill8(uint8_t * block, int size, int value) |
585 |
|
{ |
586 |
|
int i; |
587 |
|
for (i = 0; i < size; i++) |
588 |
|
block[i] = value; |
589 |
|
} |
590 |
|
|
591 |
|
void fill16(int16_t * block, int size, int value) |
592 |
|
{ |
593 |
|
int i; |
594 |
|
for (i = 0; i < size; i++) |
595 |
|
block[i] = value; |
596 |
|
} |
597 |
|
|
598 |
|
#define RANDOM(min,max) min + (rand() % (max-min)) |
599 |
|
|
600 |
|
void random8(uint8_t * block, int size, int min, int max) |
601 |
|
{ |
602 |
|
int i; |
603 |
|
for (i = 0; i < size; i++) |
604 |
|
block[i] = RANDOM(min,max); |
605 |
|
} |
606 |
|
|
607 |
|
void random16(int16_t * block, int size, int min, int max) |
608 |
|
{ |
609 |
|
int i; |
610 |
|
for (i = 0; i < size; i++) |
611 |
|
block[i] = RANDOM(min,max); |
612 |
|
} |
613 |
|
|
614 |
|
int compare16(const int16_t * blockA, const int16_t * blockB, int size) |
615 |
|
{ |
616 |
|
int i; |
617 |
|
for (i = 0; i < size; i++) |
618 |
|
if (blockA[i] != blockB[i]) |
619 |
|
return 1; |
620 |
|
|
621 |
|
return 0; |
622 |
|
} |
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
int test_h263_intra(quanth263_intraFunc * funcA, quanth263_intraFunc * funcB, |
627 |
|
const char * nameA, const char * nameB, |
628 |
|
int min, int max) |
629 |
|
{ |
630 |
|
int q,i; |
631 |
|
int64_t timeSTART; |
632 |
|
int64_t timeA = 0; |
633 |
|
int64_t timeB = 0; |
634 |
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
635 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
636 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
637 |
|
|
638 |
|
for (q = 1; q <= 31; q++) /* quantizer */ |
639 |
|
{ |
640 |
|
for (i = min; i < max; i++) /* input coeff */ |
641 |
|
{ |
642 |
|
fill16(arrayX, 64, i); |
643 |
|
|
644 |
|
timeSTART = read_counter(); |
645 |
|
funcA(arrayA, arrayX, q, q); |
646 |
|
timeA += read_counter() - timeSTART; |
647 |
|
|
648 |
|
timeSTART = read_counter(); |
649 |
|
funcB(arrayB, arrayX, q, q); |
650 |
|
timeB += read_counter() - timeSTART; |
651 |
|
|
652 |
|
if (compare16(arrayA, arrayB, 64)) |
653 |
|
{ |
654 |
|
printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i); |
655 |
|
return 0; |
656 |
|
} |
657 |
|
} |
658 |
|
} |
659 |
|
|
660 |
|
if (nameA) printf("%s:\t%I64i\n", nameA, timeA); |
661 |
|
if (nameB) printf("%s:\t%I64i\n", nameB, timeB); |
662 |
|
|
663 |
|
return 0; |
664 |
|
} |
665 |
|
|
666 |
|
int test_h263_inter(quanth263_interFunc * funcA, quanth263_interFunc * funcB, |
667 |
|
const char * nameA, const char * nameB, |
668 |
|
int min, int max) |
669 |
|
{ |
670 |
|
int q,i; |
671 |
|
int64_t timeSTART; |
672 |
|
int64_t timeA = 0; |
673 |
|
int64_t timeB = 0; |
674 |
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
675 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
676 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
677 |
|
|
678 |
|
for (q = 1; q <= 31; q++) /* quantizer */ |
679 |
|
{ |
680 |
|
for (i = min; i < max; i++) /* input coeff */ |
681 |
|
{ |
682 |
|
fill16(arrayX, 64, i); |
683 |
|
|
684 |
|
timeSTART = read_counter(); |
685 |
|
funcA(arrayA, arrayX, q); |
686 |
|
timeA += read_counter() - timeSTART; |
687 |
|
|
688 |
|
timeSTART = read_counter(); |
689 |
|
funcB(arrayB, arrayX, q); |
690 |
|
timeB += read_counter() - timeSTART; |
691 |
|
|
692 |
|
if (compare16(arrayA, arrayB, 64)) |
693 |
|
{ |
694 |
|
printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i); |
695 |
|
return 0; |
696 |
|
} |
697 |
|
} |
698 |
|
} |
699 |
|
|
700 |
|
if (nameA) printf("%s:\t%I64i\n", nameA, timeA); |
701 |
|
if (nameB) printf("%s:\t%I64i\n", nameB, timeB); |
702 |
|
|
703 |
|
return 0; |
704 |
|
} |
705 |
|
|
706 |
|
|
707 |
|
|
708 |
|
int xvid_init_test() |
709 |
|
{ |
710 |
|
int cpu_flags; |
711 |
|
|
712 |
|
printf("xvid_init_test\n"); |
713 |
|
|
714 |
|
#if defined(ARCH_X86) |
715 |
|
cpu_flags = check_cpu_features(); |
716 |
|
|
717 |
|
emms_mmx(); |
718 |
|
|
719 |
|
printf("--- quant intra ---\n"); |
720 |
|
if (cpu_flags & XVID_CPU_MMX) |
721 |
|
test_h263_intra(quant_intra_c, quant_intra_mmx, "c", "mmx", -2048, 2047); |
722 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
723 |
|
test_h263_intra(quant_intra_c, quant_intra_3dne, NULL, "3dne", -2048, 2047); |
724 |
|
if (cpu_flags & XVID_CPU_SSE2) |
725 |
|
test_h263_intra(quant_intra_c, quant_intra_sse2, NULL, "sse2", -2048, 2047); |
726 |
|
|
727 |
|
printf("\n--- quant inter ---\n"); |
728 |
|
if (cpu_flags & XVID_CPU_MMX) |
729 |
|
test_h263_inter(quant_inter_c, quant_inter_mmx, "c", "mmx", -2048, 2047); |
730 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
731 |
|
test_h263_inter(quant_inter_c, quant_inter_3dne, NULL, "3dne", -2048, 2047); |
732 |
|
if (cpu_flags & XVID_CPU_SSE2) |
733 |
|
test_h263_inter(quant_inter_c, quant_inter_sse2, NULL, "sse2", -2048, 2047); |
734 |
|
|
735 |
|
printf("\n--- dequan intra ---\n"); |
736 |
|
if (cpu_flags & XVID_CPU_MMX) |
737 |
|
test_h263_intra(dequant_intra_c, dequant_intra_mmx, "c", "mmx", -256, 255); |
738 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
739 |
|
test_h263_intra(dequant_intra_c, dequant_intra_xmm, NULL, "xmm", -256, 255); |
740 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
741 |
|
test_h263_intra(dequant_intra_c, dequant_intra_3dne, NULL, "3dne", -256, 255); |
742 |
|
if (cpu_flags & XVID_CPU_SSE2) |
743 |
|
test_h263_intra(dequant_intra_c, dequant_intra_sse2, NULL, "sse2", -256, 255); |
744 |
|
|
745 |
|
printf("\n--- dequant inter ---\n"); |
746 |
|
if (cpu_flags & XVID_CPU_MMX) |
747 |
|
test_h263_inter((quanth263_interFunc*)dequant_inter_c, |
748 |
|
(quanth263_interFunc*)dequant_inter_mmx, "c", "mmx", -256, 255); |
749 |
|
|
750 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
751 |
|
test_h263_inter((quanth263_interFunc*)dequant_inter_c, |
752 |
|
(quanth263_interFunc*)dequant_inter_xmm, NULL, "xmm", -256, 255); |
753 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
754 |
|
test_h263_inter((quanth263_interFunc*)dequant_inter_c, |
755 |
|
(quanth263_interFunc*)dequant_inter_3dne, NULL, "3dne", -256, 255); |
756 |
|
if (cpu_flags & XVID_CPU_SSE2) |
757 |
|
test_h263_inter((quanth263_interFunc*)dequant_inter_c, |
758 |
|
(quanth263_interFunc*)dequant_inter_sse2, NULL, "sse2", -256, 255); |
759 |
|
|
760 |
|
printf("\n--- quant4_intra ---\n"); |
761 |
|
if (cpu_flags & XVID_CPU_MMX) |
762 |
|
test_h263_intra((quanth263_intraFunc*)quant4_intra_c, |
763 |
|
(quanth263_intraFunc*)quant4_intra_mmx, "c", "mmx", -2048, 2047); |
764 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
765 |
|
test_h263_intra((quanth263_intraFunc*)quant4_intra_c, |
766 |
|
(quanth263_intraFunc*)quant4_intra_xmm, NULL, "xmm", -2048, 2047); |
767 |
|
|
768 |
|
printf("\n--- quant4_inter ---\n"); |
769 |
|
if (cpu_flags & XVID_CPU_MMX) |
770 |
|
test_h263_inter((quanth263_interFunc*)quant4_inter_c, |
771 |
|
(quanth263_interFunc*)quant4_inter_mmx, "c", "mmx", -2048, 2047); |
772 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
773 |
|
test_h263_inter((quanth263_interFunc*)quant4_inter_c, |
774 |
|
(quanth263_interFunc*)quant4_inter_xmm, NULL, "xmm", -2048, 2047); |
775 |
|
|
776 |
|
|
777 |
|
printf("\n--- dequant4_intra ---\n"); |
778 |
|
if (cpu_flags & XVID_CPU_MMX) |
779 |
|
test_h263_intra((quanth263_intraFunc*)dequant4_intra_c, |
780 |
|
(quanth263_intraFunc*)dequant4_intra_mmx, "c", "mmx", -256, 255); |
781 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
782 |
|
test_h263_intra((quanth263_intraFunc*)dequant4_intra_c, |
783 |
|
(quanth263_intraFunc*)dequant4_intra_3dne, NULL, "sse2", -256, 255); |
784 |
|
|
785 |
|
printf("\n--- dequant4_inter ---\n"); |
786 |
|
if (cpu_flags & XVID_CPU_MMX) |
787 |
|
test_h263_inter((quanth263_interFunc*)dequant4_inter_c, |
788 |
|
(quanth263_interFunc*)dequant4_inter_mmx, "c", "mmx", -256, 255); |
789 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
790 |
|
test_h263_inter((quanth263_interFunc*)dequant4_inter_c, |
791 |
|
(quanth263_interFunc*)dequant4_inter_3dne, NULL, "sse2", -256, 255); |
792 |
|
|
793 |
|
emms_mmx(); |
794 |
|
|
795 |
|
#endif |
796 |
|
|
797 |
|
return XVID_ERR_OK; |
798 |
|
} |
799 |
|
|
800 |
|
|
801 |
int |
int |
802 |
xvid_init(void *handle, |
xvid_init(void *handle, |
803 |
int opt, |
int opt, |
812 |
case XVID_INIT_CONVERT : |
case XVID_INIT_CONVERT : |
813 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
814 |
|
|
815 |
|
case XVID_INIT_TEST : |
816 |
|
return xvid_init_test(); |
817 |
|
|
818 |
default : |
default : |
819 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
820 |
} |
} |