g77 i586 different optimization for real*4 in common/dimension

Dmitry A. Bukin bukind@sndxt1.inp.nsk.su
Tue Apr 8 07:58:00 GMT 2003


Hello,

We have noticed that a program compiled by g77 with optimization
produces different results in array of real*4 dependent on
the location of this array (whether it is in common or in dimension).
The problematic program is placed into attachment -- both
variants: with common and with dimension.

OS: redhat-8.0

processor type:
unix% cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 6
model           : 3
model name      : AMD Duron(tm) Processor
stepping        : 1
cpu MHz         : 756.728
cache size      : 64 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov 
pat pse36 mmx fxsr syscall mmxext 3dnowext 3dnow
bogomips        : 1502.29

g77 version:
unix% g77 --version
GNU Fortran (GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)) 3.2 20020903 (Red 
Hat Linux 8.0 3.2-7)
Copyright (C) 2002 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
or type the command `info -f g77 Copying'.

libc version:
unix% rpm -q glibc
glibc-2.3.2-4.80

compilation command line arguments and output:
unix% g77 --verbose -O -g -fno-ugly -fugly-assumed -Wall -Wsurprising -W -malign-double -fforce-mem -fforce-addr -fno-automatic -finit-local-zero -fdollar-ok -Wuninitialized -ffixed-line-length-none -o test1 test1.for
Driving: g77 -v -O -g -fno-ugly -fugly-assumed -Wall -Wsurprising -W -malign-double -fforce-mem -fforce-addr -fno-automatic -finit-local-zero -fdollar-ok -Wuninitialized -ffixed-line-length-none -o test1 test1.for -lfrtbegin -lg2c -lm -shared-libgcc
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2/f771 test1.for -quiet -dumpbase test1.for -malign-double -g -O -Wall -Wsurprising -W -Wuninitialized -version -fno-ugly -fugly-assumed -fforce-mem -fforce-addr -fno-automatic -finit-local-zero -fdollar-ok -ffixed-line-length-none -o /tmp/ccHRCOS3.s
GNU F77 version 3.2 20020903 (Red Hat Linux 8.0 3.2-7) (i386-redhat-linux)
	compiled by GNU C version 3.2 20020903 (Red Hat Linux 8.0 3.2-7).
 as -V -Qy -o /tmp/ccGRjrx1.o /tmp/ccHRCOS3.s
GNU assembler version 2.13.90.0.2 (i386-redhat-linux) using BFD version 2.13.90.0.2 20020802
 /usr/lib/gcc-lib/i386-redhat-linux/3.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test1 /usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crt1.o /usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crti.o /usr/lib/gcc-lib/i386-redhat-linux/3.2/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/3.2 -L/usr/lib/gcc-lib/i386-redhat-linux/3.2/../../.. /tmp/ccGRjrx1.o -lfrtbegin -lg2c -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc-lib/i386-redhat-linux/3.2/crtend.o /usr/lib/gcc-lib/i386-redhat-linux/3.2/../../../crtn.o

Difference in output of two programs:
unix% diff -u test1.out test2.out
--- test1.out   2003-04-08 14:37:43.000000000 +0700
+++ test2.out   2003-04-08 14:37:40.000000000 +0700
@@ -10,11 +10,11 @@
   1.25663996  0.309014231  0.951057434
   1.57079995 -3.61999014E-06  1.
   1.88495994 -0.309021115  0.951055169
-  2.19912004 -0.587789357  0.809014022
+  2.19912004 -0.587789357  0.809013963
   2.51327991 -0.8090204  0.587780595
-  2.82743979 -0.951058507  0.309010804
+  2.82743979 -0.951058507  0.309010923
   3.14159989 -1. -7.23998028E-06
-  3.45576 -0.951054037 -0.309024572
+  3.45576 -0.951054037 -0.309024692
   3.76991987 -0.809011877 -0.587792277
-  4.08407974 -0.587777615 -0.809022546
-  4.39824009 -0.309007347 -0.951059639
+  4.08407974 -0.587777615 -0.809022486
+  4.39824009 -0.309007347 -0.951059699

This problem disappeared when we used option -ffloat-store,
but we are afraid of the performance hit of this option...
The replacement of real*4 with real*8 solves the problem also,
but this solution is not suitable, as we want our results
to be the same as they were on the older platform/compiler.

The solution with setting _FPU_DOUBLE bit in the control word of FPU
does not solve the problem.

The older compiler we have also used (GNU Fortran 0.5.24-19981002)
did not show this problem.

With best regards,
-- 
 Apr 8 13:56 
Dmitry Bukin.  D.A.Bukin@inp.nsk.su
-------------- next part --------------
      program test1
      common /chcb07/ ac(20),as(20)
      data alo/0./

      do i = 1, 20
        al = -90. + 18.*(i-1) + alo
        al = al * 3.1416 / 180.
        ac(i) = cos(al)
        as(i) = sin(al)
        write (6,*) al, ac(i), as(i)
      enddo
      end
-------------- next part --------------
      program test1
      dimension ac(20),as(20)
      data alo/0./

      do i = 1, 20
        al = -90. + 18.*(i-1) + alo
        al = al * 3.1416 / 180.
        ac(i) = cos(al)
        as(i) = sin(al)
        write (6,*) al, ac(i), as(i)
      enddo
      end


More information about the Gcc-bugs mailing list