On Thu, Nov 2, 2017 at 2:49 PM, Szabolcs Nagy <szabolcs.n...@arm.com> wrote: > On 01/11/17 16:47, Szabolcs Nagy wrote: >> On 01/11/17 16:26, Jakub Jelinek wrote: >>> On Wed, Nov 01, 2017 at 04:23:11PM +0000, Szabolcs Nagy wrote: >>>> is there a way to get vectorized math functions in fortran? >>>> >>>> in c code there is attribute simd declarations or openmp >>>> declare simd pragma to tell the compiler which functions >>>> have simd variant, but i see no such thing in fortran. >>> >>> !$omp declare simd should work fine in fortran (with -fopenmp >>> or -fopenmp-simd). >>> >> >> 1) i don't want to change the fortran. >> >> 2) it does not work for me. >> >> i want this to call vector powf in libmvec: >> >> subroutine foo(a,b,c) >> real(4) a(8000),b(8000),c(8000) >> do j=1,8000 >> a(j)=b(j)**c(j) >> end do >> end >> >> where do i put >> >> !$omp declare simd (powf) >> >> ? > > to answer my question.. > > it seems fortran cannot express the type signature > of mathematical functions because arguments are > passed by reference. > > so there is no way to declare math interfaces > and then add omp declare simd to them to get > simd versions. > > (it's not clear to me how omp declare simd is > supposed to work in fortran, but it is not useful > for vectorizing loops with math functions.) > > so gfortran will need a different mechanism to > do the vectorization, e.g. an option like > -mveclibabi=glibc, but the list of available > vector functions need to be specified somewhere.
The fortran frontend turns the b(j)**c(j) expression in your example into a "call" to __builtin_powf() (check with -fdump-tree-original), and similarly for other math intrinsics that have corresponding builtins. Ideally the middle-end optimizers should to be able to turn that into calls to the appropriate vector math library when -mveclibabi= is in effect. -- Janne Blomqvist