comparison vp56.h @ 12251:bbe8e7233c5d libavcodec

Split renorm of vp56 arith decoder to its own function
author conrad
date Fri, 23 Jul 2010 21:46:08 +0000
parents 0d81ba00151a
children b8211cda076d
comparison
equal deleted inserted replaced
12250:0d81ba00151a 12251:bbe8e7233c5d
189 c->buffer = buf; 189 c->buffer = buf;
190 c->end = buf + buf_size; 190 c->end = buf + buf_size;
191 c->code_word = bytestream_get_be16(&c->buffer); 191 c->code_word = bytestream_get_be16(&c->buffer);
192 } 192 }
193 193
194 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) 194 static av_always_inline void vp56_rac_renorm(VP56RangeCoder *c, unsigned int code_word)
195 { 195 {
196 /* Don't put c->high in a local variable; if we do that, gcc gets 196 int shift = ff_h264_norm_shift[c->high] - 1;
197 * the stupids and turns the code below into a branch again. */
198 int bits = c->bits; 197 int bits = c->bits;
199 unsigned int code_word = c->code_word; 198
200 unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
201 unsigned int low_shift = low << 8;
202 int bit = code_word >= low_shift;
203 int shift;
204
205 /* Incantation to convince GCC to turn these into conditional moves
206 * instead of branches -- faster, as this branch is basically
207 * unpredictable. */
208 c->high = bit ? c->high - low : low;
209 code_word = bit ? code_word - low_shift : code_word;
210
211 /* normalize */
212 shift = ff_h264_norm_shift[c->high] - 1;
213 c->high <<= shift; 199 c->high <<= shift;
214 code_word <<= shift; 200 code_word <<= shift;
215 bits += shift; 201 bits += shift;
216 if(bits >= 0 && c->buffer < c->end) { 202 if(bits >= 0 && c->buffer < c->end) {
217 code_word |= *c->buffer++ << bits; 203 code_word |= *c->buffer++ << bits;
218 bits -= 8; 204 bits -= 8;
219 } 205 }
220 c->bits = bits; 206 c->bits = bits;
221 c->code_word = code_word; 207 c->code_word = code_word;
208 }
209
210 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
211 {
212 /* Don't put c->high in a local variable; if we do that, gcc gets
213 * the stupids and turns the code below into a branch again. */
214 unsigned int code_word = c->code_word;
215 unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
216 unsigned int low_shift = low << 8;
217 int bit = code_word >= low_shift;
218
219 /* Incantation to convince GCC to turn these into conditional moves
220 * instead of branches -- faster, as this branch is basically
221 * unpredictable. */
222 c->high = bit ? c->high - low : low;
223 code_word = bit ? code_word - low_shift : code_word;
224
225 vp56_rac_renorm(c, code_word);
222 return bit; 226 return bit;
223 } 227 }
224 228
225 static inline int vp56_rac_get(VP56RangeCoder *c) 229 static inline int vp56_rac_get(VP56RangeCoder *c)
226 { 230 {