sort¶
sort
function¶
template <typename T, size_t N>
vec<T, N> sort(const vec<T, N> &x)
Sort the elements in the vector in ascending order
x input vector
@return sorted vector
CHECK(sort(make_vector(1000, 1, 2, -10)) == make_vector(-10, 1, 2, 1000));
Source code
template <typename T, size_t N>
KFR_INTRINSIC vec<T, N> sort(const vec<T, N>& x)
{
constexpr size_t Nhalf = N / 2;
vec<T, Nhalf> e = low(x);
vec<T, Nhalf> o = high(x);
constexpr auto blend0 = cconcat(csizes<1>, csizeseq<Nhalf - 1, 0, 0>);
for (size_t i = 0; i < Nhalf; i++)
{
vec<T, Nhalf> t;
t = min(e, o);
o = max(e, o);
o = rotateright<1>(o);
e = t;
t = max(e, o);
o = min(e, o);
e = t;
t = blend(e, o, blend0);
o = blend(o, e, blend0);
o = rotateleft<1>(o);
e = t;
}
return interleavehalves(concat(e, o));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/sort.hpp#L46
sortdesc
function¶
template <typename T, size_t N>
vec<T, N> sortdesc(const vec<T, N> &x)
Sort the elements in the vector in descending order
x input vector
@return sorted vector
CHECK(sort(make_vector(1000, 1, 2, -10)) == make_vector(1000, 2, 1, -10));
Source code
template <typename T, size_t N>
KFR_INTRINSIC vec<T, N> sortdesc(const vec<T, N>& x)
{
constexpr size_t Nhalf = N / 2;
vec<T, Nhalf> e = low(x);
vec<T, Nhalf> o = high(x);
constexpr auto blend0 = cconcat(csizes<1>, csizeseq<Nhalf - 1, 0, 0>);
for (size_t i = 0; i < Nhalf; i++)
{
vec<T, Nhalf> t;
t = max(e, o);
o = min(e, o);
o = rotateright<1>(o);
e = t;
t = min(e, o);
o = max(e, o);
e = t;
t = blend(e, o, blend0);
o = blend(o, e, blend0);
o = rotateleft<1>(o);
e = t;
}
return interleavehalves(concat(e, o));
}
https://github.com/kfrlib/kfr/blob//include/kfr/simd/sort.hpp#L79
Auto-generated from sources, Revision , https://github.com/kfrlib/kfr/blob//include/kfr/