[FFmpeg-cvslog] h264: avoid undefined behavior in chroma motion compensation

Janne Grunau git at videolan.org
Thu Feb 20 23:07:02 CET 2014


ffmpeg | branch: master | Janne Grunau <janne-libav at jannau.net> | Fri Feb 14 17:00:06 2014 +0100| [982b596ea6640bfe218a31f6c3fc542d9fe61c31] | committer: Janne Grunau

h264: avoid undefined behavior in chroma motion compensation

Makes fate-h264 pass under valgrind --undef-value-errors=yes with
-cpuflags none. {avg,put}_h264_chroma_mc8_8 approximately 5% faster,
{avg,put}_h264_chroma_mc4_8 2% faster both on x86 and arm.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=982b596ea6640bfe218a31f6c3fc542d9fe61c31
---

 libavcodec/h264chroma_template.c |   35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h264chroma_template.c b/libavcodec/h264chroma_template.c
index 351d9d2..028ed13 100644
--- a/libavcodec/h264chroma_template.c
+++ b/libavcodec/h264chroma_template.c
@@ -43,7 +43,7 @@ static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
-    }else{\
+    } else if (B + C) {\
         const int E= B+C;\
         const int step= C ? stride : 1;\
         for(i=0; i<h; i++){\
@@ -52,6 +52,13 @@ static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
+    } else {\
+        for ( i = 0; i < h; i++){\
+            OP(dst[0], A * src[0]);\
+            OP(dst[1], A * src[1]);\
+            dst += stride;\
+            src += stride;\
+        }\
     }\
 }\
 \
@@ -76,7 +83,7 @@ static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
-    }else{\
+    } else if (B + C) {\
         const int E= B+C;\
         const int step= C ? stride : 1;\
         for(i=0; i<h; i++){\
@@ -87,6 +94,15 @@ static void FUNCC(OPNAME ## h264_chroma_mc4)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
+    } else {\
+        for ( i = 0; i < h; i++){\
+            OP(dst[0], A * src[0]);\
+            OP(dst[1], A * src[1]);\
+            OP(dst[2], A * src[2]);\
+            OP(dst[3], A * src[3]);\
+            dst += stride;\
+            src += stride;\
+        }\
     }\
 }\
 \
@@ -115,7 +131,7 @@ static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
-    }else{\
+    } else if (B + C) {\
         const int E= B+C;\
         const int step= C ? stride : 1;\
         for(i=0; i<h; i++){\
@@ -130,6 +146,19 @@ static void FUNCC(OPNAME ## h264_chroma_mc8)(uint8_t *_dst/*align 8*/, uint8_t *
             dst+= stride;\
             src+= stride;\
         }\
+    } else {\
+        for ( i = 0; i < h; i++){\
+            OP(dst[0], A * src[0]);\
+            OP(dst[1], A * src[1]);\
+            OP(dst[2], A * src[2]);\
+            OP(dst[3], A * src[3]);\
+            OP(dst[4], A * src[4]);\
+            OP(dst[5], A * src[5]);\
+            OP(dst[6], A * src[6]);\
+            OP(dst[7], A * src[7]);\
+            dst += stride;\
+            src += stride;\
+        }\
     }\
 }
 



More information about the ffmpeg-cvslog mailing list