This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc 2.96 20000731 (Red Hat Linux 7.1 2.96-81) + libdv


My gcc version is 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
 

I found a bug in gcc that causes incorrect compilation of libdv-0.8.
A simple Makefile and the smallest excerpt (weighting.c) from libdv-0.8 that produces the error (the smallest I found) is attached to this e-mail.

Invalid assembly code is produced when the following lines are being compiled:
        for (z=0;z<4;z++) {
                for (x=0;x<8;x++) {
                        dv_weight_inverse_248_matrix[z*8+x] =
                                1.0 / (W[x] * W[2*z] / 2);      // HERE (compiler forgets about
                                        //            ^^^          number 2 and uses uninitialized variable
                        dv_weight_inverse_248_matrix[(z+4)*8+x] =
                                1.0 / (W[x] * W[2*z] / 2);      // HERE
 
                }
        }

I found the following line (in weighting.S) guilty:
        fldl    -1144(%ebp)
Local variable -1144(%ebp) was NOT INITIALIZED! Here is should probably be:
        fldl    .LC59

It is enough to disturb the compiler with some function call to make it produce a correct code. Example:

        for (z=0;z<4;z++) {
                for (x=0;x<8;x++) {
                        dv_weight_inverse_248_matrix[z*8+x] =
                                1.0 / (W[x] * W[2*z] / 2);      // HERE
                        dv_weight_inverse_248_matrix[(z+4)*8+x] =
                                1.0 / (W[x] * W[2*z] / 2);      // HERE
 
                }
                puts("Hello");          // lets disturb the compiler
        }
 

Attached files:
    weighting.S contains invalid assembly code produced for weighting.c.
    weighting-good.S contains correct assembly code produced for weighting.c modified with weighting-good.C.patch.

    result-bad contains example output (can be random) from compiled weighting.c.
    result-good contains expected output from modified version.
 

Here is an interesting excerpt from diff -u weighting.S weighting-good.S:
@@ -1187,28 +1189,33 @@
        fstp    %st(0)
        fstp    %st(0)
        movl    $0, -1132(%ebp)
-       movl    $W, %edi
-       fldl    -1144(%ebp)                     // Uninitialized!!!
-       fld1
+       movl    $W, %ebx
        xorl    %esi, %esi
-       xorl    %ebx, %ebx
+       movl    $1072693248, %edi
+       movl    $0, -1136(%ebp)
+       movl    $0, -1140(%ebp)
        .p2align 2
 .L247:
        .stabn 68,0,153,.LM116-weight_init
 .LM116:
+       movl    -1140(%ebp), %edx
+       movl    -1136(%ebp), %eax
        xorl    %ecx, %ecx
-       fldl    (%edi)
-       leal    dv_weight_inverse_248_matrix+256(%ebx), %edx
-       leal    dv_weight_inverse_248_matrix(%esi), %eax
+       fldl    (%ebx)
+       addl    $dv_weight_inverse_248_matrix+256, %edx
+       addl    $dv_weight_inverse_248_matrix, %eax
        .p2align 2
 .L251:
        .stabn 68,0,154,.LM117-weight_init
 .LM117:
        fldl    W(,%ecx,8)
-       fmul    %st(1), %st
-       fmul    %st(3), %st                     // multiply by ???
-       fld     %st(2)
-       fdivp   %st, %st(1)
+       movl    %esi, -1168(%ebp)
+       movl    %edi, -1164(%ebp)
+       fldl    -1168(%ebp)
+       fxch    %st(1)
+       fmul    %st(2), %st
+       fmull   .LC59                           // multiply by 0.5 (divide by 2)
+       fdivrp  %st, %st(1)
        .stabn 68,0,153,.LM118-weight_init
 .LM118:
        incl    %ecx
 
 

Artur Zaprzala
<zybi@talex.com.pl>

libdv_gcc.tar.bz2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]