]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cabac.c
checkasm/vf_blend: Decrease iteration count
[ffmpeg] / libavcodec / cabac.c
index 5bf5bc284ef8e0eec34c384394645beb2741dd93..a9fafbdd33ef3b3c3b2fefef10bc6bb47ac4ac67 100644 (file)
@@ -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;
@@ -309,7 +318,9 @@ int main(void){
         put_cabac(&c, state, r[i]&1);
     }
 
-    put_cabac_terminate(&c, 1);
+    i= put_cabac_terminate(&c, 1);
+    b[i++] = av_lfg_get(&prng);
+    b[i  ] = av_lfg_get(&prng);
 
     ff_init_cabac_decoder(&c, b, SIZE);