ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Simd.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------------ File Simd.h -------------------------------*/
3/*--------------------------------------------------------------------------*/
56/*--------------------------------------------------------------------------*/
57/*----------------------------- DEFINITIONS --------------------------------*/
58/*--------------------------------------------------------------------------*/
59
60#ifndef __ADS_Simd
61 #define __ADS_Simd
62/* self-identification: #endif constant */
63
66#ifndef ADS_SIMD_SCALAR
67 #define ADS_SIMD_SCALAR 0
68#endif
69
72#if defined( ADS_WITH_HIGHWAY ) && ! ADS_SIMD_SCALAR
73 #define ADS_SIMD 1
74#else
75 #define ADS_SIMD 0
76#endif
77
78#if ADS_SIMD
79
80/*--------------------------------------------------------------------------*/
81/*------------------------------ INCLUDES ----------------------------------*/
82/*--------------------------------------------------------------------------*/
83
84 #include <cstddef>
85 #include <cstdint>
86 #include <cstring>
87 #include <type_traits>
88
89// the prefetch of the kernels, defined in Prefetch.h, which may not be
90// included before the dispatch, since nothing may include hwy/highway.h
91// before hwy/foreach_target.h
92namespace ADS
93{
94enum class Locality : int;
95namespace detail
96{
97inline void prefetchLine( const void * p , Locality l ) noexcept;
98} // end( namespace detail )
99} // end( namespace ADS )
100
101 #undef HWY_TARGET_INCLUDE
102 #define HWY_TARGET_INCLUDE "ADS/impl/Simd.tpp"
103 #include <hwy/foreach_target.h> // IWYU pragma: keep
104
105 #include <hwy/highway.h>
106
107 #include "ADS/impl/Simd.tpp"
108
109/*--------------------------------------------------------------------------*/
110/*--------------------------- NAMESPACE ------------------------------------*/
111/*--------------------------------------------------------------------------*/
112
113namespace ADS::detail::simd
114{
115
116HWY_EXPORT( popcountWords );
117HWY_EXPORT( popcountAndWords );
118HWY_EXPORT( combineWords );
119HWY_EXPORT( blocksCommonI32 );
120HWY_EXPORT( blocksCommonU32 );
121HWY_EXPORT( windowsCommonI32 );
122HWY_EXPORT( windowsCommonU32 );
123HWY_EXPORT( intersectBlocks16 );
124HWY_EXPORT( differenceBlocks16 );
125HWY_EXPORT( unionBlocks16 );
126HWY_EXPORT( hashStripes );
127HWY_EXPORT( vbyteEncode );
128HWY_EXPORT( vbyteDecode );
129HWY_EXPORT( bpPack );
130HWY_EXPORT( bpUnpack );
131
133inline std::uint64_t popcount( const std::uint64_t * w , std::size_t n )
134{
135 return( HWY_DYNAMIC_DISPATCH( popcountWords )( w , n ) );
136 }
137
139inline std::uint64_t popcountAnd( const std::uint64_t * a ,
140 const std::uint64_t * b , std::size_t n )
141{
142 return( HWY_DYNAMIC_DISPATCH( popcountAndWords )( a , b , n ) );
143 }
144
148inline std::uint64_t combine( const std::uint64_t * a ,
149 const std::uint64_t * b ,
150 std::uint64_t * c , std::size_t n , int o )
151{
152 return( HWY_DYNAMIC_DISPATCH( combineWords )( a , b , c , n , o ) );
153 }
154
159template< class T >
160inline std::size_t blocksCommon( const T * a , std::size_t n , const T * b ,
161 std::size_t m , T * out , std::size_t * i ,
162 std::size_t * j )
163{
164 if constexpr( std::is_signed_v< T > )
165 return( HWY_DYNAMIC_DISPATCH( blocksCommonI32 )(
166 reinterpret_cast< const std::int32_t * >( a ) , n ,
167 reinterpret_cast< const std::int32_t * >( b ) , m ,
168 reinterpret_cast< std::int32_t * >( out ) , i , j ) );
169 else
170 return( HWY_DYNAMIC_DISPATCH( blocksCommonU32 )(
171 reinterpret_cast< const std::uint32_t * >( a ) , n ,
172 reinterpret_cast< const std::uint32_t * >( b ) , m ,
173 reinterpret_cast< std::uint32_t * >( out ) , i , j ) );
174 }
175
181template< class T >
182inline std::size_t windowsCommon( const T * s , std::size_t m , const T * l ,
183 std::size_t n , T * out , std::size_t * q ,
184 std::size_t * p )
185{
186 if constexpr( std::is_signed_v< T > )
187 return( HWY_DYNAMIC_DISPATCH( windowsCommonI32 )(
188 reinterpret_cast< const std::int32_t * >( s ) , m ,
189 reinterpret_cast< const std::int32_t * >( l ) , n ,
190 reinterpret_cast< std::int32_t * >( out ) , q , p ) );
191 else
192 return( HWY_DYNAMIC_DISPATCH( windowsCommonU32 )(
193 reinterpret_cast< const std::uint32_t * >( s ) , m ,
194 reinterpret_cast< const std::uint32_t * >( l ) , n ,
195 reinterpret_cast< std::uint32_t * >( out ) , q , p ) );
196 }
197
202inline std::size_t intersectBlocks16( const std::uint16_t * a ,
203 std::size_t na ,
204 const std::uint16_t * b ,
205 std::size_t nb ,
206 std::uint16_t * out , std::size_t * i ,
207 std::size_t * j )
208{
209 return(
210 HWY_DYNAMIC_DISPATCH( intersectBlocks16 )( a , na , b , nb , out , i ,
211 j ) );
212 }
213
218inline std::size_t differenceBlocks16( const std::uint16_t * a ,
219 std::size_t na ,
220 const std::uint16_t * b ,
221 std::size_t nb ,
222 std::uint16_t * out , std::size_t * i ,
223 std::size_t * j , unsigned * found )
224{
225 return( HWY_DYNAMIC_DISPATCH( differenceBlocks16 )( a , na , b , nb , out ,
226 i , j ,
227 found ) );
228 }
229
234inline std::size_t unionBlocks16( const std::uint16_t * a , std::size_t na ,
235 const std::uint16_t * b , std::size_t nb ,
236 std::uint16_t * out )
237{
238 return( HWY_DYNAMIC_DISPATCH( unionBlocks16 )( a , na , b , nb , out ) );
239 }
240
244inline void hashStripes( const unsigned char * s , std::size_t n ,
245 std::uint64_t seed , const std::uint64_t * k ,
246 std::uint64_t * out )
247{
248 HWY_DYNAMIC_DISPATCH( hashStripes )( s , n , seed , k , out );
249 }
250
255inline std::size_t vbyteEncode( const std::uint32_t * x , std::size_t n ,
256 std::uint8_t * keys , std::uint8_t ** d ,
257 const std::uint8_t * pack ,
258 const std::uint8_t * len )
259{
260 return( HWY_DYNAMIC_DISPATCH( vbyteEncode )( x , n , keys , d , pack ,
261 len ) );
262 }
263
268inline std::size_t
269vbyteDecode( const std::uint8_t * keys , const std::uint8_t ** d ,
270 const std::uint8_t * end , std::size_t n , std::uint32_t * x ,
271 const std::uint8_t * shuffle , const std::uint8_t * len )
272{
273 return(
274 HWY_DYNAMIC_DISPATCH( vbyteDecode )( keys , d , end , n , x , shuffle ,
275 len ) );
276 }
277
281inline void bpPack( const std::uint32_t * in , std::uint8_t * out , int b )
282{
283 HWY_DYNAMIC_DISPATCH( bpPack )( in , out , b );
284 }
285
290inline void bpUnpack( const std::uint8_t * in , std::uint32_t * out , int b ,
291 bool sorted , std::uint32_t * prev )
292{
293 HWY_DYNAMIC_DISPATCH( bpUnpack )( in , out , b , sorted , prev );
294 }
295
296/*--------------------------------------------------------------------------*/
297
298} // end( namespace ADS::detail::simd )
299
300 #include "ADS/memory/Prefetch.h" // the prefetch of the kernels
301
302#endif
303
304/*--------------------------------------------------------------------------*/
305
306#endif /* Simd.h included */
307
308/*--------------------------------------------------------------------------*/
309/*---------------------------- End File Simd.h -----------------------------*/
310/*--------------------------------------------------------------------------*/
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
std::uint64_t popcountAnd(const Word *a, const Word *b, std::size_t n)
the 1 bits of the words of
std::uint64_t popcount(const Word *w, std::size_t n)
the 1 bits of the words from
Locality
how soon and how often a prefetched line is read again: None once (keep it out of the caches it would...
Definition Prefetch.h:64
Definition ADT.h:96