On Tue, Apr 10, 2018 at 12:45 PM, Szabolcs Nagy <szabolcs.n...@arm.com>

> i had a query earlier about libmvec vector functions in fortran:
> https://gcc.gnu.org/ml/gcc/2017-11/msg00007.html
> but there were no simple solutions to make math functions vectorizable
> in fortran, because it's hard to make libc headers with simd attributes
> visible to the fortran front end.
> i think a possible workaround is to have a dummy libmvec implementation
> in libgcc.a (or more likely as a separate libgccmvec.a) that just calls
> scalar functions from libm like
> vdouble _ZGVbN2v_sin(vdouble x)
> {
>   return (vdouble){sin(x[0]), sin(x[1])};
> }
> and similarly for all relevant single and double precision functions
> for all vector lengths and other supported variants.
> then gcc knows that there is an implementation for these functions
> available and with the right link order a better implementation from
> libmvec can override these dummy implementations. (the cost model
> cannot assume a faster vector algorithm than the scalar one though)
> - this allows vectorizing loops with math functions even in fortran,
> - and on targets without a libmvec implementation (but with a vector abi),
> - and allows users to provide their own vector math implementation
> more easily without hacking around glibc math.h (which may not support
> vector math or only enable it for a small subset of math functions).
> gcc needs a new cflag and ldflag to enable this.
> (maybe -mveclibabi= already present in x86 and ppc can be used for this)
As I mentioned previously in that thread you linked to, the fortran
frontend never generates a direct call to libm sin(), or for that matter
ZGVbN2v_sin(). Instead it generates a "call" to __builtin_sin(). And
similarly for other libm functions that have gcc builtins. The middle-end
optimizers are then free to do whatever optimizations they like on that
__builtin_sin call, such as constant folding, and at least as far as the
fortran frontend is concerned, vectorizing if -mveclibabi= or such is in

Janne Blomqvist

Reply via email to