From 5fecfb7d58a12baf326e99f2d071060f2638d93c Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Wed, 10 Dec 2008 21:35:17 +0000 Subject: [PATCH] clear_block mmx Originally committed as revision 16045 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/dsputil.c | 6 +++++ libavcodec/dsputil.h | 1 + libavcodec/h263.c | 6 ++--- libavcodec/i386/dsputil_mmx.c | 50 ++++++++++++++++++++++++++--------- libavcodec/intrax8.c | 2 +- libavcodec/mimic.c | 2 +- libavcodec/mjpegdec.c | 4 +-- libavcodec/vp3.c | 4 +-- libavcodec/vp56.c | 2 +- libavcodec/wmv2.c | 4 +-- 10 files changed, 56 insertions(+), 25 deletions(-) diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index 4c8fab4f86..a97fb1e2cd 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -3420,6 +3420,11 @@ void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ } } +static void clear_block_c(DCTELEM *block) +{ + memset(block, 0, sizeof(DCTELEM)*64); +} + /** * memset(blocks, 0, sizeof(DCTELEM)*6*64) */ @@ -4288,6 +4293,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->sum_abs_dctelem = sum_abs_dctelem_c; c->gmc1 = gmc1_c; c->gmc = ff_gmc_c; + c->clear_block = clear_block_c; c->clear_blocks = clear_blocks_c; c->pix_sum = pix_sum_c; c->pix_norm1 = pix_norm1_c; diff --git a/libavcodec/dsputil.h b/libavcodec/dsputil.h index 66a46d72a7..1864cc70d6 100644 --- a/libavcodec/dsputil.h +++ b/libavcodec/dsputil.h @@ -203,6 +203,7 @@ typedef struct DSPContext { */ void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); + void (*clear_block)(DCTELEM *block/*align 16*/); void (*clear_blocks)(DCTELEM *blocks/*align 16*/); int (*pix_sum)(uint8_t * pix, int line_size); int (*pix_norm1)(uint8_t * pix, int line_size); diff --git a/libavcodec/h263.c b/libavcodec/h263.c index 7d88f06bde..cb7183045f 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -810,7 +810,7 @@ static inline int get_p_cbp(MpegEncContext * s, for (i = 0; i < 6; i++) { if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ s->block_last_index[i]= -1; - memset(s->block[i], 0, sizeof(DCTELEM)*64); + s->dsp.clear_block(s->block[i]); } } }else{ @@ -853,7 +853,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], for (i = 0; i < 6; i++) { if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ s->block_last_index[i]= -1; - memset(s->block[i], 0, sizeof(DCTELEM)*64); + s->dsp.clear_block(s->block[i]); } } }else{ @@ -4651,7 +4651,7 @@ retry: rl = &rl_intra_aic; i = 0; s->gb= gb; - memset(block, 0, sizeof(DCTELEM)*64); + s->dsp.clear_block(block); goto retry; } av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); diff --git a/libavcodec/i386/dsputil_mmx.c b/libavcodec/i386/dsputil_mmx.c index 28e0e83bbd..c3dcb77842 100644 --- a/libavcodec/i386/dsputil_mmx.c +++ b/libavcodec/i386/dsputil_mmx.c @@ -464,21 +464,42 @@ static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_si ); } -static void clear_blocks_mmx(DCTELEM *blocks) +#define CLEAR_BLOCKS(name,n) \ +static void name(DCTELEM *blocks)\ +{\ + __asm__ volatile(\ + "pxor %%mm7, %%mm7 \n\t"\ + "mov %1, %%"REG_a" \n\t"\ + "1: \n\t"\ + "movq %%mm7, (%0, %%"REG_a") \n\t"\ + "movq %%mm7, 8(%0, %%"REG_a") \n\t"\ + "movq %%mm7, 16(%0, %%"REG_a") \n\t"\ + "movq %%mm7, 24(%0, %%"REG_a") \n\t"\ + "add $32, %%"REG_a" \n\t"\ + " js 1b \n\t"\ + : : "r" (((uint8_t *)blocks)+128*n),\ + "i" (-128*n)\ + : "%"REG_a\ + );\ +} +CLEAR_BLOCKS(clear_blocks_mmx, 6) +CLEAR_BLOCKS(clear_block_mmx, 1) + +static void clear_block_sse(DCTELEM *block) { __asm__ volatile( - "pxor %%mm7, %%mm7 \n\t" - "mov $-128*6, %%"REG_a" \n\t" - "1: \n\t" - "movq %%mm7, (%0, %%"REG_a") \n\t" - "movq %%mm7, 8(%0, %%"REG_a") \n\t" - "movq %%mm7, 16(%0, %%"REG_a") \n\t" - "movq %%mm7, 24(%0, %%"REG_a") \n\t" - "add $32, %%"REG_a" \n\t" - " js 1b \n\t" - : : "r" (((uint8_t *)blocks)+128*6) - : "%"REG_a - ); + "xorps %%xmm0, %%xmm0 \n" + "movaps %%xmm0, (%0) \n" + "movaps %%xmm0, 16(%0) \n" + "movaps %%xmm0, 32(%0) \n" + "movaps %%xmm0, 48(%0) \n" + "movaps %%xmm0, 64(%0) \n" + "movaps %%xmm0, 80(%0) \n" + "movaps %%xmm0, 96(%0) \n" + "movaps %%xmm0, 112(%0) \n" + :: "r"(block) + : "memory" + ); } static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){ @@ -2569,7 +2590,10 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->put_pixels_clamped = put_pixels_clamped_mmx; c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx; c->add_pixels_clamped = add_pixels_clamped_mmx; + c->clear_block = clear_block_mmx; c->clear_blocks = clear_blocks_mmx; + if (mm_flags & FF_MM_SSE) + c->clear_block = clear_block_sse; #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \ c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \ diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 0436deb4ce..04fdf03852 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -511,7 +511,7 @@ static int x8_decode_intra_mb(IntraX8Context* const w, const int chroma){ int sign; assert(w->orient<12); - memset(s->block[0],0x00,64*sizeof(DCTELEM)); + s->dsp.clear_block(s->block[0]); if(chroma){ dc_mode=2; diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c index b740275fc4..e30b682e69 100644 --- a/libavcodec/mimic.c +++ b/libavcodec/mimic.c @@ -163,7 +163,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale) DCTELEM *block = ctx->dct_block; unsigned int pos; - memset(block, 0, 64 * sizeof(DCTELEM)); + ctx->dsp.clear_block(block); block[0] = get_bits(&ctx->gb, 8) << 3; diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 54beb76dae..5dcdb73976 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -444,7 +444,7 @@ static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, int comp int dc_index, int16_t *quant_matrix, int Al) { int val; - memset(block, 0, 64*sizeof(DCTELEM)); + s->dsp.clear_block(block); val = mjpeg_decode_dc(s, dc_index); if (val == 0xffff) { av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); @@ -800,7 +800,7 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i if(s->interlaced && s->bottom_field) ptr += linesize[c] >> 1; if(!s->progressive) { - memset(s->block, 0, sizeof(s->block)); + s->dsp.clear_block(s->block); if(decode_block(s, s->block, i, s->dc_index[i], s->ac_index[i], s->quant_matrixes[ s->quant_index[c] ]) < 0) { diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index a5b97adb9e..27370253ce 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -1402,14 +1402,14 @@ static void render_slice(Vp3DecodeContext *s, int slice) /* dequantize the DCT coefficients */ if(s->avctx->idct_algo==FF_IDCT_VP3){ Coeff *coeff= s->coeffs + i; - memset(block, 0, sizeof(block)); + s->dsp.clear_block(block); while(coeff->next){ block[coeff->index]= coeff->coeff * dequantizer[coeff->index]; coeff= coeff->next; } }else{ Coeff *coeff= s->coeffs + i; - memset(block, 0, sizeof(block)); + s->dsp.clear_block(block); while(coeff->next){ block[coeff->index]= (coeff->coeff * dequantizer[coeff->index] + 2)>>2; coeff= coeff->next; diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c index c9daaf7800..30306c42a2 100644 --- a/libavcodec/vp56.c +++ b/libavcodec/vp56.c @@ -405,7 +405,7 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col, int is_alpha) mb_type = vp56_decode_mv(s, row, col); ref_frame = vp56_reference_frame[mb_type]; - memset(s->block_coeff, 0, sizeof(s->block_coeff)); + s->dsp.clear_blocks(*s->block_coeff); s->parse_coeff(s); diff --git a/libavcodec/wmv2.c b/libavcodec/wmv2.c index 1e29363cf9..015e3f28b9 100644 --- a/libavcodec/wmv2.c +++ b/libavcodec/wmv2.c @@ -43,12 +43,12 @@ static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int st case 1: ff_simple_idct84_add(dst , stride, block1); ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]); - memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM)); + s->dsp.clear_block(w->abt_block2[n]); break; case 2: ff_simple_idct48_add(dst , stride, block1); ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]); - memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM)); + s->dsp.clear_block(w->abt_block2[n]); break; default: av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");