Do you know a way to use a sorting algorithm that uses vectors intrinsics efficiently ?
I have to use the capability of loading, storing 4 floats at one operation and also other vectors operations.
I found this code for "Quick Sort". Can you help me understand how to implement it with SIMD ?
int partition(float *arr, int low, int high)
{
float pivot;
int i, j;
// pivot (Element to be placed at right position)
pivot = arr[high];
i = (low - 1); // Index of smaller element and indicates the
// right position of pivot found so far
for (j = low; j <= high - 1; j++) {
// If current element is smaller than the pivot
if (arr[j] < pivot) {
i++; // increment index of smaller element
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}
/* low –> Starting index, high –> Ending index */
void quickSort(float *arr, int low, int high)
{
int pi;
if (low < high) {
/* pi is partitioning index, arr[pi] is now at right place */
pi = partition(arr, low, high);
quickSort(arr, low, pi-1); // Before pi
quickSort(arr, pi + 1, high); // After pi
}
}