◆ shuffle() [1/4]

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

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

Header <boost/simd/function/shuffle.hpp>
Semantic:

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

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

is equivalent to:

boost::simd::pack<T,N> r{ I1 != -1 ? x[I1] : 0, ..., In != -1 ? x[In] : 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};
std::cout << "Original: " << x << std::endl
<< "Permuted: " << boost::simd::shuffle<3,-1,2,0>(x) << std::endl;
return 0;
}
Possible output:
Original: (1, 2, 3, 4)
Permuted: (4, 0, 3, 1)
Parameters
xboost::simd::pack to shuffle