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]
Other format: [Raw text]

BugReportGCC


Dear colleagues (addressee=gcc-bugs@gcc.gnu.org)[date=20040223095252][subject=BugReportGCC],


I apologize not to follow the usual procedure for submitting a bug report ; this
is due to the nature of this bug :

1-This bug is encountered with almost all PC Linux used and in particular :

     1.1-Mobile Intel(R) Pentium(R) 4 - M CPU 2.20GHz
     Linux version 2.4.18-bf2.4 (root@zombie) (gcc version 2.95.4 20011002 (Debian prerelease)) #1 Son Apr 14 09:53:28 CEST 2002

     1.2-Pentium III (Coppermine)
     Linux version 2.2.17-21mdk (chmou@no.mandrakesoft.com) (gcc version 2.95.3 19991030 (prerelease)) #1 Thu Oct 5 13:16:08 CEST 2000

     1.3-Intel(R) Pentium(R) 4 CPU 3.00GHz
     Linux version 2.4.22-1.2115.nptl (bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030422 (Red Hat Linux 3.2.3-6)) #1 Wed Oct 29 15:42:51 EST 2003

     1.4-Intel(R) Pentium(R) 4 CPU 2.60GHz
     Linux version 2.4.22-1.2115.nptl (bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030422 (Red Hat Linux 3.2.3-6)) #1 Wed Oct 29 15:42:51 EST 2003

     1.5-etc...


2-This bug appears using the following options :

     gcc -O2 -lm
     gcc -O3 -lm

and desappears when using :

     gcc -O0 -lm
     gcc -O1 -lm
     gcc -O2 -ffloat-store -lm
     gcc -O3 -ffloat-store -lm


3-It seems to me that this bug can be described using the following scenario :

     3.1-let A and B be two EQUAL floating point numbers currently computed ; they are
     stored in 80-bit floating point registers. At that time, it is possible to add them,
     to multiple them,... and to compare them without ambiguity.

     3.2-suppose that due to a lack of floating point resources, the number A is moved
     to memory (and then in a 64-bit format) and suppose (and I believe it is here the
     heart of the bug) that the optimizer "ignores" that move.

     3.3-imagine that some instructions later, one have to compare A (now a 64-bit number)
     and B (still a 80-bit number) ; A is moved from memory to a floating point register
     and 26 (null) bits are added to it. A and B are no more equal.


4-The following program is here to exhibit this phenomenon. By the way, please note
that this program is a "stupid" one for it computes the minimum of a set of equal
values ! But it is written only to exhibit this phenomenon and everything is mandatory
(for example, deleting one the fflush() induces the desappearing of the bug) ; is is
almost impossible to simplify it...

If the bug does not exist (gcc -O0 for example), this program does not print anything.
When the bug exists (gcc -O2 for example), the program will produce outputs like this
one :

     X=0002 Y=0000 YY=0001 :
     dm=0.592987960313625218 (e30f0022,3fe2f9c1)
     dc=0.592987960313625218 (e30f0022,3fe2f9c1) diff=0.000000000000000056 (00000000,3c900000)

where one can see that the two numbers 'dm' and 'dc' are strictly equal (using a 64-bit
hexa-decimal format) when their difference 'diff' is non zero and when the test 'dm>dc'
is true...


/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        T E S T   P R O G R A M  :                                                                                                 */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author :                                                                                                                   */
/*                                                                                                                                   */
/*                    John F. Kolonna (LACTAMME, 20040219104426).                                                                    */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#include  <stdio.h>

extern    double    sin();

typedef   union     flottant  {
                              double    d;
                              struct    i         {
                                                  int       i1;
                                                  int       i2;
                                                  }         i;
                              }         flottant;
#define   pd(x)     (x.d)
#define   pi1(x)    (x.i.i1)
#define   pi2(x)    (x.i.i2)
                                        /* to allow hexa-decimal printing of double precision numbers.                               */

#define   dimY      3
#define   Ymin      0
#define   Ymax      (Ymin+dimY-1)

#define   dimX      7
#define   Xmin      0
#define   Xmax      (Xmin+dimX-1)

#define   DM(t)               t[dimY*dimX]
#define   IM(t,x,y)           (*((t)+((y-Ymin)*(dimX)+(x-Xmin))))
#define   PM(c,min,max)       (c=(min) ; c <= (max) ; c++)
                                        /* to define and to access matrices as vectors.                                              */

#define   ABSO(x)   (((x) > 0) ? (x) : -(x))
#define   MIN2(a,b) (((a) < (b)) ? (a) : (b))
#define   MAX2(a,b) (((a) > (b)) ? (a) : (b))
#define   SOUA(a,b) ABSO((a) - (b))

void      fonction(argumentA,argumentB)
double    argumentA;
double    argumentB;
          {
          int       X,Y,YY;
          double    DM(A1),DM(TM),DM(A2),DM(A1N);
          double    minA1=+1e308,maxA1=-1e308;

          for       PM(Y,Ymin,Ymax)
                    {
                    for       PM(X,Xmin,Xmax)
                              {
                              double    valeurX=((1.0+sin(10.0*((double)(X-Xmin))/((double)(Xmax-Xmin))))/2.0);
                              double    valeurY=((1.0+sin(10.0*((double)(Y-Ymin))/((double)(Ymax-Ymin))))/2.0);

                              IM(A1,X,Y) = valeurY;
                              minA1=MIN2(minA1,valeurY);
                              maxA1=MAX2(maxA1,valeurY);

                              IM(A2,X,Y) = valeurX;
                              IM(TM,X,Y) = valeurX;
                                        /* please note that : IM(TM,X,Ymin)=...=IM(TM,X,Ymax).                                       */
                              }
                    }

          for       PM(Y,Ymin,Ymax)
                    {
                    for       PM(X,Xmin,Xmax)
                              {
                              IM(A1N,X,Y) = (IM(A1,X,Y)-minA1)/(maxA1-minA1);
                              }
                    }

          for       PM(Y,Ymin,Ymax)
                    {
                    for       PM(X,Xmin,Xmax)
                              {
                              int       cX=(int)((argumentA*(Xmin+((Xmax-Xmin)*IM(A1N,X,Y))))+argumentB);
                                        /* please note that : cX=Xmin+1 due to argumentA=0 and argumentB=Xmin+1.                     */
                              int       cY=Ymin;
                              double    ncA2=IM(A2,X,Y);
                              double    dm=+1e308;
                                        /* 'dm' will be the minimum of the {dc} set.                                                 */

                              if        ((cX < Xmin) || (cX > Xmax) || (cY < Ymin) || (cY > Ymax))
                                        /* this test always false must be there...                                                   */
                                        {
                                        printf("les coordonnees du produit generalise inverse a droite sont incorrectes\n");
                                        printf("X=%d : doit etre dans [%d,%d]\n",cX,Xmin,Xmax);
                                        fflush(stdout);
                                        printf("Y=%d : doit etre dans [%d,%d]\n",cY,Ymin,Ymax);
                                        fflush(stdout);
                                        }

                              for       PM(YY,Ymin,Ymax)
                                        /* inner loop to compute 'dm' as the minimum of the {dc} set.                                */
                                        {
                                        double    nctm=IM(TM,cX,YY);
                                        /* please remember that : IM(TM,X,Ymin)=...=IM(TM,X,Ymax).                                   */
                                        double    dc;

                                        dc = SOUA(nctm,ncA2);
                                        /* inside this inner loop 'dc' has always the same value...                                  */

                                        if        (dm > dc)
                                        /* this test should be true only the first time (YY=Ymin) for                                */
                                        /* IM(TM,X,Ymin)=...=IM(TM,X,Ymax).                                                          */
                                                  {
                                                  if        (YY > Ymin)
                                        /* it should be impossible to be there...                                                    */
                                                            {
                                                            flottant  fdm,fdc,fdiff;

                                                            pd(fdm) = dm;
                                                            pd(fdc) = dc;
                                                            pd(fdiff) = dm - dc;

                                                            printf("X=%04d Y=%04d YY=%04d :\n"
                                                                  ,X,Y,YY
                                                                   );
                                                            printf("dm=%.18f (%08x,%08x)\ndc=%.18f (%08x,%08x) diff=%.18f (%08x,%08x)\n"
                                                                  ,pd(fdm),pi1(fdm),pi2(fdm)
                                                                  ,pd(fdc),pi1(fdc),pi2(fdc)
                                                                  ,pd(fdiff),pi1(fdiff),pi2(fdiff)
                                                                   );
                                                            }

                                                  dm=dc;
                                                  cY=YY;
                                                  }
                                        }
                              }
                    }
          }

main()
          {
          double    parametreA=0.0;
          double    parametreB=(double)MIN2(Xmin+1,Xmax);

          fonction(parametreA,parametreB);
          }
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        E N D   O F   T E S T   P R O G R A M  :                                                                                   */
/*                                                                                                                                   */
/*************************************************************************************************************************************/


Sincerely yours,


Jean-Francois COLONNA

CMAP
Room 00.20.16
ECOLE POLYTECHNIQUE
91128 Palaiseau Cedex
France

WWW..... = http://www.lactamme.polytechnique.fr
Phone... = +33 (0)1 69 33 40 53
Fax..... = +33 (0)1 69 33 30 11
E-mail.. = colonna@cmap.polytechnique.fr


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