From 0c8e5fb21183cba79223d3ba06d48adb90004f4d Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 24 Jan 2014 17:11:39 +0100 Subject: [PATCH] avcodec/mpeg12dec: Optimize mpeg1_decode_block_intra() sandybridge i7 274->260 cycles Signed-off-by: Michael Niedermayer --- libavcodec/mpeg12dec.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index a4ff5d6925..86011d11e3 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -142,29 +142,30 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, in i = 0; { OPEN_READER(re, &s->gb); + UPDATE_CACHE(re, &s->gb); + if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) + goto end; + /* now quantify & encode AC coefficients */ for (;;) { - UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); - if (level == 127) { - break; - } else if (level != 0) { + if (level != 0) { i += run; j = scantable[i]; level = (level * qscale * quant_matrix[j]) >> 4; level = (level - 1) | 1; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); - LAST_SKIP_BITS(re, &s->gb, 1); + SKIP_BITS(re, &s->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); UPDATE_CACHE(re, &s->gb); level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); if (level == -128) { - level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); + level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); } else if (level == 0) { - level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); + level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); } i += run; j = scantable[i]; @@ -184,7 +185,13 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, int16_t *block, in } block[j] = level; + if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) + break; + + UPDATE_CACHE(re, &s->gb); } +end: + LAST_SKIP_BITS(re, &s->gb, 2); CLOSE_READER(re, &s->gb); } s->block_last_index[n] = i;