Mercurial > libavcodec.hg
comparison cabac.h @ 3991:72bae00a317f libavcodec
make lps_range a global table its constant anyway (saves 1 addition for accessing it)
| author | michael |
|---|---|
| date | Wed, 11 Oct 2006 13:21:42 +0000 |
| parents | 746a60ba3177 |
| children | a09b5b667229 |
comparison
equal
deleted
inserted
replaced
| 3990:746a60ba3177 | 3991:72bae00a317f |
|---|---|
| 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_range[2*65][4]; ///< rangeTabLPS | |
| 45 uint8_t lps_state[2*64]; ///< transIdxLPS | 44 uint8_t lps_state[2*64]; ///< transIdxLPS |
| 46 uint8_t mps_state[2*64]; ///< transIdxMPS | 45 uint8_t mps_state[2*64]; ///< transIdxMPS |
| 47 const uint8_t *bytestream_start; | 46 const uint8_t *bytestream_start; |
| 48 const uint8_t *bytestream; | 47 const uint8_t *bytestream; |
| 49 const uint8_t *bytestream_end; | 48 const uint8_t *bytestream_end; |
| 50 PutBitContext pb; | 49 PutBitContext pb; |
| 51 }CABACContext; | 50 }CABACContext; |
| 52 | 51 |
| 53 extern const uint8_t ff_h264_lps_range[64][4]; | 52 extern uint8_t ff_h264_lps_range[2*65][4]; ///< rangeTabLPS |
| 54 extern const uint8_t ff_h264_mps_state[64]; | 53 extern const uint8_t ff_h264_mps_state[64]; |
| 55 extern const uint8_t ff_h264_lps_state[64]; | 54 extern const uint8_t ff_h264_lps_state[64]; |
| 56 extern const uint8_t ff_h264_norm_shift[128]; | 55 extern const uint8_t ff_h264_norm_shift[128]; |
| 57 | 56 |
| 58 | 57 |
| 59 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); | 58 void ff_init_cabac_encoder(CABACContext *c, uint8_t *buf, int buf_size); |
| 60 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); | 59 void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size); |
| 61 void ff_init_cabac_states(CABACContext *c, uint8_t const (*lps_range)[4], | 60 void ff_init_cabac_states(CABACContext *c, |
| 62 uint8_t const *mps_state, uint8_t const *lps_state, int state_count); | 61 uint8_t const *mps_state, uint8_t const *lps_state, int state_count); |
| 63 | 62 |
| 64 | 63 |
| 65 static inline void put_cabac_bit(CABACContext *c, int b){ | 64 static inline void put_cabac_bit(CABACContext *c, int b){ |
| 66 put_bits(&c->pb, 1, b); | 65 put_bits(&c->pb, 1, b); |
| 86 c->low += c->low; | 85 c->low += c->low; |
| 87 } | 86 } |
| 88 } | 87 } |
| 89 | 88 |
| 90 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ | 89 static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ |
| 91 int RangeLPS= c->lps_range[*state][c->range>>6]; | 90 int RangeLPS= ff_h264_lps_range[*state][c->range>>6]; |
| 92 | 91 |
| 93 if(bit == ((*state)&1)){ | 92 if(bit == ((*state)&1)){ |
| 94 c->range -= RangeLPS; | 93 c->range -= RangeLPS; |
| 95 *state= c->mps_state[*state]; | 94 *state= c->mps_state[*state]; |
| 96 }else{ | 95 }else{ |
| 368 #ifdef ARCH_X86 | 367 #ifdef ARCH_X86 |
| 369 int bit; | 368 int bit; |
| 370 | 369 |
| 371 #define LOW "0" | 370 #define LOW "0" |
| 372 #define RANGE "4" | 371 #define RANGE "4" |
| 373 #define LPS_RANGE "12" | 372 #define LPS_STATE "12" |
| 374 #define LPS_STATE "12+2*65*4" | 373 #define MPS_STATE "12+2*64" |
| 375 #define MPS_STATE "12+2*65*4+2*64" | 374 #define BYTESTART "12+4*64" |
| 376 #define BYTESTART "12+2*65*4+4*64" | 375 #define BYTE "16+4*64" |
| 377 #define BYTE "16+2*65*4+4*64" | 376 #define BYTEEND "20+4*64" |
| 378 #define BYTEEND "20+2*65*4+4*64" | |
| 379 #ifndef BRANCHLESS_CABAC_DECODER | 377 #ifndef BRANCHLESS_CABAC_DECODER |
| 380 asm volatile( | 378 asm volatile( |
| 381 "movzbl (%1), %%eax \n\t" | 379 "movzbl (%1), %%eax \n\t" |
| 382 "movl "RANGE "(%2), %%ebx \n\t" | 380 "movl "RANGE "(%2), %%ebx \n\t" |
| 383 "movl "RANGE "(%2), %%edx \n\t" | 381 "movl "RANGE "(%2), %%edx \n\t" |
| 384 "shrl $23, %%ebx \n\t" | 382 "shrl $23, %%ebx \n\t" |
| 385 "leal "LPS_RANGE"(%2, %%eax, 4), %%esi \n\t" | 383 "movzbl ff_h264_lps_range(%%ebx, %%eax, 4), %%esi\n\t" |
| 386 "movzbl (%%ebx, %%esi), %%esi \n\t" | |
| 387 "shll $17, %%esi \n\t" | 384 "shll $17, %%esi \n\t" |
| 388 "movl "LOW "(%2), %%ebx \n\t" | 385 "movl "LOW "(%2), %%ebx \n\t" |
| 389 //eax:state ebx:low, edx:range, esi:RangeLPS | 386 //eax:state ebx:low, edx:range, esi:RangeLPS |
| 390 "subl %%esi, %%edx \n\t" | 387 "subl %%esi, %%edx \n\t" |
| 391 "cmpl %%edx, %%ebx \n\t" | 388 "cmpl %%edx, %%ebx \n\t" |
| 451 asm volatile( | 448 asm volatile( |
| 452 "movzbl (%1), %%eax \n\t" | 449 "movzbl (%1), %%eax \n\t" |
| 453 "movl "RANGE "(%2), %%ebx \n\t" | 450 "movl "RANGE "(%2), %%ebx \n\t" |
| 454 "movl "RANGE "(%2), %%edx \n\t" | 451 "movl "RANGE "(%2), %%edx \n\t" |
| 455 "shrl $23, %%ebx \n\t" | 452 "shrl $23, %%ebx \n\t" |
| 456 "leal "LPS_RANGE"(%2, %%eax, 4), %%esi \n\t" | 453 "movzbl ff_h264_lps_range(%%ebx, %%eax, 4), %%esi\n\t" |
| 457 "movzbl (%%ebx, %%esi), %%esi \n\t" | |
| 458 "shll $17, %%esi \n\t" | 454 "shll $17, %%esi \n\t" |
| 459 "movl "LOW "(%2), %%ebx \n\t" | 455 "movl "LOW "(%2), %%ebx \n\t" |
| 460 //eax:state ebx:low, edx:range, esi:RangeLPS | 456 //eax:state ebx:low, edx:range, esi:RangeLPS |
| 461 "subl %%esi, %%edx \n\t" | 457 "subl %%esi, %%edx \n\t" |
| 462 #ifdef CMOV_IS_FAST //FIXME actually define this somewhere | 458 #ifdef CMOV_IS_FAST //FIXME actually define this somewhere |
| 518 ); | 514 ); |
| 519 bit&=1; | 515 bit&=1; |
| 520 #endif | 516 #endif |
| 521 #else | 517 #else |
| 522 int s = *state; | 518 int s = *state; |
| 523 int RangeLPS= c->lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1); | 519 int RangeLPS= ff_h264_lps_range[s][c->range>>(CABAC_BITS+7)]<<(CABAC_BITS+1); |
| 524 int bit, lps_mask attribute_unused; | 520 int bit, lps_mask attribute_unused; |
| 525 | 521 |
| 526 c->range -= RangeLPS; | 522 c->range -= RangeLPS; |
| 527 #ifndef BRANCHLESS_CABAC_DECODER | 523 #ifndef BRANCHLESS_CABAC_DECODER |
| 528 if(c->low < c->range){ | 524 if(c->low < c->range){ |
