comparison vp56.h @ 12349:f618c62a6ddb libavcodec

VP5/6/8: tweak some arithcoder inlining Always inline the arithmetic coder, except in the case of header-parsing stuff, in which case don't inline it at all to save code size.
author darkshikari
date Tue, 03 Aug 2010 08:06:08 +0000
parents 83400282990a
children e25a985a550c
comparison
equal deleted inserted replaced
12348:97a9ea928ffc 12349:f618c62a6ddb
212 #include "x86/vp56_arith.h" 212 #include "x86/vp56_arith.h"
213 #endif 213 #endif
214 214
215 #ifndef vp56_rac_get_prob 215 #ifndef vp56_rac_get_prob
216 #define vp56_rac_get_prob vp56_rac_get_prob 216 #define vp56_rac_get_prob vp56_rac_get_prob
217 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) 217 static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
218 { 218 {
219 unsigned int code_word = vp56_rac_renorm(c); 219 unsigned int code_word = vp56_rac_renorm(c);
220 unsigned int low = 1 + (((c->high - 1) * prob) >> 8); 220 unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
221 unsigned int low_shift = low << 8; 221 unsigned int low_shift = low << 8;
222 int bit = code_word >= low_shift; 222 int bit = code_word >= low_shift;
244 c->high = low; 244 c->high = low;
245 c->code_word = code_word; 245 c->code_word = code_word;
246 return 0; 246 return 0;
247 } 247 }
248 248
249 static inline int vp56_rac_get(VP56RangeCoder *c) 249 static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
250 { 250 {
251 unsigned int code_word = vp56_rac_renorm(c); 251 unsigned int code_word = vp56_rac_renorm(c);
252 /* equiprobable */ 252 /* equiprobable */
253 int low = (c->high + 1) >> 1; 253 int low = (c->high + 1) >> 1;
254 unsigned int low_shift = low << 8; 254 unsigned int low_shift = low << 8;
263 c->code_word = code_word; 263 c->code_word = code_word;
264 return bit; 264 return bit;
265 } 265 }
266 266
267 // rounding is different than vp56_rac_get, is vp56_rac_get wrong? 267 // rounding is different than vp56_rac_get, is vp56_rac_get wrong?
268 static inline int vp8_rac_get(VP56RangeCoder *c) 268 static av_always_inline int vp8_rac_get(VP56RangeCoder *c)
269 { 269 {
270 return vp56_rac_get_prob(c, 128); 270 return vp56_rac_get_prob(c, 128);
271 } 271 }
272 272
273 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits) 273 static int vp56_rac_gets(VP56RangeCoder *c, int bits)
274 { 274 {
275 int value = 0; 275 int value = 0;
276 276
277 while (bits--) { 277 while (bits--) {
278 value = (value << 1) | vp56_rac_get(c); 278 value = (value << 1) | vp56_rac_get(c);
279 } 279 }
280 280
281 return value; 281 return value;
282 } 282 }
283 283
284 static inline int vp8_rac_get_uint(VP56RangeCoder *c, int bits) 284 static int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
285 { 285 {
286 int value = 0; 286 int value = 0;
287 287
288 while (bits--) { 288 while (bits--) {
289 value = (value << 1) | vp8_rac_get(c); 289 value = (value << 1) | vp8_rac_get(c);
291 291
292 return value; 292 return value;
293 } 293 }
294 294
295 // fixme: add 1 bit to all the calls to this? 295 // fixme: add 1 bit to all the calls to this?
296 static inline int vp8_rac_get_sint(VP56RangeCoder *c, int bits) 296 static int vp8_rac_get_sint(VP56RangeCoder *c, int bits)
297 { 297 {
298 int v; 298 int v;
299 299
300 if (!vp8_rac_get(c)) 300 if (!vp8_rac_get(c))
301 return 0; 301 return 0;
307 307
308 return v; 308 return v;
309 } 309 }
310 310
311 // P(7) 311 // P(7)
312 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits) 312 static int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
313 { 313 {
314 int v = vp56_rac_gets(c, 7) << 1; 314 int v = vp56_rac_gets(c, 7) << 1;
315 return v + !v; 315 return v + !v;
316 } 316 }
317 317
318 static inline int vp8_rac_get_nn(VP56RangeCoder *c) 318 static int vp8_rac_get_nn(VP56RangeCoder *c)
319 { 319 {
320 int v = vp8_rac_get_uint(c, 7) << 1; 320 int v = vp8_rac_get_uint(c, 7) << 1;
321 return v + !v; 321 return v + !v;
322 } 322 }
323 323
324 static inline int vp56_rac_get_tree(VP56RangeCoder *c, 324 static av_always_inline
325 const VP56Tree *tree, 325 int vp56_rac_get_tree(VP56RangeCoder *c,
326 const uint8_t *probs) 326 const VP56Tree *tree,
327 const uint8_t *probs)
327 { 328 {
328 while (tree->val > 0) { 329 while (tree->val > 0) {
329 if (vp56_rac_get_prob(c, probs[tree->prob_idx])) 330 if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
330 tree += tree->val; 331 tree += tree->val;
331 else 332 else
337 /** 338 /**
338 * This is identical to vp8_rac_get_tree except for the possibility of starting 339 * This is identical to vp8_rac_get_tree except for the possibility of starting
339 * on a node other than the root node, needed for coeff decode where this is 340 * on a node other than the root node, needed for coeff decode where this is
340 * used to save a bit after a 0 token (by disallowing EOB to immediately follow.) 341 * used to save a bit after a 0 token (by disallowing EOB to immediately follow.)
341 */ 342 */
342 static inline int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2], 343 static av_always_inline
343 const uint8_t *probs, int i) 344 int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2],
345 const uint8_t *probs, int i)
344 { 346 {
345 do { 347 do {
346 i = tree[i][vp56_rac_get_prob(c, probs[i])]; 348 i = tree[i][vp56_rac_get_prob(c, probs[i])];
347 } while (i > 0); 349 } while (i > 0);
348 350
349 return -i; 351 return -i;
350 } 352 }
351 353
352 // how probabilities are associated with decisions is different I think 354 // how probabilities are associated with decisions is different I think
353 // well, the new scheme fits in the old but this way has one fewer branches per decision 355 // well, the new scheme fits in the old but this way has one fewer branches per decision
354 static inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2], 356 static av_always_inline
355 const uint8_t *probs) 357 int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
358 const uint8_t *probs)
356 { 359 {
357 return vp8_rac_get_tree_with_offset(c, tree, probs, 0); 360 return vp8_rac_get_tree_with_offset(c, tree, probs, 0);
358 } 361 }
359 362
360 // DCTextra 363 // DCTextra
361 static inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob) 364 static av_always_inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob)
362 { 365 {
363 int v = 0; 366 int v = 0;
364 367
365 do { 368 do {
366 v = (v<<1) + vp56_rac_get_prob(c, *prob++); 369 v = (v<<1) + vp56_rac_get_prob(c, *prob++);