[cvs] / xvidcore / src / xvid.c Repository:
ViewVC logotype

Diff of /xvidcore/src/xvid.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.33.2.18, Thu Dec 19 00:37:56 2002 UTC revision 1.33.2.20, Thu Jan 2 13:58:54 2003 UTC
# Line 41  Line 41 
41   *   *
42   ****************************************************************************/   ****************************************************************************/
43    
44    #include <stdlib.h>
45    #include <time.h>
46    
47  #include "xvid.h"  #include "xvid.h"
48  #include "decoder.h"  #include "decoder.h"
49  #include "encoder.h"  #include "encoder.h"
# Line 580  Line 583 
583  }  }
584    
585    
586    
587    void fill8(uint8_t * block, int size, int value)
588    {
589            int i;
590            for (i = 0; i < size; i++)
591                    block[i] = value;
592    }
593    
594    void fill16(int16_t * block, int size, int value)
595    {
596            int i;
597            for (i = 0; i < size; i++)
598                    block[i] = value;
599    }
600    
601    #define RANDOM(min,max) min + (rand() % (max-min))
602    
603    void random8(uint8_t * block, int size, int min, int max)
604    {
605            int i;
606            for (i = 0; i < size; i++)
607                    block[i] = RANDOM(min,max);
608    }
609    
610    void random16(int16_t * block, int size, int min, int max)
611    {
612            int i;
613            for (i = 0; i < size; i++)
614                    block[i] = RANDOM(min,max);
615    }
616    
617    int compare16(const int16_t * blockA, const int16_t * blockB, int size)
618    {
619            int i;
620            for (i = 0; i < size; i++)
621                    if (blockA[i] != blockB[i])
622                            return 1;
623    
624            return 0;
625    }
626    
627    int diff16(const int16_t * blockA, const int16_t * blockB, int size)
628    {
629            int i, diff = 0;
630            for (i = 0; i < size; i++)
631                    diff += ABS(blockA[i]-blockB[i]);
632            return diff;
633    }
634    
635    
636    #define XVID_TEST_RANDOM        0x00000001      /* random input data */
637    #define XVID_TEST_VERBOSE       0x00000002      /* verbose error output */
638    
639    
640    #define TEST_FORWARD    0x00000001      /* intra */
641    #define TEST_FDCT  (TEST_FORWARD)
642    #define TEST_IDCT  (0)
643    
644    int test_transform(void * funcA, void * funcB, const char * nameB,
645                                       int test, int flags)
646    {
647            int i;
648            int64_t timeSTART;
649            int64_t timeA = 0;
650            int64_t timeB = 0;
651            DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
652            DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
653            int min, max;
654            int count = 0;
655    
656            int tmp;
657            int min_error = 0x10000*64;
658            int max_error = 0;
659    
660    
661            if ((test & TEST_FORWARD))      /* forward */
662            {
663                    min = -256;
664                    max = 255;
665            }else{          /* inverse */
666                    min = -2048;
667                    max = 2047;
668            }
669    
670            for (i = 0; i < 64*64; i++)
671            {
672                    if ((flags & XVID_TEST_RANDOM))
673                    {
674                            random16(arrayA, 64, min, max);
675                    }else{
676                            fill16(arrayA, 64, i);
677                    }
678                    memcpy(arrayB, arrayA, 64*sizeof(int16_t));
679    
680                    if ((test & TEST_FORWARD))
681                    {
682                            timeSTART = read_counter();
683                            ((fdctFunc*)funcA)(arrayA);
684                            timeA += read_counter() - timeSTART;
685    
686                            timeSTART = read_counter();
687                            ((fdctFunc*)funcB)(arrayB);
688                            timeB += read_counter() - timeSTART;
689                    }
690                    else
691                    {
692                            timeSTART = read_counter();
693                            ((idctFunc*)funcA)(arrayA);
694                            timeA += read_counter() - timeSTART;
695    
696                            timeSTART = read_counter();
697                            ((idctFunc*)funcB)(arrayB);
698                            timeB += read_counter() - timeSTART;
699                    }
700    
701                    tmp = diff16(arrayA, arrayB, 64) / 64;
702                    if (tmp > max_error)
703                            max_error = tmp;
704                    if (tmp < min_error)
705                            min_error = tmp;
706    
707                    count++;
708            }
709    
710            /* print the "average difference" of best/worst transforms */
711            printf("%s:\t%I64i\t(min_error:%i, max_error:%i)\n", nameB, timeB / count, min_error, max_error);
712    
713            return 0;
714    }
715    
716    
717    #define TEST_QUANT      0x00000001      /* forward quantization */
718    #define TEST_INTRA      0x00000002      /* intra */
719    #define TEST_QUANT_INTRA        (TEST_QUANT|TEST_INTRA)
720    #define TEST_QUANT_INTER        (TEST_QUANT)
721    #define TEST_DEQUANT_INTRA      (TEST_INTRA)
722    #define TEST_DEQUANT_INTER      (0)
723    
724    int test_quant(void * funcA, void * funcB, const char * nameB,
725                               int test, int flags)
726    {
727            int q,i;
728            int64_t timeSTART;
729            int64_t timeA = 0;
730            int64_t timeB = 0;
731            int retA, retB;
732            DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE);
733            DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE);
734            DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE);
735            int min, max;
736            int count = 0;
737            int errors = 0;
738    
739            if ((test & TEST_QUANT))        /* quant */
740            {
741                    min = -2048;
742                    max = 2047;
743            }else{          /* dequant */
744                    min = -256;
745                    max = 255;
746            }
747    
748            for (q = 1; q <= 31; q++)       /* quantizer */
749            {
750                    for (i = min; i < max; i++)     /* input coeff */
751                    {
752                            if ((flags & XVID_TEST_RANDOM))
753                            {
754                                    random16(arrayX, 64, min, max);
755                            }else{
756                                    fill16(arrayX, 64, i);
757                            }
758    
759                            if ((test & TEST_INTRA))        /* intra */
760                            {
761                                    timeSTART = read_counter();
762                                    ((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q);
763                                    timeA += read_counter() - timeSTART;
764    
765                                    timeSTART = read_counter();
766                                    ((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q);
767                                    timeB += read_counter() - timeSTART;
768                            }
769                            else    /* inter */
770                            {
771                                    timeSTART = read_counter();
772                                    retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q);
773                                    timeA += read_counter() - timeSTART;
774    
775                                    timeSTART = read_counter();
776                                    retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q);
777                                    timeB += read_counter() - timeSTART;
778                            }
779    
780                            /* compare return value from quant_inter, and compare (de)quantiz'd arrays */
781                            if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) ||
782                                    compare16(arrayA, arrayB, 64))
783                            {
784                                    errors++;
785                                    if ((flags & XVID_TEST_VERBOSE))
786                                            printf("%s error: q=%i, i=%i\n", nameB, q, i);
787                            }
788    
789                            count++;
790                    }
791            }
792    
793            printf("%s:\t%I64i", nameB, timeB / count);
794            if (errors>0)
795                    printf("\t(%i errors out of %i)", errors, count);
796            printf("\n");
797    
798            return 0;
799    }
800    
801    
802    
803    int xvid_init_test(int flags)
804    {
805            int cpu_flags;
806    
807            srand(time(0));
808    
809            printf("xvid_init_test\n");
810    
811    #if defined(ARCH_X86)
812            cpu_flags = check_cpu_features();
813            idct_int32_init();
814            emms_mmx();
815    
816            printf("--- fdct ---\n");
817                    test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags);
818            if (cpu_flags & XVID_CPU_MMX)
819                    test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags);
820            if (cpu_flags & XVID_CPU_SSE2)
821                    test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags);
822    
823            printf("\n--- idct ---\n");
824                    test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags);
825            if (cpu_flags & XVID_CPU_MMX)
826                    test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags);
827            if (cpu_flags & XVID_CPU_MMXEXT)
828                    test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags);
829            if (cpu_flags & XVID_CPU_3DNOWEXT)
830                    test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags);
831            if (cpu_flags & XVID_CPU_SSE2)
832                    test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags);
833    
834            printf("\n--- quant intra ---\n");
835                    test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags);
836            if (cpu_flags & XVID_CPU_MMX)
837                    test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
838            if (cpu_flags & XVID_CPU_3DNOWEXT)
839                    test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags);
840            if (cpu_flags & XVID_CPU_SSE2)
841                    test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags);
842    
843            printf("\n--- quant inter ---\n");
844                    test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags);
845            if (cpu_flags & XVID_CPU_MMX)
846                    test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
847            if (cpu_flags & XVID_CPU_3DNOWEXT)
848                    test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags);
849            if (cpu_flags & XVID_CPU_SSE2)
850                    test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags);
851    
852            printf("\n--- dequant intra ---\n");
853                    test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags);
854            if (cpu_flags & XVID_CPU_MMX)
855                    test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
856            if (cpu_flags & XVID_CPU_MMXEXT)
857                    test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags);
858            if (cpu_flags & XVID_CPU_3DNOWEXT)
859                    test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
860            if (cpu_flags & XVID_CPU_SSE2)
861                    test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags);
862    
863            printf("\n--- dequant inter ---\n");
864                    test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags);
865            if (cpu_flags & XVID_CPU_MMX)
866                    test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
867            if (cpu_flags & XVID_CPU_MMXEXT)
868                    test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags);
869            if (cpu_flags & XVID_CPU_3DNOWEXT)
870                    test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
871            if (cpu_flags & XVID_CPU_SSE2)
872                    test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags);
873    
874            printf("\n--- quant4_intra ---\n");
875                    test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags);
876            if (cpu_flags & XVID_CPU_MMX)
877                    test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags);
878            if (cpu_flags & XVID_CPU_MMXEXT)
879                    test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags);
880    
881            printf("\n--- quant4_inter ---\n");
882                    test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags);
883            if (cpu_flags & XVID_CPU_MMX)
884                    test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags);
885            if (cpu_flags & XVID_CPU_MMXEXT)
886                    test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags);
887    
888            printf("\n--- dequant4_intra ---\n");
889                    test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags);
890            if (cpu_flags & XVID_CPU_MMX)
891                    test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags);
892            if (cpu_flags & XVID_CPU_3DNOWEXT)
893                    test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags);
894    
895            printf("\n--- dequant4_inter ---\n");
896                    test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags);
897            if (cpu_flags & XVID_CPU_MMX)
898                    test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags);
899            if (cpu_flags & XVID_CPU_3DNOWEXT)
900                    test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags);
901    
902            emms_mmx();
903    
904    #endif
905    
906            return XVID_ERR_OK;
907    }
908    
909    
910  int  int
911  xvid_init(void *handle,  xvid_init(void *handle,
912                    int opt,                    int opt,
# Line 594  Line 921 
921                  case XVID_INIT_CONVERT :                  case XVID_INIT_CONVERT :
922                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);                          return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1);
923    
924                    case XVID_INIT_TEST :
925                            return xvid_init_test((int)param1);
926    
927                  default :                  default :
928                          return XVID_ERR_FAIL;                          return XVID_ERR_FAIL;
929          }          }

Legend:
Removed from v.1.33.2.18  
changed lines
  Added in v.1.33.2.20

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4