Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

vectorization of operations involving frexp ldexp modf etc.

$
0
0

How would I vectorise (say for avx2) a doubly indexed loop containing the following code:

double f (double lhs, double  rhs)
{
int index;
std::frexp(rhs, index);
auto twopwr = std::ldexp(double(.5), index);
return (lhs * twopwr + (rhs - twopwr);
}

So optimise/vectorise the following:

for (ptrdiff  i= 0; i < end(X) - begin(X) ; ++i)
   for (ptrdiff  j= 0; j < end(Y) - begin(Y) ; ++j)
      ANS.emplace_back( f(*(begin(X)+i), *(begin(Y)+j)) );

Where ANS X and Y are appropriately aligned vectors of doubles. One may reorder the loops. The order in ANS is not important here and can be dealt with elsewhere in the code. Actually f should be template and I need code that works work for floats, doubles, extended doubles, ...

The values lhs and rhs and f(lhs, rhs) are constrained and will always be fully represented positive integer doubles in the sense they are strictly positive and that index is always less than 53 and the integer part of lhs or rhs always equals lhs, rhs respectively. One could size ANS so that there were no memory allocations during the loops.

Suggestions appreciated?


Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>