◆ shuffle() [2/4]

template<int P0, int ... Ps, typename T >
T boost::simd::shuffle ( T const &  x,
T const &  y 
)

Shuffle the elements of two boost::simd::pack using an index permutation described by compile-time integral constants.

Semantic:

For any boost::simd::pack x and y of base type T and cardinal N and N compile-time integral constants I1...In with value comprised between -1 and 2*N-1, the following code:

boost::simd::pack<T,N> r = shuffle<I1,...,In>(x,y);

is equivalent to:

boost::simd::pack<T,N> r{ I1 != -1 ? (I1<N ? x[I1] : y[I1-N]) : 0, ..., In != -1 ? (In<N ? x[In] : y[In-N]) : 0 };

The actual integral constants is mapped at compile-time to the optimal sequence of intrinsics to apply the desired permutation.

The special index value -1 is used to specify that, instead of fetching a data from inside the shuffled boost::simd::pack, the value 0 has to be inserted in the result.

Example:
#include <boost/simd/pack.hpp>
#include <boost/simd/function/shuffle.hpp>
#include <iostream>
int main()
{
boost::simd::pack<float,4> x{1.f,2.f,3.f,4.f}, y{10.f,20.f,30.f,40.f};
std::cout << "Original: " << x << " " << y << std::endl
<< "Permuted: " << boost::simd::shuffle<-1,3,7,-1>(x,y) << std::endl;
return 0;
}
Possible output:
Original: (1, 2, 3, 4) (10, 20, 30, 40)
Permuted: (0, 4, 40, 0)
Parameters
xboost::simd::pack to shuffle
yboost::simd::pack to shuffle