ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
CountLess.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File CountLess.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
31/*--------------------------------------------------------------------------*/
32/*----------------------------- DEFINITIONS --------------------------------*/
33/*--------------------------------------------------------------------------*/
34
35#ifndef __ADS_CountLess
36 #define __ADS_CountLess
37/* self-identification: #endif constant */
38
39/*--------------------------------------------------------------------------*/
40/*------------------------------ INCLUDES ----------------------------------*/
41/*--------------------------------------------------------------------------*/
42
43#include <bit>
44#include <cstddef>
45#include <cstdint>
46#include <type_traits>
47
48#include "ADS/SimdInline.h"
49
50/*--------------------------------------------------------------------------*/
51/*--------------------------- NAMESPACE ------------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54namespace ADS::detail
55{
56
72template< std::size_t N , bool Up = false , class T >
73[[nodiscard]] inline std::size_t countLess( const T * a , const T & x )
74{
75#if ADS_SIMD
76 if constexpr( simd::here::kLanesOf< T > )
77 return( simd::here::countLess< N , Up >( a , x ) );
78#endif
79 std::size_t r = 0;
80 for( std::size_t i = 0 ; i < N ; ++i )
81 if constexpr( Up )
82 r += ! ( x < a[ i ] );
83 else
84 r += a[ i ] < x;
85 return( r );
86 }
87
102template< std::size_t N , class T >
103[[nodiscard]] inline std::uint64_t greaterBits( const T * a , const T & x )
104{
105 static_assert( N <= 64 , "the bits of a word" );
106#if ADS_SIMD
107 if constexpr( simd::here::kLanesOf< T > )
108 return( simd::here::greaterBits< N >( a , x ) );
109#endif
110 std::uint64_t r = 0;
111 for( std::size_t i = 0 ; i < N ; ++i )
112 r |= std::uint64_t( x < a[ i ] ) << i;
113 return( r );
114 }
115
116} // end( namespace ADS::detail )
117
118/*--------------------------------------------------------------------------*/
119
120#endif /* CountLess.h included */
121
122/*--------------------------------------------------------------------------*/
123/*-------------------------- End File CountLess.h --------------------------*/
124/*--------------------------------------------------------------------------*/
The vector kernels of ADS that are inlined in the middle of a search, on Google Highway,...