[FFmpeg-cvslog] cabac: Ensure 2-byte cabac loads are on 2-byte boundry
John Cox
git at videolan.org
Fri Jan 22 04:38:54 CET 2016
ffmpeg | branch: master | John Cox <jc at kynesim.co.uk> | Wed Jan 20 17:48:30 2016 +0000| [48f80831bad87addf40b6496210817ea0efc85af] | committer: Michael Niedermayer
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 at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=48f80831bad87addf40b6496210817ea0efc85af
---
libavcodec/cabac.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index 5bf5bc2..f2c239d 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;
More information about the ffmpeg-cvslog
mailing list