summaryrefslogtreecommitdiff
path: root/libavcodec/cabac.c
diff options
context:
space:
mode:
authorJohn Cox <jc@kynesim.co.uk>2016-01-20 17:48:30 +0000
committerMichael Niedermayer <michael@niedermayer.cc>2016-01-22 02:31:32 +0100
commit48f80831bad87addf40b6496210817ea0efc85af (patch)
tree8f7b7a82c55914d65df136159785a07e3cb0fe55 /libavcodec/cabac.c
parent17399f6a9f00aa492f4b7a408a03bd84d2701008 (diff)
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>
Diffstat (limited to 'libavcodec/cabac.c')
-rw-r--r--libavcodec/cabac.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index 5bf5bc284e..f2c239da89 100644
--- a/libavcodec/cabac.c
+++ b/libavcodec/cabac.c
@@ -183,10 +183,19 @@ int ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
#if CABAC_BITS == 16
c->low = (*c->bytestream++)<<18;
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
c->low = (*c->bytestream++)<<10;
-#endif
c->low+= ((*c->bytestream++)<<2) + 2;
+#endif
c->range= 0x1FE;
if ((c->range<<(CABAC_BITS+1)) < c->low)
return AVERROR_INVALIDDATA;