[Bug c/54408] sqrt for vector types

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Sep 6 15:05:00 GMT 2012


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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> 2012-09-06 15:04:53 UTC ---
Thanks for the explanations.

One goal would be, in C++, to be able to write a single function template:

template<class T> T f(T x){return x+sqrt(x);}

which would work for float, double, long double, float vectors and double
vectors. (how exactly sqrt is spelled, possibly __builtin_math_sqrt, isn't that
important)

Currently, std::sqrt is overloaded on arithmetic types. If we had
__builtin_vec_sqrt, I guess we could add an extra overload to std::sqrt for
vector types (sfinae-constrained in some way). Not quite as convenient as a
completely generic __builtin_sqrt, but good enough I think (assuming the
libstdc++ maintainers are ok with it). Otherwise, a more generic
__builtin_math_sqrt which works on both scalars and vectors would be better.



More information about the Gcc-bugs mailing list