Mercurial > libavcodec.hg
comparison cabac.h @ 3993:8b7c59b7af01 libavcodec
make state transition tables global as they are constant and the code is slightly faster that way
author | michael |
---|---|
date | Wed, 11 Oct 2006 14:44:17 +0000 |
parents | a09b5b667229 |
children | 2734b228fc87 |
comparison
equal
deleted
inserted
replaced
3992:a09b5b667229 | 3993:8b7c59b7af01 |
---|---|
39 int range; | 39 int range; |
40 int outstanding_count; | 40 int outstanding_count; |
41 #ifdef STRICT_LIMITS | 41 #ifdef STRICT_LIMITS |
42 int symCount; | 42 int symCount; |
43 #endif | 43 #endif |
44 uint8_t lps_state[2*64]; ///< transIdxLPS | |
45 uint8_t mps_state[2*64]; ///< transIdxMPS | |
46 const uint8_t *bytestream_start; | 44 const uint8_t *bytestream_start; |
47 const uint8_t *bytestream; | 45 const uint8_t *bytestream; |
48 const uint8_t *bytestream_end; | 46 const uint8_t *bytestream_end; |
49 PutBitContext pb; | 47 PutBitContext pb; |
50 }CABACContext; | 48 }CABACContext; |
51 | 49 |
52 extern uint8_t ff_h264_lps_range[2*65][4]; ///< rangeTabLPS | 50 extern uint8_t ff_h264_lps_range[2*65][4]; ///< rangeTabLPS |
53 extern const uint8_t ff_h264_mps_state[64]; | 51 extern uint8_t ff_h264_mps_state[2*64]; ///< transIdxMPS |
54 extern const uint8_t ff_h264_lps_state[64]; | 52 extern uint8_t ff_h264_lps_state[2*64]; ///< transIdxLPS |
55 extern const uint8_t ff_h264_norm_shift[128]; | 53 extern const uint8_t ff_h264_norm_shift[128]; |
56 | 54 |
57 | 55 |
58 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); | 56 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); |
59 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); | 57 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); |
60 void ff_init_cabac_states(CABACContext *c, | 58 void ff_init_cabac_states(CABACContext *c); |
61 uint8_t const *mps_state, uint8_t const *lps_state, int state_count); | |
62 | 59 |
63 | 60 |
64 static inline void put_cabac_bit(CABACContext *c, int b){ | 61 static inline void put_cabac_bit(CABACContext *c, int b){ |
65 put_bits(&c->pb, 1, b); | 62 put_bits(&c->pb, 1, b); |
66 for(;c->outstanding_count; c->outstanding_count--){ | 63 for(;c->outstanding_count; c->outstanding_count--){ |
89 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ | 86 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ |
90 int RangeLPS= ff_h264_lps_range[*state][c->range>>6]; | 87 int RangeLPS= ff_h264_lps_range[*state][c->range>>6]; |
91 | 88 |
92 if(bit == ((*state)&1)){ | 89 if(bit == ((*state)&1)){ |
93 c->range -= RangeLPS; | 90 c->range -= RangeLPS; |
94 *state= c->mps_state[*state]; | 91 *state= ff_h264_mps_state[*state]; |
95 }else{ | 92 }else{ |
96 c->low += c->range - RangeLPS; | 93 c->low += c->range - RangeLPS; |
97 c->range = RangeLPS; | 94 c->range = RangeLPS; |
98 *state= c->lps_state[*state]; | 95 *state= ff_h264_lps_state[*state]; |
99 } | 96 } |
100 | 97 |
101 renorm_cabac_encoder(c); | 98 renorm_cabac_encoder(c); |
102 | 99 |
103 #ifdef STRICT_LIMITS | 100 #ifdef STRICT_LIMITS |
367 #ifdef ARCH_X86 | 364 #ifdef ARCH_X86 |
368 int bit; | 365 int bit; |
369 | 366 |
370 #define LOW "0" | 367 #define LOW "0" |
371 #define RANGE "4" | 368 #define RANGE "4" |
372 #define LPS_STATE "12" | 369 #define BYTESTART "12" |
373 #define MPS_STATE "12+2*64" | 370 #define BYTE "16" |
374 #define BYTESTART "12+4*64" | 371 #define BYTEEND "20" |
375 #define BYTE "16+4*64" | |
376 #define BYTEEND "20+4*64" | |
377 #ifndef BRANCHLESS_CABAC_DECODER | 372 #ifndef BRANCHLESS_CABAC_DECODER |
378 asm volatile( | 373 asm volatile( |
379 "movzbl (%1), %%eax \n\t" | 374 "movzbl (%1), %%eax \n\t" |
380 "movl "RANGE "(%2), %%ebx \n\t" | 375 "movl "RANGE "(%2), %%ebx \n\t" |
381 "movl "RANGE "(%2), %%edx \n\t" | 376 "movl "RANGE "(%2), %%edx \n\t" |
389 " ja 1f \n\t" | 384 " ja 1f \n\t" |
390 "cmp $0x2000000, %%edx \n\t" //FIXME avoidable | 385 "cmp $0x2000000, %%edx \n\t" //FIXME avoidable |
391 "setb %%cl \n\t" | 386 "setb %%cl \n\t" |
392 "shl %%cl, %%edx \n\t" | 387 "shl %%cl, %%edx \n\t" |
393 "shl %%cl, %%ebx \n\t" | 388 "shl %%cl, %%ebx \n\t" |
394 "movzbl "MPS_STATE"(%2, %%eax), %%ecx \n\t" | 389 "movzbl "MANGLE(ff_h264_mps_state)"(%%eax), %%ecx \n\t" |
395 "movb %%cl, (%1) \n\t" | 390 "movb %%cl, (%1) \n\t" |
396 //eax:state ebx:low, edx:range, esi:RangeLPS | 391 //eax:state ebx:low, edx:range, esi:RangeLPS |
397 "test %%bx, %%bx \n\t" | 392 "test %%bx, %%bx \n\t" |
398 " jnz 2f \n\t" | 393 " jnz 2f \n\t" |
399 "movl "BYTE "(%2), %%esi \n\t" | 394 "movl "BYTE "(%2), %%esi \n\t" |
411 "movl %%esi, %%edx \n\t" | 406 "movl %%esi, %%edx \n\t" |
412 "shr $19, %%esi \n\t" | 407 "shr $19, %%esi \n\t" |
413 "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t" | 408 "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t" |
414 "shll %%cl, %%ebx \n\t" | 409 "shll %%cl, %%ebx \n\t" |
415 "shll %%cl, %%edx \n\t" | 410 "shll %%cl, %%edx \n\t" |
416 "movzbl "LPS_STATE"(%2, %%eax), %%ecx \n\t" | 411 "movzbl "MANGLE(ff_h264_lps_state)"(%%eax), %%ecx \n\t" |
417 "movb %%cl, (%1) \n\t" | 412 "movb %%cl, (%1) \n\t" |
418 "addl $1, %%eax \n\t" | 413 "addl $1, %%eax \n\t" |
419 "test %%bx, %%bx \n\t" | 414 "test %%bx, %%bx \n\t" |
420 " jnz 2f \n\t" | 415 " jnz 2f \n\t" |
421 | 416 |
473 "subl %%ecx, %%ebx \n\t" | 468 "subl %%ecx, %%ebx \n\t" |
474 "xorl %%edx, %%eax \n\t" | 469 "xorl %%edx, %%eax \n\t" |
475 #endif | 470 #endif |
476 | 471 |
477 //eax:state ebx:low edx:mask esi:range | 472 //eax:state ebx:low edx:mask esi:range |
478 "movzbl "MPS_STATE"(%2, %%eax), %%ecx \n\t" | 473 "movzbl "MANGLE(ff_h264_mps_state)"(%%eax), %%ecx \n\t" |
479 "movb %%cl, (%1) \n\t" | 474 "movb %%cl, (%1) \n\t" |
480 | 475 |
481 "movl %%esi, %%edx \n\t" | 476 "movl %%esi, %%edx \n\t" |
482 //eax:bit ebx:low edx:range esi:range | 477 //eax:bit ebx:low edx:range esi:range |
483 | 478 |
521 | 516 |
522 c->range -= RangeLPS; | 517 c->range -= RangeLPS; |
523 #ifndef BRANCHLESS_CABAC_DECODER | 518 #ifndef BRANCHLESS_CABAC_DECODER |
524 if(c->low < c->range){ | 519 if(c->low < c->range){ |
525 bit= s&1; | 520 bit= s&1; |
526 *state= c->mps_state[s]; | 521 *state= ff_h264_mps_state[s]; |
527 renorm_cabac_decoder_once(c); | 522 renorm_cabac_decoder_once(c); |
528 }else{ | 523 }else{ |
529 bit= ff_h264_norm_shift[RangeLPS>>19]; | 524 bit= ff_h264_norm_shift[RangeLPS>>19]; |
530 c->low -= c->range; | 525 c->low -= c->range; |
531 *state= c->lps_state[s]; | 526 *state= ff_h264_lps_state[s]; |
532 c->range = RangeLPS<<bit; | 527 c->range = RangeLPS<<bit; |
533 c->low <<= bit; | 528 c->low <<= bit; |
534 bit= (s&1)^1; | 529 bit= (s&1)^1; |
535 | 530 |
536 if(!(c->low & 0xFFFF)){ | 531 if(!(c->low & 0xFFFF)){ |
542 | 537 |
543 c->low -= c->range & lps_mask; | 538 c->low -= c->range & lps_mask; |
544 c->range += (RangeLPS - c->range) & lps_mask; | 539 c->range += (RangeLPS - c->range) & lps_mask; |
545 | 540 |
546 s^=lps_mask; | 541 s^=lps_mask; |
547 *state= c->mps_state[s]; | 542 *state= ff_h264_mps_state[s]; |
548 bit= s&1; | 543 bit= s&1; |
549 | 544 |
550 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+3)]; | 545 lps_mask= ff_h264_norm_shift[c->range>>(CABAC_BITS+3)]; |
551 c->range<<= lps_mask; | 546 c->range<<= lps_mask; |
552 c->low <<= lps_mask; | 547 c->low <<= lps_mask; |