[FFmpeg-devel] [PATCH] Fix strict-aliasing violations in MPV_motion_internal (in mpegvideo_common.h)

Eli Friedman eli.friedman
Tue Jun 29 23:07:20 CEST 2010


Patch attached.  Per subject, fixes strict-aliasing violations.  I
have absolutely no clue why, but gcc 4.4 actually generates slightly
different code, but not in any way directly related to the change (the
patched version uses "add    %r13d,%eax" instead of "lea
0x0(%r13,%rax,1),%eax" in a few places in mpegvideo.c, and the
register allocation is different in mpegvideo_enc.c).

-Eli
-------------- next part --------------
Index: libavcodec/mpegvideo_common.h
===================================================================
--- libavcodec/mpegvideo_common.h	(revision 23854)
+++ libavcodec/mpegvideo_common.h	(working copy)
@@ -670,19 +670,19 @@
         }
 
         if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
-            *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
-            *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
+            AV_COPY32(mv_cache[1][0], mv_cache[1][1]);
+            AV_COPY32(mv_cache[2][0], mv_cache[2][1]);
         }else{
-            *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
-            *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
+            AV_COPY32(mv_cache[1][0], s->current_picture.motion_val[0][mot_xy-1]);
+            AV_COPY32(mv_cache[2][0], s->current_picture.motion_val[0][mot_xy-1+mot_stride]);
         }
 
         if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
-            *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
-            *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
+            AV_COPY32(mv_cache[1][3], mv_cache[1][2]);
+            AV_COPY32(mv_cache[2][3], mv_cache[2][2]);
         }else{
-            *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
-            *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
+            AV_COPY32(mv_cache[1][3], s->current_picture.motion_val[0][mot_xy+2]);
+            AV_COPY32(mv_cache[2][3], s->current_picture.motion_val[0][mot_xy+2+mot_stride]);
         }
 
         mx = 0;



More information about the ffmpeg-devel mailing list