diff --git a/sort.hh b/sort.hh new file mode 100644 index 0000000..c36623d --- /dev/null +++ b/sort.hh @@ -0,0 +1,112 @@ +/* +Sorting for SIMD types + +Copyright 2024 Ahmet Inan +*/ + +#pragma once + +#include + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vorder(SIMD a) +{ + SIMD tmp; + for (int i = 0; i < WIDTH; ++i) + tmp.v[i] = i; + std::stable_sort(tmp.v, tmp.v+WIDTH, [a](int i, int j){ return a.v[i] < a.v[j]; }); + return tmp; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} + +template +static inline SIMD vsort(SIMD a) +{ + std::sort(a.v, a.v+WIDTH); + return a; +} +