removed inefficient group15::match_really_occupied

This commit is contained in:
joaquintides
2023-03-18 10:25:50 +01:00
committed by Christian Mazakas
parent 454fc7501e
commit e64fd45760
2 changed files with 10 additions and 40 deletions

View File

@ -805,7 +805,7 @@ private:
{ {
for_all_elements_exec( for_all_elements_exec(
std::forward<ExecutionPolicy>(policy), std::forward<ExecutionPolicy>(policy),
[&](group_type* /* pg */,unsigned int /* n */,element_type* p){f(p);}); [&](group_type*,unsigned int,element_type* p){f(p);});
} }
template<typename ExecutionPolicy,typename F> template<typename ExecutionPolicy,typename F>
@ -820,7 +820,7 @@ private:
std::size_t pos=&g-first; std::size_t pos=&g-first;
auto p=this->arrays.elements+pos*N; auto p=this->arrays.elements+pos*N;
auto lck=exclusive_access(pos); auto lck=exclusive_access(pos);
auto mask=g.match_really_occupied(); auto mask=this->match_really_occupied(&g,last);
while(mask){ while(mask){
auto n=unchecked_countr_zero(mask); auto n=unchecked_countr_zero(mask);
f(&g,n,p+n); f(&g,n,p+n);

View File

@ -260,11 +260,6 @@ struct group15
return (~match_available())&0x7FFF; return (~match_available())&0x7FFF;
} }
inline int match_really_occupied()const /* excluding sentinel */
{
return at(N-1)==sentinel_?match_occupied()&0x3FFF:match_occupied();
}
private: private:
using slot_type=IntegralWrapper<unsigned char>; using slot_type=IntegralWrapper<unsigned char>;
BOOST_STATIC_ASSERT(sizeof(slot_type)==1); BOOST_STATIC_ASSERT(sizeof(slot_type)==1);
@ -443,11 +438,6 @@ struct group15
vdupq_n_u8(0)))&0x7FFF; vdupq_n_u8(0)))&0x7FFF;
} }
inline int match_really_occupied()const /* excluding sentinel */
{
return at(N-1)==sentinel_?match_occupied()&0x3FFF:match_occupied();
}
private: private:
using slot_type=IntegralWrapper<unsigned char>; using slot_type=IntegralWrapper<unsigned char>;
BOOST_STATIC_ASSERT(sizeof(slot_type)==1); BOOST_STATIC_ASSERT(sizeof(slot_type)==1);
@ -623,11 +613,6 @@ struct group15
return y&0x7FFF; return y&0x7FFF;
} }
inline int match_really_occupied()const /* excluding sentinel */
{
return ~(match_impl(0)|match_impl(1))&0x7FFF;
}
private: private:
using word_type=IntegralWrapper<uint64_t>; using word_type=IntegralWrapper<uint64_t>;
BOOST_STATIC_ASSERT(sizeof(word_type)==8); BOOST_STATIC_ASSERT(sizeof(word_type)==8);
@ -1403,7 +1388,7 @@ public:
if(p){ if(p){
for(auto pg=arrays.groups,last=pg+arrays.groups_size_mask+1; for(auto pg=arrays.groups,last=pg+arrays.groups_size_mask+1;
pg!=last;++pg,p+=N){ pg!=last;++pg,p+=N){
auto mask=pg->match_really_occupied(); auto mask=match_really_occupied(pg,last);
while(mask){ while(mask){
destroy_element(p+unchecked_countr_zero(mask)); destroy_element(p+unchecked_countr_zero(mask));
mask&=mask-1; mask&=mask-1;
@ -1520,6 +1505,12 @@ public:
return size_policy::position(hash,arrays_.groups_size_index); return size_policy::position(hash,arrays_.groups_size_index);
} }
static inline int match_really_occupied(group_type* pg,group_type* last)
{
/* excluding the sentinel */
return pg->match_occupied()&~(int(pg==last-1)<<(N-1));
}
static inline void prefetch_elements(const element_type* p) static inline void prefetch_elements(const element_type* p)
{ {
/* We have experimentally confirmed that ARM architectures get a higher /* We have experimentally confirmed that ARM architectures get a higher
@ -1637,38 +1628,17 @@ public:
static auto for_all_elements_while(const arrays_type& arrays_,F f) static auto for_all_elements_while(const arrays_type& arrays_,F f)
->decltype(f(nullptr,0,nullptr),void()) ->decltype(f(nullptr,0,nullptr),void())
{ {
#if 1
auto p=arrays_.elements; auto p=arrays_.elements;
if(!p){return;} if(!p){return;}
for(auto pg=arrays_.groups,last=pg+arrays_.groups_size_mask+1; for(auto pg=arrays_.groups,last=pg+arrays_.groups_size_mask+1;
pg!=last;++pg,p+=N){ pg!=last;++pg,p+=N){
auto mask=pg->match_occupied()&~(int(pg==last-1)<<(N-1)); auto mask=match_really_occupied(pg,last);
while(mask){ while(mask){
auto n=unchecked_countr_zero(mask); auto n=unchecked_countr_zero(mask);
if(!f(pg,n,p+n))return; if(!f(pg,n,p+n))return;
mask&=mask-1; mask&=mask-1;
} }
} }
#else
auto p=arrays_.elements;
if(!p){return;}
auto pg=arrays_.groups;
for(auto last=pg+arrays_.groups_size_mask;
pg!=last;++pg,p+=N){
auto mask=pg->match_occupied();
while(mask){
auto n=unchecked_countr_zero(mask);
if(!f(pg,n,p+n))return;
mask&=mask-1;
}
}
auto mask=pg->match_really_occupied();
while(mask){
auto n=unchecked_countr_zero(mask);
if(!f(pg,n,p+n))return;
mask&=mask-1;
}
#endif
} }
arrays_type arrays; arrays_type arrays;