[PATCH][fortran] Make sincos, cexpi and cbrt available

Richard Guenther richard.guenther@gmail.com
Fri Jan 19 23:03:00 GMT 2007


On 1/19/07, Tobias Burnus <burnus@net-b.de> wrote:
> Hi all,
>
> Richard Guenther wrote:
> > This makes said functions available from the fortran frontend for
> > use by the middle-end conditional on TARGET_C99_FUNCTIONS and
> > TARGET_GNU_SINCOS.
> >
> > Bootstrap and regtest in progress.
> >
>
> I applied the patch (with the change TARGET_GNU_SINCOS ->
> TARGET_HAS_SINCOS), bootstapped (with manually running symbol.c without
> -Werror) and did a regression test on x86_64-unknown-linux-gnu (alias
> openSUSE Factory), which gave no errors.
>
> As all? needed parts of the middle end are also checked in,
> http://gcc.gnu.org/ml/gcc-cvs/2007-01/msg00657.html  (adds
> TARGET_HAS_SINCOS)
> http://gcc.gnu.org/ml/gcc-cvs/2007-01/msg00658.html
> this patch only depends on a Fortran maintainer's review.
>
>
> > 2007-01-17  Richard Guenther  <rguenther@suse.de>
> >
> >       * f95-lang.c (gfc_init_builtin_functions): Provide cbrt and
> >       cexpi builtins if we have TARGET_C99_FUNCTIONS.  Provide
> >       sincos builtins if the target has sincos.
> >
> Shouldn't one add    PR fortran/30233  ?

30223, indeed.  I'll make sure to do so.

> Now, as proud owner of sincos, I tried to optimize a simple program (cf.
> PR 30038); however, it does not use sincos(). Any ideas what goes wrong
> here? [Same with Polyhedron's fatigue: No sincos!]

Well, the sincos patch is not yet applied ;)

> (Side note: For fatigue, the unmodified [and also the modified] gfortran
> which uses sinf/cosf takes 19.7s, ifort which uses sincos needs 11.8s
> and sunf95 needs only 8.4s and uses sin/cos. With gfortran I got once a
> >20% speedup with sincos [cf. PR 30038, comment 17].)
>
> (Side note 2: Using r**(1./3.) => cbrtf() works.)
>
> Tobias
>
> PS: Big thanks to Richard for his sincos work!
>
> ----------------------------------------
> integer :: i, j
> volatile :: j = 1
> real :: r, s(10000),c(10000)
> do i = 1, 10000
>   r = real(i)/1000.0
>   s(i) = sin(r)
>   c(i) = cos(r)
> end do
> print *, s(j),c(j)
> end
> ----------------------------------------
>
> If I run now:
> gfortran -O3 -ftree-vectorize -ftree-vectorizer-verbose=6 -funroll-loops
> -ffast-math -msse3 x.f90
> x.f90:7: note: not vectorized: unsupported use in stmt.
> x.f90:1: note: vectorized 0 loops in function.
>
> Looking at x.f90.103t.vrp2 shows:
>
> <L0>:;
>   D.1460_61 = (<unnamed type>) ivtmp.36_59;
>   D.1461_64 = D.1460_61 + 2;
>   i_66 = (int4) D.1461_64;
>   i_1 = i_66;
>   D.1396_3 = (real4) i_1;
>   r_4 = D.1396_3 * 1.000000047497451305389404296875e-3;
>   D.1399_7 = __builtin_sinf (r_4);
>   D.1462_56 = (<unnamed type>) ivtmp.36_59;
>   MEM[symbol: s, index: D.1462_56, step: 4, offset: 4] = D.1399_7;
>   D.1400_10 = __builtin_cosf (r_4);
>   D.1463_55 = (<unnamed type>) ivtmp.36_59;
>   MEM[symbol: c, index: D.1463_55, step: 4, offset: 4] = D.1400_10;
>   ivtmp.36_60 = ivtmp.36_59 + 1;
>   if (ivtmp.36_60 == 9999) goto <L4>; else goto <L0>;

With libgcc-math we could even vectorize this loop...

Richard.



More information about the Gcc-patches mailing list