Browse code

ff_check_alignment to warn the user about a missaligned stack

Originally committed as revision 7249 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2006/12/08 03:33:00
Showing 3 changed files
... ...
@@ -3801,11 +3801,31 @@ void dsputil_static_init(void)
3801 3801
     for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1;
3802 3802
 }
3803 3803
 
3804
+int ff_check_alignment(void){
3805
+    static int did_fail=0;
3806
+    DECLARE_ALIGNED_16(int, aligned);
3807
+
3808
+    if((int)&aligned & 15){
3809
+        if(!did_fail){
3810
+#if defined(HAVE_MMX) || defined(HAVE_ALTIVEC)
3811
+            av_log(NULL, AV_LOG_ERROR,
3812
+                "Compiler did not align stack variables, your code has been misscompiled\n"
3813
+                "and may crash, this is not a bug in the application but in the compiler\n"
3814
+                "so reporting it anywhere but to the compiler maintainers is senseless!\n");
3815
+#endif
3816
+            did_fail=1;
3817
+        }
3818
+        return -1;
3819
+    }
3820
+    return 0;
3821
+}
3804 3822
 
3805 3823
 void dsputil_init(DSPContext* c, AVCodecContext *avctx)
3806 3824
 {
3807 3825
     int i;
3808 3826
 
3827
+    ff_check_alignment();
3828
+
3809 3829
 #ifdef CONFIG_ENCODERS
3810 3830
     if(avctx->dct_algo==FF_DCT_FASTINT) {
3811 3831
         c->fdct = fdct_ifast;
... ...
@@ -410,6 +410,8 @@ typedef struct DSPContext {
410 410
 void dsputil_static_init(void);
411 411
 void dsputil_init(DSPContext* p, AVCodecContext *avctx);
412 412
 
413
+int ff_check_alignment(void);
414
+
413 415
 /**
414 416
  * permute block according to permuatation.
415 417
  * @param last last non zero element in scantable order
... ...
@@ -4838,6 +4838,8 @@ static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
4838 4838
 static int estimate_motion_thread(AVCodecContext *c, void *arg){
4839 4839
     MpegEncContext *s= arg;
4840 4840
 
4841
+    ff_check_alignment();
4842
+
4841 4843
     s->me.dia_size= s->avctx->dia_size;
4842 4844
     s->first_slice_line=1;
4843 4845
     for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
... ...
@@ -4864,6 +4866,8 @@ static int mb_var_thread(AVCodecContext *c, void *arg){
4864 4864
     MpegEncContext *s= arg;
4865 4865
     int mb_x, mb_y;
4866 4866
 
4867
+    ff_check_alignment();
4868
+
4867 4869
     for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) {
4868 4870
         for(mb_x=0; mb_x < s->mb_width; mb_x++) {
4869 4871
             int xx = mb_x * 16;
... ...
@@ -4911,6 +4915,8 @@ static int encode_thread(AVCodecContext *c, void *arg){
4911 4911
     PutBitContext pb[2], pb2[2], tex_pb[2];
4912 4912
 //printf("%d->%d\n", s->resync_mb_y, s->end_mb_y);
4913 4913
 
4914
+    ff_check_alignment();
4915
+
4914 4916
     for(i=0; i<2; i++){
4915 4917
         init_put_bits(&pb    [i], bit_buf    [i], MAX_MB_BYTES);
4916 4918
         init_put_bits(&pb2   [i], bit_buf2   [i], MAX_MB_BYTES);