From fe1b5d974acf7736151e2e13f2498f4fbd6af765 Mon Sep 17 00:00:00 2001 From: David Conrad Date: Fri, 23 Jul 2010 21:46:17 +0000 Subject: Decode DCT tokens by branching to a different code path for each branch on the huffman tree, instead of traversing the tree in a while loop. Based on the similar optimization in libvpx's detokenize.c 10% faster at normal bitrates, and 30% faster for high-bitrate intra-only Originally committed as revision 24468 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/vp56.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libavcodec/vp56.h') diff --git a/libavcodec/vp56.h b/libavcodec/vp56.h index b7c1887596..ad07a49e9b 100644 --- a/libavcodec/vp56.h +++ b/libavcodec/vp56.h @@ -226,6 +226,24 @@ static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) return bit; } +// branchy variant, to be used where there's a branch based on the bit decoded +static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob) +{ + unsigned long code_word = vp56_rac_renorm(c); + unsigned low = 1 + (((c->high - 1) * prob) >> 8); + unsigned low_shift = low << 8; + + if (code_word >= low_shift) { + c->high -= low; + c->code_word = code_word - low_shift; + return 1; + } + + c->high = low; + c->code_word = code_word; + return 0; +} + static inline int vp56_rac_get(VP56RangeCoder *c) { unsigned int code_word = vp56_rac_renorm(c); -- cgit v1.2.3