--- xvid.c 2002/12/08 05:38:56 1.33.2.15 +++ xvid.c 2002/12/30 10:49:17 1.33.2.19 @@ -37,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.33.2.15 2002/12/08 05:38:56 suxen_drol Exp $ + * $Id: xvid.c,v 1.33.2.19 2002/12/30 10:49:17 suxen_drol Exp $ * ****************************************************************************/ @@ -237,15 +237,17 @@ /* reduced resoltuion */ + copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; + add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; #ifdef ARCH_X86 vfilter_31 = xvid_VFilter_31_x86; hfilter_31 = xvid_HFilter_31_x86; #else - copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; - add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; vfilter_31 = xvid_VFilter_31_C; hfilter_31 = xvid_HFilter_31_C; #endif + filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; + filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; /* Initialize internal colorspace transformation tables */ colorspace_init(); @@ -354,6 +356,8 @@ copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_mmx; add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_mmx; hfilter_31 = xvid_HFilter_31_mmx; + filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_mmx; + filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_mmx; /* image input xxx_to_yv12 related functions */ yv12_to_yv12 = yv12_to_yv12_mmx; @@ -409,6 +413,9 @@ add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; /* Quantization */ + quant4_intra = quant4_intra_xmm; + quant4_inter = quant4_inter_xmm; + dequant_intra = dequant_intra_xmm; dequant_inter = dequant_inter_xmm; @@ -437,6 +444,42 @@ interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; } + if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) { + + /* Inverse DCT */ + idct = idct_3dne; + + /* Buffer transfer */ + transfer_8to16copy = transfer_8to16copy_3dne; + transfer_16to8copy = transfer_16to8copy_3dne; + transfer_8to16sub = transfer_8to16sub_3dne; + transfer_8to16sub2 = transfer_8to16sub2_3dne; + transfer_16to8add = transfer_16to8add_3dne; + transfer8x8_copy = transfer8x8_copy_3dne; + + /* Quantization */ + dequant4_intra = dequant4_intra_3dne; + dequant4_inter = dequant4_inter_3dne; + quant_intra = quant_intra_3dne; + quant_inter = quant_inter_3dne; + dequant_intra = dequant_intra_3dne; + dequant_inter = dequant_inter_3dne; + + /* ME functions */ + calc_cbp = calc_cbp_3dne; + sad16 = sad16_3dne; + sad8 = sad8_3dne; + sad16bi = sad16bi_3dne; + sad8bi = sad8bi_3dne; + dev16 = dev16_3dne; + + /* Interpolation */ + interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dne; + interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dne; + interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; + } + + if ((cpu_flags & XVID_CPU_SSE2) > 0) { #ifdef EXPERIMENTAL_SSE2_CODE @@ -509,7 +552,7 @@ static int xvid_init_convert(XVID_INIT_CONVERTINFO* convert) { - const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); + // const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); const int width = convert->width; const int height = convert->height; const int width2 = convert->width/2; @@ -537,6 +580,224 @@ } + +void fill8(uint8_t * block, int size, int value) +{ + int i; + for (i = 0; i < size; i++) + block[i] = value; +} + +void fill16(int16_t * block, int size, int value) +{ + int i; + for (i = 0; i < size; i++) + block[i] = value; +} + +#define RANDOM(min,max) min + (rand() % (max-min)) + +void random8(uint8_t * block, int size, int min, int max) +{ + int i; + for (i = 0; i < size; i++) + block[i] = RANDOM(min,max); +} + +void random16(int16_t * block, int size, int min, int max) +{ + int i; + for (i = 0; i < size; i++) + block[i] = RANDOM(min,max); +} + +int compare16(const int16_t * blockA, const int16_t * blockB, int size) +{ + int i; + for (i = 0; i < size; i++) + if (blockA[i] != blockB[i]) + return 1; + + return 0; +} + + + +int test_h263_intra(quanth263_intraFunc * funcA, quanth263_intraFunc * funcB, + const char * nameA, const char * nameB, + int min, int max) +{ + int q,i; + int64_t timeSTART; + int64_t timeA = 0; + int64_t timeB = 0; + DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); + DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); + DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); + + for (q = 1; q <= 31; q++) /* quantizer */ + { + for (i = min; i < max; i++) /* input coeff */ + { + fill16(arrayX, 64, i); + + timeSTART = read_counter(); + funcA(arrayA, arrayX, q, q); + timeA += read_counter() - timeSTART; + + timeSTART = read_counter(); + funcB(arrayB, arrayX, q, q); + timeB += read_counter() - timeSTART; + + if (compare16(arrayA, arrayB, 64)) + { + printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i); + return 0; + } + } + } + + if (nameA) printf("%s:\t%I64i\n", nameA, timeA); + if (nameB) printf("%s:\t%I64i\n", nameB, timeB); + + return 0; +} + +int test_h263_inter(quanth263_interFunc * funcA, quanth263_interFunc * funcB, + const char * nameA, const char * nameB, + int min, int max) +{ + int q,i; + int64_t timeSTART; + int64_t timeA = 0; + int64_t timeB = 0; + DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); + DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); + DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); + + for (q = 1; q <= 31; q++) /* quantizer */ + { + for (i = min; i < max; i++) /* input coeff */ + { + fill16(arrayX, 64, i); + + timeSTART = read_counter(); + funcA(arrayA, arrayX, q); + timeA += read_counter() - timeSTART; + + timeSTART = read_counter(); + funcB(arrayB, arrayX, q); + timeB += read_counter() - timeSTART; + + if (compare16(arrayA, arrayB, 64)) + { + printf("%s/%s error: q=%i, i=%i\n", nameA?nameA:"?", nameB?nameB:"?", q, i); + return 0; + } + } + } + + if (nameA) printf("%s:\t%I64i\n", nameA, timeA); + if (nameB) printf("%s:\t%I64i\n", nameB, timeB); + + return 0; +} + + + +int xvid_init_test() +{ + int cpu_flags; + + printf("xvid_init_test\n"); + +#if defined(ARCH_X86) + cpu_flags = check_cpu_features(); + + emms_mmx(); + + printf("--- quant intra ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_intra(quant_intra_c, quant_intra_mmx, "c", "mmx", -2048, 2047); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_intra(quant_intra_c, quant_intra_3dne, NULL, "3dne", -2048, 2047); + if (cpu_flags & XVID_CPU_SSE2) + test_h263_intra(quant_intra_c, quant_intra_sse2, NULL, "sse2", -2048, 2047); + + printf("\n--- quant inter ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_inter(quant_inter_c, quant_inter_mmx, "c", "mmx", -2048, 2047); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_inter(quant_inter_c, quant_inter_3dne, NULL, "3dne", -2048, 2047); + if (cpu_flags & XVID_CPU_SSE2) + test_h263_inter(quant_inter_c, quant_inter_sse2, NULL, "sse2", -2048, 2047); + + printf("\n--- dequan intra ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_intra(dequant_intra_c, dequant_intra_mmx, "c", "mmx", -256, 255); + if (cpu_flags & XVID_CPU_MMXEXT) + test_h263_intra(dequant_intra_c, dequant_intra_xmm, NULL, "xmm", -256, 255); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_intra(dequant_intra_c, dequant_intra_3dne, NULL, "3dne", -256, 255); + if (cpu_flags & XVID_CPU_SSE2) + test_h263_intra(dequant_intra_c, dequant_intra_sse2, NULL, "sse2", -256, 255); + + printf("\n--- dequant inter ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_inter((quanth263_interFunc*)dequant_inter_c, + (quanth263_interFunc*)dequant_inter_mmx, "c", "mmx", -256, 255); + + if (cpu_flags & XVID_CPU_MMXEXT) + test_h263_inter((quanth263_interFunc*)dequant_inter_c, + (quanth263_interFunc*)dequant_inter_xmm, NULL, "xmm", -256, 255); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_inter((quanth263_interFunc*)dequant_inter_c, + (quanth263_interFunc*)dequant_inter_3dne, NULL, "3dne", -256, 255); + if (cpu_flags & XVID_CPU_SSE2) + test_h263_inter((quanth263_interFunc*)dequant_inter_c, + (quanth263_interFunc*)dequant_inter_sse2, NULL, "sse2", -256, 255); + + printf("\n--- quant4_intra ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_intra((quanth263_intraFunc*)quant4_intra_c, + (quanth263_intraFunc*)quant4_intra_mmx, "c", "mmx", -2048, 2047); + if (cpu_flags & XVID_CPU_MMXEXT) + test_h263_intra((quanth263_intraFunc*)quant4_intra_c, + (quanth263_intraFunc*)quant4_intra_xmm, NULL, "xmm", -2048, 2047); + + printf("\n--- quant4_inter ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_inter((quanth263_interFunc*)quant4_inter_c, + (quanth263_interFunc*)quant4_inter_mmx, "c", "mmx", -2048, 2047); + if (cpu_flags & XVID_CPU_MMXEXT) + test_h263_inter((quanth263_interFunc*)quant4_inter_c, + (quanth263_interFunc*)quant4_inter_xmm, NULL, "xmm", -2048, 2047); + + + printf("\n--- dequant4_intra ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_intra((quanth263_intraFunc*)dequant4_intra_c, + (quanth263_intraFunc*)dequant4_intra_mmx, "c", "mmx", -256, 255); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_intra((quanth263_intraFunc*)dequant4_intra_c, + (quanth263_intraFunc*)dequant4_intra_3dne, NULL, "sse2", -256, 255); + + printf("\n--- dequant4_inter ---\n"); + if (cpu_flags & XVID_CPU_MMX) + test_h263_inter((quanth263_interFunc*)dequant4_inter_c, + (quanth263_interFunc*)dequant4_inter_mmx, "c", "mmx", -256, 255); + if (cpu_flags & XVID_CPU_3DNOWEXT) + test_h263_inter((quanth263_interFunc*)dequant4_inter_c, + (quanth263_interFunc*)dequant4_inter_3dne, NULL, "sse2", -256, 255); + + emms_mmx(); + +#endif + + return XVID_ERR_OK; +} + + int xvid_init(void *handle, int opt, @@ -551,6 +812,9 @@ case XVID_INIT_CONVERT : return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); + case XVID_INIT_TEST : + return xvid_init_test(); + default : return XVID_ERR_FAIL; }