comparison vp56.h @ 12252:b8211cda076d libavcodec

Move renormalization of the VP56 arith decoder to before decoding a bit No difference at the moment, but allows a future branchy variant of vp56_rac_get_prob to be significantly faster
author conrad
date Fri, 23 Jul 2010 21:46:14 +0000
parents bbe8e7233c5d
children 112b3a0db187
comparison
equal deleted inserted replaced
12251:bbe8e7233c5d 12252:b8211cda076d
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 av_always_inline void vp56_rac_renorm(VP56RangeCoder *c, unsigned int code_word) 194 static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
195 { 195 {
196 int shift = ff_h264_norm_shift[c->high] - 1; 196 int shift = ff_h264_norm_shift[c->high] - 1;
197 int bits = c->bits; 197 int bits = c->bits;
198 unsigned int code_word = c->code_word;
198 199
199 c->high <<= shift; 200 c->high <<= shift;
200 code_word <<= shift; 201 code_word <<= shift;
201 bits += shift; 202 bits += shift;
202 if(bits >= 0 && c->buffer < c->end) { 203 if(bits >= 0 && c->buffer < c->end) {
203 code_word |= *c->buffer++ << bits; 204 code_word |= *c->buffer++ << bits;
204 bits -= 8; 205 bits -= 8;
205 } 206 }
206 c->bits = bits; 207 c->bits = bits;
207 c->code_word = code_word; 208 return code_word;
208 } 209 }
209 210
210 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) 211 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
211 { 212 {
212 /* Don't put c->high in a local variable; if we do that, gcc gets 213 /* 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 * the stupids and turns the code below into a branch again. */
214 unsigned int code_word = c->code_word; 215 unsigned int code_word = vp56_rac_renorm(c);
215 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); 216 unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
216 unsigned int low_shift = low << 8; 217 unsigned int low_shift = low << 8;
217 int bit = code_word >= low_shift; 218 int bit = code_word >= low_shift;
218 219
219 /* Incantation to convince GCC to turn these into conditional moves 220 /* Incantation to convince GCC to turn these into conditional moves
220 * instead of branches -- faster, as this branch is basically 221 * instead of branches -- faster, as this branch is basically
221 * unpredictable. */ 222 * unpredictable. */
222 c->high = bit ? c->high - low : low; 223 c->high = bit ? c->high - low : low;
223 code_word = bit ? code_word - low_shift : code_word; 224 c->code_word = bit ? code_word - low_shift : code_word;
224 225
225 vp56_rac_renorm(c, code_word);
226 return bit; 226 return bit;
227 } 227 }
228 228
229 static inline int vp56_rac_get(VP56RangeCoder *c) 229 static inline int vp56_rac_get(VP56RangeCoder *c)
230 { 230 {
231 unsigned int code_word = vp56_rac_renorm(c);
231 /* equiprobable */ 232 /* equiprobable */
232 int low = (c->high + 1) >> 1; 233 int low = (c->high + 1) >> 1;
233 unsigned int low_shift = low << 8; 234 unsigned int low_shift = low << 8;
234 int bit = c->code_word >= low_shift; 235 int bit = code_word >= low_shift;
235 if (bit) { 236 if (bit) {
236 c->high = (c->high - low) << 1; 237 c->high -= low;
237 c->code_word -= low_shift; 238 code_word -= low_shift;
238 } else { 239 } else {
239 c->high = low << 1; 240 c->high = low;
240 } 241 }
241 242
242 /* normalize */ 243 c->code_word = code_word;
243 c->code_word <<= 1;
244 if (++c->bits == 0 && c->buffer < c->end) {
245 c->bits = -8;
246 c->code_word |= *c->buffer++;
247 }
248 return bit; 244 return bit;
249 } 245 }
250 246
251 // rounding is different than vp56_rac_get, is vp56_rac_get wrong? 247 // rounding is different than vp56_rac_get, is vp56_rac_get wrong?
252 static inline int vp8_rac_get(VP56RangeCoder *c) 248 static inline int vp8_rac_get(VP56RangeCoder *c)