ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
VectorQuickSort.h

The quicksort in the lanes of the vector registers, beyond the book. More...

Files

file  ADS/sort/VectorQuickSort.h
 The quicksort in the lanes of the vector registers, beyond the book: vectorQuickSort() sorts integers and floating point numbers of 32 or 64 bits by their natural order.

Concepts

concept  ADS::VectorKey
 the types that vectorQuickSort() sorts: integers and floating point numbers of 32 or 64 bits

Macros

#define ADS_VECTOR_SORT   ADS_SIMD
 1 if the sort is the quicksort of Highway on the vectors of the processor, 0 if the portable code; by default ADS_SIMD [see Simd.h], and it may be set to 0 before the include

Functions

template<SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void ADS::vectorQuickSort (Store &&A)
 the quicksort of \( A \) in the lanes of the vector registers, by the natural order (the total order of IEEE 754 for floating point numbers)
template<VectorKey T>
void ADS::vectorQuickSort (std::vector< T > &A)
 vectorQuickSort() above on a vector
template<VectorKey T>
void ADS::vectorQuickSort (T *a, std::size_t n)
 the sort of vectorQuickSort() above on \( a[ 0 .. n - 1 ] \)
template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { vectorQuickSort( v , std::forward< P >( p )... ); }
decltype(auto) ADS::vectorQuickSort (R &&A, P &&... p)
 vectorQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses

Variables

constexpr bool ADS::kVectorSort = ADS_VECTOR_SORT != 0
 true if vectorQuickSort() runs in the vectors of the processor, by the quicksort of Highway, false if in the arrays of the portable code

Detailed description

The quicksort in the lanes of the vector registers, beyond the book.

The definitions, the invariants and the costs of the area are in Theory of sorting.

Macro definition documentation

◆ ADS_VECTOR_SORT

#define ADS_VECTOR_SORT   ADS_SIMD

1 if the sort is the quicksort of Highway on the vectors of the processor, 0 if the portable code; by default ADS_SIMD [see Simd.h], and it may be set to 0 before the include

Function documentation

◆ vectorQuickSort() [1/4]

template<SortRange R, class... P>
requires requires( std::vector< std::ranges::range_value_t< R > > & v , P &&... p ) { vectorQuickSort( v , std::forward< P >( p )... ); }
decltype(auto) ADS::vectorQuickSort ( R && A,
P &&... p )

vectorQuickSort() on the range \( A \) [see SortRange], the other arguments as for a vector: in place on the span of its items if \( A \) is contiguous, through a vector of its items otherwise, since the code of the sort reads the items by their addresses

◆ vectorQuickSort() [2/4]

template<VectorKey T>
void ADS::vectorQuickSort ( std::vector< T > & A)

vectorQuickSort() above on a vector

◆ vectorQuickSort() [3/4]

template<SortStore Store, VectorKey T = std::ranges::range_value_t< std::remove_cvref_t< Store > >>
void ADS::vectorQuickSort ( Store && A)

the quicksort of \( A \) in the lanes of the vector registers, by the natural order (the total order of IEEE 754 for floating point numbers)

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{vectorQuickSort}( A ) \cr 2 & \quad \mathrm{vectorQuickSort}( A , n ) \end{array}} \]

Postcondition
\( A \) is sorted, with the same items (audit)

◆ vectorQuickSort() [4/4]

template<VectorKey T>
void ADS::vectorQuickSort ( T * a,
std::size_t n )

the sort of vectorQuickSort() above on \( a[ 0 .. n - 1 ] \)

In pseudocode (after the quicksorts of Bramas, of Gueron and Krasnov and of Wassenberg et al., beyond the book), \( W \) the lanes of a register and the keys of floating point numbers their bits as signed integers:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{vqs}( a , \mathit{lo} , \mathit{hi} , \mathit{depth} ) \cr 2 & \quad \textbf{while}\ \mathit{hi} - \mathit{lo} > 16 W\ \textbf{do} \cr 3 & \qquad \textbf{if}\ \mathit{depth} = 0\ \textbf{then}\ \text{heapsort } a[ \mathit{lo} .. \mathit{hi} - 1 ];\ \textbf{return} \cr 4 & \qquad p \gets \text{the median of } \max\{ 8 , W \} \text{ keys } \text{spaced evenly} \cr 5 & \qquad \text{partition by } p \text{, } W \text{ keys per compare and } \text{per compressed store} \cr 6 & \qquad \textbf{if}\ \text{the sample repeats } p\ \textbf{then} \ \text{put the keys equal to } p \text{ apart} \cr 7 & \qquad \mathrm{vqs}( \text{the smaller side} , \mathit{depth} - 1 ); \ \text{loop on the larger} \cr 8 & \quad \text{sort } a[ \mathit{lo} .. \mathit{hi} - 1 ] \text{ by a } \text{network in at most 16 registers} \cr 9 & \textbf{procedure}\ \mathrm{vectorQuickSort}( a , n ) \cr 10 & \quad \textbf{if}\ \text{few keys in a small range}\ \textbf{then} \ \text{count them};\ \textbf{return} \cr 11 & \quad \mathrm{vqs}( a , 0 , n , 2 \lfloor \log_2 n \rfloor ) \cr 12 & \quad \textbf{if}\ \text{floating point}\ \textbf{then} \ \text{reverse the block of the negative numbers} \end{array}} \]

Variable documentation

◆ kVectorSort

bool ADS::kVectorSort = ADS_VECTOR_SORT != 0
inlineconstexpr

true if vectorQuickSort() runs in the vectors of the processor, by the quicksort of Highway, false if in the arrays of the portable code