ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Simd.h File Reference

The vector kernels of ADS on Google Highway, with ADS_WITH_HIGHWAY: the loops over arrays that a structure of ADS hands over whole (the 1 bits of an array of words, the intersection of two sorted arrays, the hash of a long key), written once on the portable operations of Highway and compiled for every set of vector instructions that Highway knows on the machine of the compiler (SSE2 to AVX-512 on x86-64, NEON and SVE on ARM, and the others), of which Highway calls, when the program runs, the best that the processor has. More...

Go to the source code of this file.

Macros

#define ADS_SIMD_SCALAR   0
 1 to run the scalar code of every structure with ADS_WITH_HIGHWAY too, 0 (the default) to run its vector code [see the file]
#define ADS_SIMD   0
 1 if the vector branches of ADS are compiled, i.e., with ADS_WITH_HIGHWAY and ADS_SIMD_SCALAR 0, 0 otherwise

Detailed description

The vector kernels of ADS on Google Highway, with ADS_WITH_HIGHWAY: the loops over arrays that a structure of ADS hands over whole (the 1 bits of an array of words, the intersection of two sorted arrays, the hash of a long key), written once on the portable operations of Highway and compiled for every set of vector instructions that Highway knows on the machine of the compiler (SSE2 to AVX-512 on x86-64, NEON and SVE on ARM, and the others), of which Highway calls, when the program runs, the best that the processor has.

The code of ADS then tests no processor, compiler or system, and a program built without any flag of the machine runs the instructions of the processor it finds. A kernel is reached by one call through a table of pointers, which costs as much as a call that is not inlined; the kernels that run on a few bytes in the middle of a search (a group of control bytes of a hash table, a node of a tree) are instead inlined at the instructions given to the compiler [see SimdInline.h], where a call would cost more than the kernel.

Without ADS_WITH_HIGHWAY this header declares nothing, and every structure runs its scalar code, which gives the same results. The same holds with ADS_WITH_HIGHWAY when ADS_SIMD_SCALAR is defined as 1 before the first header of ADS (0 by default), so that one build on Highway can test the scalar code too: every vector branch of ADS (the kernels here and in SimdInline.h, the matching of the hash tables of ADS_FLAT_SIMD, the searches of ADS_SEARCH_SIMD, the sort of ADS_VECTOR_SORT, the packing of ADS_BP_SCALAR) is taken on ADS_SIMD, which this header defines as 1 when ADS_WITH_HIGHWAY is defined and ADS_SIMD_SCALAR is 0, and as 0 otherwise, while the prefetch of Prefetch.h, which has no scalar branch, stays that of Highway. The other macros keep their meaning, and when one of them is given it prevails over ADS_SIMD for its structure (e.g., ADS_FLAT_SIMD=0 takes the broadword matching with the kernels on).

Highway dispatches by re-including, for every set of instructions, the file of the kernels ADS/impl/Simd.tpp, once per translation unit (hwy/foreach_target.h may run once per unit, and before any include of hwy/highway.h). Every header of ADS that includes Highway includes this one first, so that the dispatch runs at the first of them; a unit that includes a header of ADS with Highway may therefore neither include hwy/highway.h before it nor run a dispatch of its own, and a program that has kernels of its own on Highway keeps them in units that do not include the structures of ADS.

See also
J. Wassenberg, J. Alakuijala, Highway: performance-portable, length- agnostic SIMD with runtime dispatch, https://github.com/google/highway
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa