public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: szabolcs.nagy@arm.com,
	Janne Blomqvist <blomqvist.janne@gmail.com>,
	nd@arm.com, 	GCC Development <gcc@gcc.gnu.org>,
	"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	sellcey@cavium.com
Subject: Re: libmvec in gcc to have vector math in fortran
Date: Thu, 14 Jun 2018 22:41:00 -0000	[thread overview]
Message-ID: <CAFiYyc361TAA3Fos=hfY-C11KhhF-gU4qXZd49TfJNXFevRU4g@mail.gmail.com> (raw)
In-Reply-To: <20180410130655.GD8577@tucnak>

On Tue, Apr 10, 2018 at 3:07 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Tue, Apr 10, 2018 at 02:55:43PM +0200, Richard Biener wrote:
> > > And the easiest solution is in the Fortran FE based on some flag
> > > (e.g. -mveclibabi=glibc) through a target hook add
> > > __attribute__((__simd__ ("notinbranch")))
> > > to the builtins like __builtin_sin etc. that have them in the
> > > glibc header (x86_64 -m64 and -ffast-math only):
> > >
> > > #  undef __DECL_SIMD_cos
> > > #  define __DECL_SIMD_cos __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_cosf
> > > #  define __DECL_SIMD_cosf __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_sin
> > > #  define __DECL_SIMD_sin __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_sinf
> > > #  define __DECL_SIMD_sinf __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_sincos
> > > #  define __DECL_SIMD_sincos __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_sincosf
> > > #  define __DECL_SIMD_sincosf __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_log
> > > #  define __DECL_SIMD_log __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_logf
> > > #  define __DECL_SIMD_logf __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_exp
> > > #  define __DECL_SIMD_exp __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_expf
> > > #  define __DECL_SIMD_expf __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_pow
> > > #  define __DECL_SIMD_pow __DECL_SIMD_x86_64
> > > #  undef __DECL_SIMD_powf
> > > #  define __DECL_SIMD_powf __DECL_SIMD_x86_64
> > >
> > > The sincos/sincosf stuff is questionable, because some glibc versions
> > > implement it incorrectly and the simd ("notinbranch") attribute isn't that
> > > useful for it anyway, we'd want to use extra clauses so that it doesn't need
> > > to do scatter stores.
> >
> > I wonder if it is possible for glibc to ship a "module" for fortran instead
> > containing the appropriate declarations and gfortran auto-include that
> > (if present).
>
> Then we'd run into module binary format changing every release, so hard for
> glibc to ship that.
>
> Another thing is how would we express it in the module,
> we could just use OpenMP syntax,
>       interface
>         function sin(x) bind(C,name="__builtin_sin") result(res)
>           import
>           !$omp declare simd notinbranch
>           real(c_double) :: res
>           real(c_double),value :: x
>         end function
>       end interface
> but we'd need to temporarily enable OpenMP while parsing that module.

As-is the above doesn't work - it doesn't seem to redeclare sin() in a way
that it is 'const', thus dependence analysis rejects calls to it.

I'm playing with the following

subroutine bar (a)
  use, intrinsic :: iso_c_binding, only: c_double
  interface
    pure function sin(x) bind(C,name="sin") result(res)
     !$omp declare simd notinbranch
     import
     real(c_double) :: res
     real(c_double),value :: x
  end function sin
  end interface
  real(8) a(100,100)
  do I=1,100
   do J = 1,100
    a(j,i) = sin(a(j,i))
   end do
 end do
end subroutine bar

'pure' makes it pure but there doesn't seem to be a way to make it const?
Any hint on how to improve the interface above?  With
-fopemp -fopenmp-simd -Ofast the loop should be vectorized
(if I got index order correct).

That is, fortran doesn't seem to do anything like "merging" the above
declaration with the existing builtin so the binding above needs to be
complete.

I'm still thinking of exposing libmvec using a include/module that gets
implicitely picked up by gfortran if present.

Richard.

> I see Fortran now supports already
> !GCC$ attributes stdcall, fastcall::test
> Could we support
> !GCC$ attributes simd
> and
> !GCC$ attributes simd('notinbranch')
> too?
>
>         Jakub

  parent reply	other threads:[~2018-06-14 10:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10 10:14 Szabolcs Nagy
2018-04-10 10:22 ` Janne Blomqvist
2018-04-10 11:35   ` Szabolcs Nagy
2018-04-10 12:55     ` Jakub Jelinek
2018-04-10 13:26       ` Richard Biener
2018-04-10 13:42         ` Jakub Jelinek
2018-04-10 13:27           ` Richard Biener
2018-04-10 13:35           ` Richard Biener
2018-04-18  8:41             ` Szabolcs Nagy
2018-04-18  8:57               ` Richard Biener
2018-06-14 22:41           ` Richard Biener [this message]
2018-06-15  8:39             ` Florian Weimer
2018-06-15  8:40               ` Szabolcs Nagy
2018-06-15  9:08                 ` Richard Biener
2018-06-15  8:41               ` Richard Biener
2018-06-15  9:33                 ` Florian Weimer
2018-06-15 11:39                   ` Richard Biener
2018-06-15 20:59                     ` Thomas Koenig
2018-06-15 22:41                       ` Joseph Myers
2018-06-18 11:10                         ` Richard Biener
2018-06-18 16:02                           ` Joseph Myers
2018-06-18 16:22                             ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFiYyc361TAA3Fos=hfY-C11KhhF-gU4qXZd49TfJNXFevRU4g@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=blomqvist.janne@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=nd@arm.com \
    --cc=sellcey@cavium.com \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).