cabac: Ensure 2-byte cabac loads are on 2-byte boundry
Ensure that cabac init sets the bitstream pointer to an even value. It is often faster to load from an aligned boundry Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
17399f6a9f
commit
48f80831ba
@@ -183,10 +183,19 @@ int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
|
|||||||
#if CABAC_BITS == 16
|
#if CABAC_BITS == 16
|
||||||
c->low = (*c->bytestream++)<<18;
|
c->low = (*c->bytestream++)<<18;
|
||||||
c->low+= (*c->bytestream++)<<10;
|
c->low+= (*c->bytestream++)<<10;
|
||||||
|
// Keep our fetches on a 2-byte boundry as this should avoid ever having to
|
||||||
|
// do unaligned loads if the compiler (or asm) optimises the double byte
|
||||||
|
// load into a single instruction
|
||||||
|
if(((uintptr_t)c->bytestream & 1) == 0) {
|
||||||
|
c->low += (1 << 9);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c->low += ((*c->bytestream++) << 2) + 2;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
c->low = (*c->bytestream++)<<10;
|
c->low = (*c->bytestream++)<<10;
|
||||||
#endif
|
|
||||||
c->low+= ((*c->bytestream++)<<2) + 2;
|
c->low+= ((*c->bytestream++)<<2) + 2;
|
||||||
|
#endif
|
||||||
c->range= 0x1FE;
|
c->range= 0x1FE;
|
||||||
if ((c->range<<(CABAC_BITS+1)) < c->low)
|
if ((c->range<<(CABAC_BITS+1)) < c->low)
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
|
Reference in New Issue
Block a user