public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/34128]  New: slow gfortran 4.x (library?) compared to g77 3.4
@ 2007-11-16 22:23 mnoble at space dot mit dot edu
  2007-11-17  0:08 ` [Bug fortran/34128] " fxcoudert at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: mnoble at space dot mit dot edu @ 2007-11-16 22:23 UTC (permalink / raw)
  To: gcc-bugs

The following codes (compiled as demo1.f and demo2.f)

      PROGRAM demo1                     PROGRAM demo2

      integer i                         integer i
      double precision result           double precision result

      do i=1,8000000                    do i=1,500000000
         result = sin(i*3.14159)           result = i*3.14159
      enddo                             enddo

      print*,'result = ',result         print*,'result = ',result
      END                               END

reveal marked performance disparities between g77 and gfortran on an
x86_64 Debian Linux 4.0 machine with 4 AMD Opteron cores:

        vendor_id       : AuthenticAMD
        cpu family      : 15
        model           : 65
        model name      : Dual-Core AMD Opteron(tm) Processor 2216
        stepping        : 2
        cpu MHz         : 2400.452

Sample timings are given below, comparing the Debian binary package
of g77 3.4.6 against both gfortran 4.1.2 (Debian binary package) &
gfortran 4.2.1 (locally built from source).  Perhaps a gfortran
library issue?

Regards,
Michael S. Noble

--------------------------------------------------------------------

% uname -a
Linux rabble 2.6.18-5-amd64 #1 SMP Tue Oct 2 20:37:02 UTC 2007 x86_64 GNU/Linux

which g77 && g77 -v

        /usr/bin/g77

        Reading specs from /usr/lib/gcc/x86_64-linux-gnu/3.4.6/specs
        Configured with: ../src/configure -v
--enable-languages=c,c++,f77,pascal --prefix=/usr --libexecdir=/usr/lib
--with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --program-suffix=-3.4
--enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug
x86_64-linux-gnu
        Thread model: posix
        gcc version 3.4.6 (Debian 3.4.6-5)


g77 -o demo1-g77 -O2 demo1.f
time ./demo1-g77

        result = -0.690680921
        real     0m0.562s


g77 -o demo2-g77 -O2 demo2.f
time ./demo2-g77

         result = 1.57079501E+09
         real     0m0.041s


which gfortran && gfortran -v

        /usr/bin/gfortran

        Using built-in specs.
        Target: x86_64-linux-gnu
        Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release
x86_64-linux-gnu
        Thread model: posix
        gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

gfortran -o demo1-gfortran -O2 demo1.f
time ./demo1-gfortran

        result = -0.690680921077728
        real      0m7.681s

gfortran -o demo2-gfortran -O2 demo2.f
time ./demo2-gfortran

         result = 1570795008.00000
         real     0m2.085s


\rm demo?-gfortran
PATH=/usr/local/bin:$PATH
which gfortran && gfortran -v

        /usr/local/bin/gfortran
        Using built-in specs.
        Target: x86_64-unknown-linux-gnu
        Configured with: ./configure --prefix=/usr/local
--enable-languages=c,c++,fortran
        Thread model: posix
        gcc version 4.2.1

gfortran -o demo1-gfortran -O2 demo1.f -L/usr/local/lib -Wl,-R/usr/local/lib
time ./demo1-gfortran

        result =  -0.690680921077728
        real    0m7.672s

gfortran -o demo2-gfortran -O2 demo2.f -L/usr/local/lib -Wl,-R/usr/local/lib
time ./demo2-gfortran

        result =    1570795008.00000
        real    0m2.085s


-- 
           Summary: slow gfortran 4.x (library?) compared to g77 3.4
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mnoble at space dot mit dot edu
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
@ 2007-11-17  0:08 ` fxcoudert at gcc dot gnu dot org
  2007-11-17 22:35 ` bdavis at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-11-17  0:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-11-17 00:07 -------
While I'm trying to understand what happens, I should say that a simply
workaround is to make your calculation happen in double precision (change
"3.14159" into "3.14159d0"; after all, you want a double-precision result).

g77 called sin() to perform the calculation, while gfortran calls sinf(). And
sinf() happens to be way slower than sin() (I wonder why!). Maybe a bugreport
to glibc will be in order here.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
          Component|libfortran                  |fortran
     Ever Confirmed|0                           |1
           Keywords|                            |missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2007-11-17 00:07:55
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
  2007-11-17  0:08 ` [Bug fortran/34128] " fxcoudert at gcc dot gnu dot org
@ 2007-11-17 22:35 ` bdavis at gcc dot gnu dot org
  2007-11-17 22:42 ` fxcoudert at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bdavis at gcc dot gnu dot org @ 2007-11-17 22:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bdavis at gcc dot gnu dot org  2007-11-17 22:35 -------
here is what i got on a P4, running FC8.


[bdavis@localhost gfc]$ /usr/bin/gfortran -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-cpu=generic
--host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20070925 (Red Hat 4.1.2-33)
[bdavis@localhost gfc]$ /usr/bin/gfortran demo1.f
[bdavis@localhost gfc]$ time ./a.out
 result =  -0.690680926641407     

real    0m0.948s
user    0m0.914s
sys     0m0.002s
[bdavis@localhost gfc]$ /usr/bin/gfortran demo2.f
[bdavis@localhost gfc]$ time ./a.out
 result =    1570795059.20410     

real    0m1.853s
user    0m1.808s
sys     0m0.004s
[bdavis@localhost gfc]$ g77 --version
GNU Fortran (GCC) 3.4.6 20060404 (Red Hat 3.4.6-8)
Copyright (C) 2006 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'.
[bdavis@localhost gfc]$ g77 demo1.f
[bdavis@localhost gfc]$ time ./a.out
 result =  -0.990368962

real    0m0.938s
user    0m0.912s
sys     0m0.002s
[bdavis@localhost gfc]$ g77 demo2.f
[bdavis@localhost gfc]$ time ./a.out
 result =   1.57079506E+09

real    0m2.386s
user    0m2.354s
sys     0m0.004s



           gfortran      g77
demo1     0m0.948s    0m0.938s
demo2     0m1.853s    0m2.386s


the answers were different on demo1.f


with these versions, and on the P4 under linux, i say gfortran is OK.


--bud


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
  2007-11-17  0:08 ` [Bug fortran/34128] " fxcoudert at gcc dot gnu dot org
  2007-11-17 22:35 ` bdavis at gcc dot gnu dot org
@ 2007-11-17 22:42 ` fxcoudert at gcc dot gnu dot org
  2007-11-18  8:37 ` burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-11-17 22:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from fxcoudert at gcc dot gnu dot org  2007-11-17 22:42 -------
It's 64-bit only, and it appears to be a glibc bug: with glibc on x86_64,
sinf((float) integer_variable) is slower than (float)sin((double)
integer_variable). Paul Brook looked into it a bit, and said that while glibc's
sin() was clearly well optimized, its sinf() was poor.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (2 preceding siblings ...)
  2007-11-17 22:42 ` fxcoudert at gcc dot gnu dot org
@ 2007-11-18  8:37 ` burnus at gcc dot gnu dot org
  2007-12-08 19:00 ` jvdelisle at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-11-18  8:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2007-11-18 08:37 -------
> It's 64-bit only, and it appears to be a glibc bug: with glibc on x86_64,
> sinf((float) integer_variable) is slower than (float)sin((double)
> integer_variable).

Can it be that it has been fixed meanwhile? Using demo1.f on x86-64 (openSUSE
factory; glibc 2.6.1 (20070803), g77 3.3.5 20050117; gfortran 4.3.0 20071117;
AMD Athlon64 x2 4800+) I get the following timings with "-O2":

              g77     gfortran
-m32  real(4) 0.408s  0.421s
-m64  real(4) 1.040s  0.589s
-m32  real(8) 0.411s  0.408s
-m64  real(8) 0.976s  0.968s


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (3 preceding siblings ...)
  2007-11-18  8:37 ` burnus at gcc dot gnu dot org
@ 2007-12-08 19:00 ` jvdelisle at gcc dot gnu dot org
  2007-12-08 19:05 ` jvdelisle at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-12-08 19:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jvdelisle at gcc dot gnu dot org  2007-12-08 18:59 -------
On x86-64 (gfc = gfortran)

$ gfc -m32 demo1.f 
$ time ./a.out
 result =  -0.69068092664140723     

real    0m0.552s
user    0m0.551s
sys     0m0.001s
$ gfc -m64 demo1.f 
$ time ./a.out
 result =  -0.69068092107772827     

real    0m8.533s
user    0m8.532s
sys     0m0.002s
$ g77 -m32 demo1.f 
$ time ./a.out
 result =  -0.990368962

real    0m0.546s
user    0m0.545s
sys     0m0.002s
$ g77 -m64 demo1.f 
$ time ./a.out
 result =  -0.690680921

real    0m0.877s
user    0m0.874s
sys     0m0.003s
$ 

Something definitely wrong here.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (4 preceding siblings ...)
  2007-12-08 19:00 ` jvdelisle at gcc dot gnu dot org
@ 2007-12-08 19:05 ` jvdelisle at gcc dot gnu dot org
  2008-03-29  4:49 ` jvdelisle at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2007-12-08 19:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jvdelisle at gcc dot gnu dot org  2007-12-08 19:04 -------
Note in comment #5 the g77 wrong result when using -m32.  Not a good thing.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (5 preceding siblings ...)
  2007-12-08 19:05 ` jvdelisle at gcc dot gnu dot org
@ 2008-03-29  4:49 ` jvdelisle at gcc dot gnu dot org
  2008-03-29  5:28 ` jvdelisle at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-03-29  4:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jvdelisle at gcc dot gnu dot org  2008-03-29 04:48 -------
The disparity goes away mostly using -ffast-math

$ g77 -ffast-math demo1.f -o g771
$ time ./g771
 result =  -0.690680927

real    0m0.594s
user    0m0.590s
sys     0m0.004s

$ gfc -ffast-math demo1.f -o gfc1
$ time ./gfc1
 result =  -0.69068092664138392     

real    0m0.720s
user    0m0.716s
sys     0m0.003s

Regardless sinf needs some work.  See also glibc bug 1163:

http://sources.redhat.com/bugzilla/show_bug.cgi?id=1163

Which identifies some other issues.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (6 preceding siblings ...)
  2008-03-29  4:49 ` jvdelisle at gcc dot gnu dot org
@ 2008-03-29  5:28 ` jvdelisle at gcc dot gnu dot org
  2008-03-29 21:20 ` jvdelisle at gcc dot gnu dot org
  2009-03-28 13:21 ` fxcoudert at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-03-29  5:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from jvdelisle at gcc dot gnu dot org  2008-03-29 05:27 -------
Browsing through the glibc sources I see two kinds of implementations for the
sinf function, FPU and software.

The FPU versions appear to be succinct assembly code with the expected FPU
instructions.

The software versions appear to be fairly elaborate and written in C using
taylor series expansions.

I wonder if the time difference being seen is that the slow sinf function is a
software implementation rather than FPU.  The problem does not occur with cos.
I speculate that this is a configuration related problem.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (7 preceding siblings ...)
  2008-03-29  5:28 ` jvdelisle at gcc dot gnu dot org
@ 2008-03-29 21:20 ` jvdelisle at gcc dot gnu dot org
  2009-03-28 13:21 ` fxcoudert at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2008-03-29 21:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jvdelisle at gcc dot gnu dot org  2008-03-29 21:19 -------
I have submitted glibc PR

http://sources.redhat.com/bugzilla/show_bug.cgi?id=5997

With a C test case that clearly shows the problem.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug fortran/34128] slow gfortran 4.x (library?) compared to g77 3.4
  2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
                   ` (8 preceding siblings ...)
  2008-03-29 21:20 ` jvdelisle at gcc dot gnu dot org
@ 2009-03-28 13:21 ` fxcoudert at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-03-28 13:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from fxcoudert at gcc dot gnu dot org  2009-03-28 13:21 -------
I think this is glibc issue, which can be worked around (as Jerry demonstrated)
e.g. by using -ffast-math or by using a differently math library. Thus, I'm
closing this PR.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
             Status|NEW                         |RESOLVED
  GCC build triplet|x86_64-unknown-linux-gnu    |
   GCC host triplet|x86_64-unknown-linux-gnu    |
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34128


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-03-28 13:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-16 22:23 [Bug libfortran/34128] New: slow gfortran 4.x (library?) compared to g77 3.4 mnoble at space dot mit dot edu
2007-11-17  0:08 ` [Bug fortran/34128] " fxcoudert at gcc dot gnu dot org
2007-11-17 22:35 ` bdavis at gcc dot gnu dot org
2007-11-17 22:42 ` fxcoudert at gcc dot gnu dot org
2007-11-18  8:37 ` burnus at gcc dot gnu dot org
2007-12-08 19:00 ` jvdelisle at gcc dot gnu dot org
2007-12-08 19:05 ` jvdelisle at gcc dot gnu dot org
2008-03-29  4:49 ` jvdelisle at gcc dot gnu dot org
2008-03-29  5:28 ` jvdelisle at gcc dot gnu dot org
2008-03-29 21:20 ` jvdelisle at gcc dot gnu dot org
2009-03-28 13:21 ` fxcoudert at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).