From b2fa74ac18c4a333f7913a346588b87087989202 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Fri, 28 May 2010 14:28:12 -0400 Subject: [PATCH 1/2] Combine idct and reconstruction steps This moves the prediction step before the idct and combines the idct and reconstruction steps into a single step. Combining them seems to give an overall decoder performance improvement of about 1%. Change-Id: I90d8b167ec70d79c7ba2ee484106a78b3d16e318 --- vp8/common/arm/idct_arm.h | 8 - vp8/common/arm/systemdependent.c | 2 - vp8/common/generic/systemdependent.c | 2 +- vp8/common/idct.h | 20 ++- vp8/common/idctllm.c | 33 ++-- vp8/common/x86/idct_x86.h | 4 - vp8/common/x86/x86_systemdependent.c | 1 - vp8/decoder/arm/dequantize_arm.h | 18 -- vp8/decoder/arm/dsystemdependent.c | 4 - vp8/decoder/decodframe.c | 226 ++++++++++++------------- vp8/decoder/dequantize.c | 58 ++++++- vp8/decoder/dequantize.h | 38 +++-- vp8/decoder/generic/dsystemdependent.c | 4 +- vp8/decoder/x86/dequantize_x86.h | 8 - vp8/decoder/x86/x86_dsystemdependent.c | 2 - 15 files changed, 218 insertions(+), 210 deletions(-) diff --git a/vp8/common/arm/idct_arm.h b/vp8/common/arm/idct_arm.h index 87d888de2..97af32e69 100644 --- a/vp8/common/arm/idct_arm.h +++ b/vp8/common/arm/idct_arm.h @@ -15,7 +15,6 @@ #if HAVE_ARMV6 extern prototype_idct(vp8_short_idct4x4llm_1_v6); extern prototype_idct(vp8_short_idct4x4llm_v6_dual); -extern prototype_idct_scalar(vp8_dc_only_idct_armv6); extern prototype_second_order(vp8_short_inv_walsh4x4_1_armv6); extern prototype_second_order(vp8_short_inv_walsh4x4_armv6); @@ -25,9 +24,6 @@ extern prototype_second_order(vp8_short_inv_walsh4x4_armv6); #undef vp8_idct_idct16 #define vp8_idct_idct16 vp8_short_idct4x4llm_v6_dual -#undef vp8_idct_idct1_scalar -#define vp8_idct_idct1_scalar vp8_dc_only_idct_armv6 - #undef vp8_idct_iwalsh1 #define vp8_idct_iwalsh1 vp8_short_inv_walsh4x4_1_armv6 @@ -38,7 +34,6 @@ extern prototype_second_order(vp8_short_inv_walsh4x4_armv6); #if HAVE_ARMV7 extern prototype_idct(vp8_short_idct4x4llm_1_neon); extern prototype_idct(vp8_short_idct4x4llm_neon); -extern prototype_idct_scalar(vp8_dc_only_idct_neon); extern prototype_second_order(vp8_short_inv_walsh4x4_1_neon); extern prototype_second_order(vp8_short_inv_walsh4x4_neon); @@ -48,9 +43,6 @@ extern prototype_second_order(vp8_short_inv_walsh4x4_neon); #undef vp8_idct_idct16 #define vp8_idct_idct16 vp8_short_idct4x4llm_neon -#undef vp8_idct_idct1_scalar -#define vp8_idct_idct1_scalar vp8_dc_only_idct_neon - #undef vp8_idct_iwalsh1 #define vp8_idct_iwalsh1 vp8_short_inv_walsh4x4_1_neon diff --git a/vp8/common/arm/systemdependent.c b/vp8/common/arm/systemdependent.c index bd6d146c0..b58cd789f 100644 --- a/vp8/common/arm/systemdependent.c +++ b/vp8/common/arm/systemdependent.c @@ -43,7 +43,6 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) rtcd->idct.idct1 = vp8_short_idct4x4llm_1_neon; rtcd->idct.idct16 = vp8_short_idct4x4llm_neon; - rtcd->idct.idct1_scalar = vp8_dc_only_idct_neon; rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_neon; rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_neon; @@ -75,7 +74,6 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) rtcd->idct.idct1 = vp8_short_idct4x4llm_1_v6; rtcd->idct.idct16 = vp8_short_idct4x4llm_v6_dual; - rtcd->idct.idct1_scalar = vp8_dc_only_idct_armv6; rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_armv6; rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_armv6; diff --git a/vp8/common/generic/systemdependent.c b/vp8/common/generic/systemdependent.c index 5f7f943f5..2fbeaee4c 100644 --- a/vp8/common/generic/systemdependent.c +++ b/vp8/common/generic/systemdependent.c @@ -32,7 +32,7 @@ void vp8_machine_specific_config(VP8_COMMON *ctx) rtcd->idct.idct1 = vp8_short_idct4x4llm_1_c; rtcd->idct.idct16 = vp8_short_idct4x4llm_c; - rtcd->idct.idct1_scalar = vp8_dc_only_idct_c; + rtcd->idct.idct1_scalar_add = vp8_dc_only_idct_add_c; rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_c; rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_c; diff --git a/vp8/common/idct.h b/vp8/common/idct.h index adf7771ed..7b04799c8 100644 --- a/vp8/common/idct.h +++ b/vp8/common/idct.h @@ -18,8 +18,10 @@ #define prototype_idct(sym) \ void sym(short *input, short *output, int pitch) -#define prototype_idct_scalar(sym) \ - void sym(short input, short *output, int pitch) +#define prototype_idct_scalar_add(sym) \ + void sym(short input, \ + unsigned char *pred, unsigned char *output, \ + int pitch, int stride) #if ARCH_X86 || ARCH_X86_64 #include "x86/idct_x86.h" @@ -39,10 +41,10 @@ extern prototype_idct(vp8_idct_idct1); #endif extern prototype_idct(vp8_idct_idct16); -#ifndef vp8_idct_idct1_scalar -#define vp8_idct_idct1_scalar vp8_dc_only_idct_c +#ifndef vp8_idct_idct1_scalar_add +#define vp8_idct_idct1_scalar_add vp8_dc_only_idct_add_c #endif -extern prototype_idct_scalar(vp8_idct_idct1_scalar); +extern prototype_idct_scalar_add(vp8_idct_idct1_scalar_add); #ifndef vp8_idct_iwalsh1 @@ -56,14 +58,14 @@ extern prototype_second_order(vp8_idct_iwalsh1); extern prototype_second_order(vp8_idct_iwalsh16); typedef prototype_idct((*vp8_idct_fn_t)); -typedef prototype_idct_scalar((*vp8_idct_scalar_fn_t)); +typedef prototype_idct_scalar_add((*vp8_idct_scalar_add_fn_t)); typedef prototype_second_order((*vp8_second_order_fn_t)); typedef struct { - vp8_idct_fn_t idct1; - vp8_idct_fn_t idct16; - vp8_idct_scalar_fn_t idct1_scalar; + vp8_idct_fn_t idct1; + vp8_idct_fn_t idct16; + vp8_idct_scalar_add_fn_t idct1_scalar_add; vp8_second_order_fn_t iwalsh1; vp8_second_order_fn_t iwalsh16; diff --git a/vp8/common/idctllm.c b/vp8/common/idctllm.c index 2866fa4bb..c9686626c 100644 --- a/vp8/common/idctllm.c +++ b/vp8/common/idctllm.c @@ -104,23 +104,30 @@ void vp8_short_idct4x4llm_1_c(short *input, short *output, int pitch) } } - -void vp8_dc_only_idct_c(short input_dc, short *output, int pitch) +void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr, unsigned char *dst_ptr, int pitch, int stride) { - int i; - int a1; - short *op = output; - int shortpitch = pitch >> 1; - a1 = ((input_dc + 4) >> 3); + int a1 = ((input_dc + 4) >> 3); + int r, c; - for (i = 0; i < 4; i++) + for (r = 0; r < 4; r++) { - op[0] = a1; - op[1] = a1; - op[2] = a1; - op[3] = a1; - op += shortpitch; + for (c = 0; c < 4; c++) + { + int a = a1 + pred_ptr[c] ; + + if (a < 0) + a = 0; + + if (a > 255) + a = 255; + + dst_ptr[c] = (unsigned char) a ; + } + + dst_ptr += stride; + pred_ptr += pitch; } + } void vp8_short_inv_walsh4x4_c(short *input, short *output) diff --git a/vp8/common/x86/idct_x86.h b/vp8/common/x86/idct_x86.h index 0ad8f55cf..d7b4fc95c 100644 --- a/vp8/common/x86/idct_x86.h +++ b/vp8/common/x86/idct_x86.h @@ -22,7 +22,6 @@ #if HAVE_MMX extern prototype_idct(vp8_short_idct4x4llm_1_mmx); extern prototype_idct(vp8_short_idct4x4llm_mmx); -extern prototype_idct_scalar(vp8_dc_only_idct_mmx); extern prototype_second_order(vp8_short_inv_walsh4x4_mmx); extern prototype_second_order(vp8_short_inv_walsh4x4_1_mmx); @@ -34,9 +33,6 @@ extern prototype_second_order(vp8_short_inv_walsh4x4_1_mmx); #undef vp8_idct_idct16 #define vp8_idct_idct16 vp8_short_idct4x4llm_mmx -#undef vp8_idct_idct1_scalar -#define vp8_idct_idct1_scalar vp8_dc_only_idct_mmx - #undef vp8_idct_iwalsh16 #define vp8_idct_iwalsh16 vp8_short_inv_walsh4x4_mmx diff --git a/vp8/common/x86/x86_systemdependent.c b/vp8/common/x86/x86_systemdependent.c index 677eafa84..d7070f8e3 100644 --- a/vp8/common/x86/x86_systemdependent.c +++ b/vp8/common/x86/x86_systemdependent.c @@ -42,7 +42,6 @@ void vp8_arch_x86_common_init(VP8_COMMON *ctx) { rtcd->idct.idct1 = vp8_short_idct4x4llm_1_mmx; rtcd->idct.idct16 = vp8_short_idct4x4llm_mmx; - rtcd->idct.idct1_scalar = vp8_dc_only_idct_mmx; rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_mmx; rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_mmx; diff --git a/vp8/decoder/arm/dequantize_arm.h b/vp8/decoder/arm/dequantize_arm.h index 31fc5d05c..78af0195d 100644 --- a/vp8/decoder/arm/dequantize_arm.h +++ b/vp8/decoder/arm/dequantize_arm.h @@ -14,32 +14,14 @@ #if HAVE_ARMV6 extern prototype_dequant_block(vp8_dequantize_b_v6); -extern prototype_dequant_idct(vp8_dequant_idct_v6); -extern prototype_dequant_idct_dc(vp8_dequant_dc_idct_v6); #undef vp8_dequant_block #define vp8_dequant_block vp8_dequantize_b_v6 -#undef vp8_dequant_idct -#define vp8_dequant_idct vp8_dequant_idct_v6 - -#undef vp8_dequant_idct_dc -#define vp8_dequant_idct_dc vp8_dequant_dc_idct_v6 -#endif - #if HAVE_ARMV7 extern prototype_dequant_block(vp8_dequantize_b_neon); -extern prototype_dequant_idct(vp8_dequant_idct_neon); -extern prototype_dequant_idct_dc(vp8_dequant_dc_idct_neon); #undef vp8_dequant_block #define vp8_dequant_block vp8_dequantize_b_neon -#undef vp8_dequant_idct -#define vp8_dequant_idct vp8_dequant_idct_neon - -#undef vp8_dequant_idct_dc -#define vp8_dequant_idct_dc vp8_dequant_dc_idct_neon -#endif - #endif diff --git a/vp8/decoder/arm/dsystemdependent.c b/vp8/decoder/arm/dsystemdependent.c index 1504216fd..2ea03c415 100644 --- a/vp8/decoder/arm/dsystemdependent.c +++ b/vp8/decoder/arm/dsystemdependent.c @@ -23,8 +23,6 @@ void vp8_dmachine_specific_config(VP8D_COMP *pbi) pbi->mb.rtcd = &pbi->common.rtcd; #if HAVE_ARMV7 pbi->dequant.block = vp8_dequantize_b_neon; - pbi->dequant.idct = vp8_dequant_idct_neon; - pbi->dequant.idct_dc = vp8_dequant_dc_idct_neon; pbi->dboolhuff.start = vp8dx_start_decode_c; pbi->dboolhuff.fill = vp8dx_bool_decoder_fill_c; pbi->dboolhuff.debool = vp8dx_decode_bool_c; @@ -32,8 +30,6 @@ void vp8_dmachine_specific_config(VP8D_COMP *pbi) #elif HAVE_ARMV6 pbi->dequant.block = vp8_dequantize_b_v6; - pbi->dequant.idct = vp8_dequant_idct_v6; - pbi->dequant.idct_dc = vp8_dequant_dc_idct_v6; pbi->dboolhuff.start = vp8dx_start_decode_c; pbi->dboolhuff.fill = vp8dx_bool_decoder_fill_c; pbi->dboolhuff.debool = vp8dx_decode_bool_c; diff --git a/vp8/decoder/decodframe.c b/vp8/decoder/decodframe.c index a5850db6d..5668cef4d 100644 --- a/vp8/decoder/decodframe.c +++ b/vp8/decoder/decodframe.c @@ -126,7 +126,6 @@ static void skip_recon_mb(VP8D_COMP *pbi, MACROBLOCKD *xd) } } - static void clamp_mv_to_umv_border(MV *mv, const MACROBLOCKD *xd) { /* If the MV points so far into the UMV border that no visible pixels @@ -182,110 +181,6 @@ static void clamp_mvs(MACROBLOCKD *xd) } -static void reconstruct_mb(VP8D_COMP *pbi, MACROBLOCKD *xd) -{ - if (xd->frame_type == KEY_FRAME || xd->mbmi.ref_frame == INTRA_FRAME) - { - vp8_build_intra_predictors_mbuv(xd); - - if (xd->mbmi.mode != B_PRED) - { - vp8_build_intra_predictors_mby_ptr(xd); - vp8_recon16x16mb(RTCD_VTABLE(recon), xd); - } - else - { - vp8_recon_intra4x4mb(RTCD_VTABLE(recon), xd); - } - } - else - { - vp8_build_inter_predictors_mb(xd); - vp8_recon16x16mb(RTCD_VTABLE(recon), xd); - } -} - - -static void de_quantand_idct(VP8D_COMP *pbi, MACROBLOCKD *xd) -{ - int i; - BLOCKD *b = &xd->block[24]; - - - if (xd->mbmi.mode != B_PRED && xd->mbmi.mode != SPLITMV) - { - DEQUANT_INVOKE(&pbi->dequant, block)(b); - - // do 2nd order transform on the dc block - if (b->eob > 1) - { - IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff); - ((int *)b->qcoeff)[0] = 0; - ((int *)b->qcoeff)[1] = 0; - ((int *)b->qcoeff)[2] = 0; - ((int *)b->qcoeff)[3] = 0; - ((int *)b->qcoeff)[4] = 0; - ((int *)b->qcoeff)[5] = 0; - ((int *)b->qcoeff)[6] = 0; - ((int *)b->qcoeff)[7] = 0; - } - else - { - IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh1)(&b->dqcoeff[0], b->diff); - ((int *)b->qcoeff)[0] = 0; - } - - - for (i = 0; i < 16; i++) - { - - b = &xd->block[i]; - - if (b->eob > 1) - { - DEQUANT_INVOKE(&pbi->dequant, idct_dc)(b->qcoeff, &b->dequant[0][0], b->diff, 32, xd->block[24].diff[i]); - } - else - { - IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar)(xd->block[24].diff[i], b->diff, 32); - } - } - - for (i = 16; i < 24; i++) - { - b = &xd->block[i]; - - if (b->eob > 1) - { - DEQUANT_INVOKE(&pbi->dequant, idct)(b->qcoeff, &b->dequant[0][0], b->diff, 16); - } - else - { - IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar)(b->qcoeff[0] * b->dequant[0][0], b->diff, 16); - ((int *)b->qcoeff)[0] = 0; - } - } - } - else - { - for (i = 0; i < 24; i++) - { - - b = &xd->block[i]; - - if (b->eob > 1) - { - DEQUANT_INVOKE(&pbi->dequant, idct)(b->qcoeff, &b->dequant[0][0], b->diff, (32 - (i & 16))); - } - else - { - IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar)(b->qcoeff[0] * b->dequant[0][0], b->diff, (32 - (i & 16))); - ((int *)b->qcoeff)[0] = 0; - } - } - } -} - void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd) { int eobtotal = 0; @@ -321,27 +216,122 @@ void vp8_decode_macroblock(VP8D_COMP *pbi, MACROBLOCKD *xd) { xd->mode_info_context->mbmi.dc_diff = 0; skip_recon_mb(pbi, xd); + return; + } + + if (xd->segmentation_enabled) + mb_init_dequantizer(pbi, xd); + + // do prediction + if (xd->frame_type == KEY_FRAME || xd->mbmi.ref_frame == INTRA_FRAME) + { + vp8_build_intra_predictors_mbuv(xd); + + if (xd->mbmi.mode != B_PRED) + { + vp8_build_intra_predictors_mby_ptr(xd); + } else { + vp8_intra_prediction_down_copy(xd); + } } else { - if (xd->segmentation_enabled) - mb_init_dequantizer(pbi, xd); - - de_quantand_idct(pbi, xd); - reconstruct_mb(pbi, xd); + vp8_build_inter_predictors_mb(xd); } - - /* Restore the original MV so as not to affect the entropy context. */ - if (do_clamp) + // dequantization and idct + if (xd->mbmi.mode != B_PRED && xd->mbmi.mode != SPLITMV) { - if (xd->mbmi.mode == SPLITMV) - for (i=0; i<24; i++) - xd->block[i].bmi.mv.as_mv = orig_mvs[i]; + BLOCKD *b = &xd->block[24]; + DEQUANT_INVOKE(&pbi->dequant, block)(b); + + // do 2nd order transform on the dc block + if (b->eob > 1) + { + IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh16)(&b->dqcoeff[0], b->diff); + ((int *)b->qcoeff)[0] = 0; + ((int *)b->qcoeff)[1] = 0; + ((int *)b->qcoeff)[2] = 0; + ((int *)b->qcoeff)[3] = 0; + ((int *)b->qcoeff)[4] = 0; + ((int *)b->qcoeff)[5] = 0; + ((int *)b->qcoeff)[6] = 0; + ((int *)b->qcoeff)[7] = 0; + } else { - xd->mbmi.mv.as_mv = orig_mvs[0]; - xd->block[16].bmi.mv.as_mv = orig_mvs[1]; + IDCT_INVOKE(RTCD_VTABLE(idct), iwalsh1)(&b->dqcoeff[0], b->diff); + ((int *)b->qcoeff)[0] = 0; + } + + + for (i = 0; i < 16; i++) + { + + b = &xd->block[i]; + + if (b->eob > 1) + { + DEQUANT_INVOKE(&pbi->dequant, idct_dc_add)(b->qcoeff, &b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride, + xd->block[24].diff[i]); + } + else + { + IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)(xd->block[24].diff[i], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride); + } + } + } + else if ((xd->frame_type == KEY_FRAME || xd->mbmi.ref_frame == INTRA_FRAME) && xd->mbmi.mode == B_PRED) + { + for (i = 0; i < 16; i++) + { + + BLOCKD *b = &xd->block[i]; + vp8_predict_intra4x4(b, b->bmi.mode, b->predictor); + + if (b->eob > 1) + { + DEQUANT_INVOKE(&pbi->dequant, idct_add)(b->qcoeff, &b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride); + } + else + { + IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)(b->qcoeff[0] * b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride); + ((int *)b->qcoeff)[0] = 0; + } + } + + } + else + { + for (i = 0; i < 16; i++) + { + BLOCKD *b = &xd->block[i]; + + if (b->eob > 1) + { + DEQUANT_INVOKE(&pbi->dequant, idct_add)(b->qcoeff, &b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride); + } + else + { + IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)(b->qcoeff[0] * b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 16, b->dst_stride); + ((int *)b->qcoeff)[0] = 0; + } + } + } + + for (i = 16; i < 24; i++) + { + + BLOCKD *b = &xd->block[i]; + + if (b->eob > 1) + { + DEQUANT_INVOKE(&pbi->dequant, idct_add)(b->qcoeff, &b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 8, b->dst_stride); + } + else + { + IDCT_INVOKE(RTCD_VTABLE(idct), idct1_scalar_add)(b->qcoeff[0] * b->dequant[0][0], b->predictor, *(b->base_dst) + b->dst, 8, b->dst_stride); + ((int *)b->qcoeff)[0] = 0; } } } diff --git a/vp8/decoder/dequantize.c b/vp8/decoder/dequantize.c index b023d28eb..4c924ffb9 100644 --- a/vp8/decoder/dequantize.c +++ b/vp8/decoder/dequantize.c @@ -32,8 +32,12 @@ void vp8_dequantize_b_c(BLOCKD *d) } } -void vp8_dequant_idct_c(short *input, short *dq, short *output, int pitch) +void vp8_dequant_idct_add_c(short *input, short *dq, unsigned char *pred, unsigned char *dest, int pitch, int stride) { + // output needs to be at least pitch * 4 for vp8_short_idct4x4llm_c to work properly + short output[16*4]; + short *diff_ptr = output; + int r, c; int i; for (i = 0; i < 16; i++) @@ -41,13 +45,38 @@ void vp8_dequant_idct_c(short *input, short *dq, short *output, int pitch) input[i] = dq[i] * input[i]; } - vp8_short_idct4x4llm_c(input, output, pitch); + vp8_short_idct4x4llm_c(input, output, pitch*2); + vpx_memset(input, 0, 32); + + for (r = 0; r < 4; r++) + { + for (c = 0; c < 4; c++) + { + int a = diff_ptr[c] + pred[c]; + + if (a < 0) + a = 0; + + if (a > 255) + a = 255; + + dest[c] = (unsigned char) a; + } + + dest += stride; + diff_ptr += pitch; + pred += pitch; + } } -void vp8_dequant_dc_idct_c(short *input, short *dq, short *output, int pitch, int Dc) +void vp8_dequant_dc_idct_add_c(short *input, short *dq, unsigned char *pred, unsigned char *dest, int pitch, int stride, int Dc) { int i; + // output needs to be at least pitch * 4 for vp8_short_idct4x4llm_c to work properly + short output[16*4]; + short *diff_ptr = output; + int r, c; input[0] = (short)Dc; @@ -56,6 +85,27 @@ void vp8_dequant_dc_idct_c(short *input, short *dq, short *output, int pitch, in input[i] = dq[i] * input[i]; } - vp8_short_idct4x4llm_c(input, output, pitch); + vp8_short_idct4x4llm_c(input, output, pitch*2); + vpx_memset(input, 0, 32); + + for (r = 0; r < 4; r++) + { + for (c = 0; c < 4; c++) + { + int a = diff_ptr[c] + pred[c]; + + if (a < 0) + a = 0; + + if (a > 255) + a = 255; + + dest[c] = (unsigned char) a; + } + + dest += stride; + diff_ptr += pitch; + pred += pitch; + } } diff --git a/vp8/decoder/dequantize.h b/vp8/decoder/dequantize.h index a02ea7e81..50293c2f7 100644 --- a/vp8/decoder/dequantize.h +++ b/vp8/decoder/dequantize.h @@ -16,11 +16,16 @@ #define prototype_dequant_block(sym) \ void sym(BLOCKD *x) -#define prototype_dequant_idct(sym) \ - void sym(short *input, short *dq, short *output, int pitch) +#define prototype_dequant_idct_add(sym) \ + void sym(short *input, short *dq, \ + unsigned char *pred, unsigned char *output, \ + int pitch, int stride) -#define prototype_dequant_idct_dc(sym) \ - void sym(short *input, short *dq, short *output, int pitch, int dc) +#define prototype_dequant_idct_dc_add(sym) \ + void sym(short *input, short *dq, \ + unsigned char *pred, unsigned char *output, \ + int pitch, int stride, \ + int dc) #if ARCH_X86 || ARCH_X86_64 #include "x86/dequantize_x86.h" @@ -35,25 +40,26 @@ #endif extern prototype_dequant_block(vp8_dequant_block); -#ifndef vp8_dequant_idct -#define vp8_dequant_idct vp8_dequant_idct_c +#ifndef vp8_dequant_idct_add +#define vp8_dequant_idct_add vp8_dequant_idct_add_c #endif -extern prototype_dequant_idct(vp8_dequant_idct); +extern prototype_dequant_idct_add(vp8_dequant_idct_add); -#ifndef vp8_dequant_idct_dc -#define vp8_dequant_idct_dc vp8_dequant_dc_idct_c +#ifndef vp8_dequant_idct_dc_add +#define vp8_dequant_idct_dc_add vp8_dequant_dc_idct_add_c #endif -extern prototype_dequant_idct_dc(vp8_dequant_idct_dc); - +extern prototype_dequant_idct_dc_add(vp8_dequant_idct_dc_add); typedef prototype_dequant_block((*vp8_dequant_block_fn_t)); -typedef prototype_dequant_idct((*vp8_dequant_idct_fn_t)); -typedef prototype_dequant_idct_dc((*vp8_dequant_idct_dc_fn_t)); + +typedef prototype_dequant_idct_add((*vp8_dequant_idct_add_fn_t)); +typedef prototype_dequant_idct_dc_add((*vp8_dequant_idct_dc_add_fn_t)); + typedef struct { - vp8_dequant_block_fn_t block; - vp8_dequant_idct_fn_t idct; - vp8_dequant_idct_dc_fn_t idct_dc; + vp8_dequant_block_fn_t block; + vp8_dequant_idct_add_fn_t idct_add; + vp8_dequant_idct_dc_add_fn_t idct_dc_add; } vp8_dequant_rtcd_vtable_t; #if CONFIG_RUNTIME_CPU_DETECT diff --git a/vp8/decoder/generic/dsystemdependent.c b/vp8/decoder/generic/dsystemdependent.c index 272d422ad..c72597f4a 100644 --- a/vp8/decoder/generic/dsystemdependent.c +++ b/vp8/decoder/generic/dsystemdependent.c @@ -21,8 +21,8 @@ void vp8_dmachine_specific_config(VP8D_COMP *pbi) #if CONFIG_RUNTIME_CPU_DETECT pbi->mb.rtcd = &pbi->common.rtcd; pbi->dequant.block = vp8_dequantize_b_c; - pbi->dequant.idct = vp8_dequant_idct_c; - pbi->dequant.idct_dc = vp8_dequant_dc_idct_c; + pbi->dequant.idct_add = vp8_dequant_idct_add_c; + pbi->dequant.idct_dc_add = vp8_dequant_dc_idct_add_c; pbi->dboolhuff.start = vp8dx_start_decode_c; pbi->dboolhuff.fill = vp8dx_bool_decoder_fill_c; #if 0 //For use with RTCD, when implemented diff --git a/vp8/decoder/x86/dequantize_x86.h b/vp8/decoder/x86/dequantize_x86.h index 743a8f5dd..563d58460 100644 --- a/vp8/decoder/x86/dequantize_x86.h +++ b/vp8/decoder/x86/dequantize_x86.h @@ -21,20 +21,12 @@ */ #if HAVE_MMX extern prototype_dequant_block(vp8_dequantize_b_mmx); -extern prototype_dequant_idct(vp8_dequant_idct_mmx); -extern prototype_dequant_idct_dc(vp8_dequant_dc_idct_mmx); #if !CONFIG_RUNTIME_CPU_DETECT #undef vp8_dequant_block #define vp8_dequant_block vp8_dequantize_b_mmx -#undef vp8_dequant_idct -#define vp8_dequant_idct vp8_dequant_idct_mmx - -#undef vp8_dequant_idct_dc -#define vp8_dequant_idct_dc vp8_dequant_dc_idct_mmx - #endif #endif diff --git a/vp8/decoder/x86/x86_dsystemdependent.c b/vp8/decoder/x86/x86_dsystemdependent.c index 957fb1d67..bcd2acc75 100644 --- a/vp8/decoder/x86/x86_dsystemdependent.c +++ b/vp8/decoder/x86/x86_dsystemdependent.c @@ -43,8 +43,6 @@ void vp8_arch_x86_decode_init(VP8D_COMP *pbi) if (flags & HAS_MMX) { pbi->dequant.block = vp8_dequantize_b_mmx; - pbi->dequant.idct = vp8_dequant_idct_mmx; - pbi->dequant.idct_dc = vp8_dequant_dc_idct_mmx; } #endif From 98fcccfe9751894ace9693a39ba0609fe5ea904d Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Thu, 3 Jun 2010 10:16:07 -0400 Subject: [PATCH 2/2] Change the x86 idct functions to do reconstruction at the same time Change-Id: I896fe6f9664e6849c7cee2cc6bb4e045eb42540f --- vp8/common/x86/idct_x86.h | 4 ++ vp8/common/x86/idctllm_mmx.asm | 58 +++++++++++----- vp8/common/x86/x86_systemdependent.c | 1 + vp8/decoder/x86/dequantize_mmx.asm | 93 +++++++++++++++++++------- vp8/decoder/x86/dequantize_x86.h | 8 +++ vp8/decoder/x86/x86_dsystemdependent.c | 2 + 6 files changed, 127 insertions(+), 39 deletions(-) diff --git a/vp8/common/x86/idct_x86.h b/vp8/common/x86/idct_x86.h index d7b4fc95c..f1e433d5c 100644 --- a/vp8/common/x86/idct_x86.h +++ b/vp8/common/x86/idct_x86.h @@ -22,6 +22,7 @@ #if HAVE_MMX extern prototype_idct(vp8_short_idct4x4llm_1_mmx); extern prototype_idct(vp8_short_idct4x4llm_mmx); +extern prototype_idct_scalar_add(vp8_dc_only_idct_add_mmx); extern prototype_second_order(vp8_short_inv_walsh4x4_mmx); extern prototype_second_order(vp8_short_inv_walsh4x4_1_mmx); @@ -33,6 +34,9 @@ extern prototype_second_order(vp8_short_inv_walsh4x4_1_mmx); #undef vp8_idct_idct16 #define vp8_idct_idct16 vp8_short_idct4x4llm_mmx +#undef vp8_idct_idct1_scalar_add +#define vp8_idct_idct1_scalar_add vp8_dc_only_idct_add_mmx + #undef vp8_idct_iwalsh16 #define vp8_idct_iwalsh16 vp8_short_inv_walsh4x4_mmx diff --git a/vp8/common/x86/idctllm_mmx.asm b/vp8/common/x86/idctllm_mmx.asm index 1b18bd38d..b0d4a0c0d 100644 --- a/vp8/common/x86/idctllm_mmx.asm +++ b/vp8/common/x86/idctllm_mmx.asm @@ -220,35 +220,61 @@ sym(vp8_short_idct4x4llm_1_mmx): pop rbp ret -;void dc_only_idct_mmx(short input_dc, short *output, int pitch) -global sym(vp8_dc_only_idct_mmx) -sym(vp8_dc_only_idct_mmx): +;void vp8_dc_only_idct_add_mmx(short input_dc, unsigned char *pred_ptr, unsigned char *dst_ptr, int pitch, int stride) +global sym(vp8_dc_only_idct_add_mmx) +sym(vp8_dc_only_idct_add_mmx): push rbp mov rbp, rsp - SHADOW_ARGS_TO_STACK 3 + SHADOW_ARGS_TO_STACK 5 GET_GOT rbx + push rsi + push rdi ; end prolog - movd mm0, arg(0) ;input_dc + mov rsi, arg(1) ;s -- prediction + mov rdi, arg(2) ;d -- destination + movsxd rax, dword ptr arg(4) ;stride + movsxd rdx, dword ptr arg(3) ;pitch + pxor mm0, mm0 - paddw mm0, [fours GLOBAL] - mov rdx, arg(1) ;output + movd mm5, arg(0) ;input_dc - psraw mm0, 3 - movsxd rax, dword ptr arg(2) ;pitch + paddw mm5, [fours GLOBAL] - punpcklwd mm0, mm0 - punpckldq mm0, mm0 + psraw mm5, 3 - movq [rdx], mm0 - movq [rdx+rax], mm0 + punpcklwd mm5, mm5 + punpckldq mm5, mm5 - movq [rdx+rax*2], mm0 - add rdx, rax + movd mm1, [rsi] + punpcklbw mm1, mm0 + paddsw mm1, mm5 + packuswb mm1, mm0 ; pack and unpack to saturate + movd [rdi], mm1 - movq [rdx+rax*2], mm0 + movd mm2, [rsi+rdx] + punpcklbw mm2, mm0 + paddsw mm2, mm5 + packuswb mm2, mm0 ; pack and unpack to saturate + movd [rdi+rax], mm2 + + movd mm3, [rsi+2*rdx] + punpcklbw mm3, mm0 + paddsw mm3, mm5 + packuswb mm3, mm0 ; pack and unpack to saturate + movd [rdi+2*rax], mm3 + + add rdi, rax + add rsi, rdx + movd mm4, [rsi+2*rdx] + punpcklbw mm4, mm0 + paddsw mm4, mm5 + packuswb mm4, mm0 ; pack and unpack to saturate + movd [rdi+2*rax], mm4 ; begin epilog + pop rdi + pop rsi RESTORE_GOT UNSHADOW_ARGS pop rbp diff --git a/vp8/common/x86/x86_systemdependent.c b/vp8/common/x86/x86_systemdependent.c index d7070f8e3..66738f855 100644 --- a/vp8/common/x86/x86_systemdependent.c +++ b/vp8/common/x86/x86_systemdependent.c @@ -42,6 +42,7 @@ void vp8_arch_x86_common_init(VP8_COMMON *ctx) { rtcd->idct.idct1 = vp8_short_idct4x4llm_1_mmx; rtcd->idct.idct16 = vp8_short_idct4x4llm_mmx; + rtcd->idct.idct1_scalar_add = vp8_dc_only_idct_add_mmx; rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_mmx; rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_mmx; diff --git a/vp8/decoder/x86/dequantize_mmx.asm b/vp8/decoder/x86/dequantize_mmx.asm index 2dcf548f6..7ad9289cc 100644 --- a/vp8/decoder/x86/dequantize_mmx.asm +++ b/vp8/decoder/x86/dequantize_mmx.asm @@ -50,12 +50,12 @@ sym(vp8_dequantize_b_impl_mmx): ret -;void dequant_idct_mmx(short *input, short *dq, short *output, int pitch) -global sym(vp8_dequant_idct_mmx) -sym(vp8_dequant_idct_mmx): +;void dequant_idct_add_mmx(short *input, short *dq, unsigned char *pred, unsigned char *dest, int pitch, int stride) +global sym(vp8_dequant_idct_add_mmx) +sym(vp8_dequant_idct_add_mmx): push rbp mov rbp, rsp - SHADOW_ARGS_TO_STACK 4 + SHADOW_ARGS_TO_STACK 6 GET_GOT rbx push rsi push rdi @@ -77,7 +77,8 @@ sym(vp8_dequant_idct_mmx): movq mm3, [rax+24] pmullw mm3, [rdx+24] - mov rdx, arg(2) ;output + mov rdx, arg(3) ;dest + mov rsi, arg(2) ;pred pxor mm7, mm7 @@ -88,7 +89,8 @@ sym(vp8_dequant_idct_mmx): movq [rax+24],mm7 - movsxd rax, dword ptr arg(3) ;pitch + movsxd rax, dword ptr arg(4) ;pitch + movsxd rdi, dword ptr arg(5) ;stride psubw mm0, mm2 ; b1= 0-2 paddw mm2, mm2 ; @@ -207,13 +209,34 @@ sym(vp8_dequant_idct_mmx): punpckldq mm2, mm4 ; 32 22 12 02 punpckhdq mm5, mm4 ; 33 23 13 03 - movq [rdx], mm0 + pxor mm7, mm7 - movq [rdx+rax], mm1 - movq [rdx+rax*2], mm2 + movd mm4, [rsi] + punpcklbw mm4, mm7 + paddsw mm0, mm4 + packuswb mm0, mm7 + movd [rdx], mm0 - add rdx, rax - movq [rdx+rax*2], mm5 + movd mm4, [rsi+rax] + punpcklbw mm4, mm7 + paddsw mm1, mm4 + packuswb mm1, mm7 + movd [rdx+rdi], mm1 + + movd mm4, [rsi+2*rax] + punpcklbw mm4, mm7 + paddsw mm2, mm4 + packuswb mm2, mm7 + movd [rdx+rdi*2], mm2 + + add rdx, rdi + add rsi, rax + + movd mm4, [rsi+2*rax] + punpcklbw mm4, mm7 + paddsw mm5, mm4 + packuswb mm5, mm7 + movd [rdx+rdi*2], mm5 ; begin epilog pop rdi @@ -224,12 +247,12 @@ sym(vp8_dequant_idct_mmx): ret -;void dequant_dc_idct_mmx(short *input, short *dq, short *output, int pitch, int Dc) -global sym(vp8_dequant_dc_idct_mmx) -sym(vp8_dequant_dc_idct_mmx): +;void dequant_dc_idct_add_mmx(short *input, short *dq, unsigned char *pred, unsigned char *dest, int pitch, int stride, int Dc) +global sym(vp8_dequant_dc_idct_add_mmx) +sym(vp8_dequant_dc_idct_add_mmx): push rbp mov rbp, rsp - SHADOW_ARGS_TO_STACK 5 + SHADOW_ARGS_TO_STACK 7 GET_GOT rbx push rsi push rdi @@ -238,7 +261,7 @@ sym(vp8_dequant_dc_idct_mmx): mov rax, arg(0) ;input mov rdx, arg(1) ;dq - movsxd rcx, dword ptr arg(4) ;Dc + movsxd rcx, dword ptr arg(6) ;Dc movq mm0, [rax ] pmullw mm0, [rdx] @@ -252,7 +275,8 @@ sym(vp8_dequant_dc_idct_mmx): movq mm3, [rax+24] pmullw mm3, [rdx+24] - mov rdx, arg(2) ;output + mov rdx, arg(3) ;dest + mov rsi, arg(2) ;pred pxor mm7, mm7 @@ -262,8 +286,10 @@ sym(vp8_dequant_dc_idct_mmx): movq [rax+16],mm7 movq [rax+24],mm7 + pinsrw mm0, rcx, 0 - movsxd rax, dword ptr arg(3) ;pitch + movsxd rax, dword ptr arg(4) ;pitch + movsxd rdi, dword ptr arg(5) ;stride psubw mm0, mm2 ; b1= 0-2 paddw mm2, mm2 ; @@ -382,13 +408,34 @@ sym(vp8_dequant_dc_idct_mmx): punpckldq mm2, mm4 ; 32 22 12 02 punpckhdq mm5, mm4 ; 33 23 13 03 - movq [rdx], mm0 + pxor mm7, mm7 - movq [rdx+rax], mm1 - movq [rdx+rax*2], mm2 + movd mm4, [rsi] + punpcklbw mm4, mm7 + paddsw mm0, mm4 + packuswb mm0, mm7 + movd [rdx], mm0 - add rdx, rax - movq [rdx+rax*2], mm5 + movd mm4, [rsi+rax] + punpcklbw mm4, mm7 + paddsw mm1, mm4 + packuswb mm1, mm7 + movd [rdx+rdi], mm1 + + movd mm4, [rsi+2*rax] + punpcklbw mm4, mm7 + paddsw mm2, mm4 + packuswb mm2, mm7 + movd [rdx+rdi*2], mm2 + + add rdx, rdi + add rsi, rax + + movd mm4, [rsi+2*rax] + punpcklbw mm4, mm7 + paddsw mm5, mm4 + packuswb mm5, mm7 + movd [rdx+rdi*2], mm5 ; begin epilog pop rdi diff --git a/vp8/decoder/x86/dequantize_x86.h b/vp8/decoder/x86/dequantize_x86.h index 563d58460..32e777994 100644 --- a/vp8/decoder/x86/dequantize_x86.h +++ b/vp8/decoder/x86/dequantize_x86.h @@ -21,12 +21,20 @@ */ #if HAVE_MMX extern prototype_dequant_block(vp8_dequantize_b_mmx); +extern prototype_dequant_idct_add(vp8_dequant_idct_add_mmx); +extern prototype_dequant_idct_dc_add(vp8_dequant_dc_idct_add_mmx); #if !CONFIG_RUNTIME_CPU_DETECT #undef vp8_dequant_block #define vp8_dequant_block vp8_dequantize_b_mmx +#undef vp8_dequant_idct_add +#define vp8_dequant_idct_add vp8_dequant_idct_add_mmx + +#undef vp8_dequant_idct_dc +#define vp8_dequant_idct_add_dc vp8_dequant_dc_idct_add_mmx + #endif #endif diff --git a/vp8/decoder/x86/x86_dsystemdependent.c b/vp8/decoder/x86/x86_dsystemdependent.c index bcd2acc75..d7bed0873 100644 --- a/vp8/decoder/x86/x86_dsystemdependent.c +++ b/vp8/decoder/x86/x86_dsystemdependent.c @@ -43,6 +43,8 @@ void vp8_arch_x86_decode_init(VP8D_COMP *pbi) if (flags & HAS_MMX) { pbi->dequant.block = vp8_dequantize_b_mmx; + pbi->dequant.idct_add = vp8_dequant_idct_add_mmx; + pbi->dequant.idct_dc_add = vp8_dequant_dc_idct_add_mmx; } #endif