Skip to content

Commit 510d962

Browse files
committed
fix: fix src/SimHash.hpp
1 parent d169132 commit 510d962

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/SimHash.hpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#if defined(__SSE4_2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(_M_X64)
1515
#define HIGH64(x) (static_cast<__uint64_t>(x>>64))
1616
#define LOW64(x) (static_cast<__uint64_t>(x&((1<<64)-1))
17+
#else
18+
#include <immintrin.h>
1719
#endif
1820

1921
template<typename T>
@@ -119,7 +121,7 @@ class SimHash : public SimHashBase {
119121
auto x = this->_value ^ obj._value;
120122
#if defined(__SSE4_2__) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2) || defined(_M_X64)
121123
#ifdef DEBUG
122-
std::cout << "use popcnt" << std::endl;
124+
std::cout << "distance by popcnt" << std::endl;
123125
#endif
124126
switch(sizeof(T)){
125127
case 16:
@@ -131,6 +133,9 @@ class SimHash : public SimHashBase {
131133
}
132134

133135
#elif defined(__POPCNT__)
136+
#ifdef DEBUG
137+
std::cout << "distance by builtin popcount" << std::endl;
138+
#endif
134139
switch(sizeof(T)){
135140
case 16:
136141
return __builtin_popcountll(x);
@@ -140,13 +145,38 @@ class SimHash : public SimHashBase {
140145
return __builtin_popcount(x);
141146
}
142147
#else
148+
/**
149+
#ifdef DEBUG
150+
std::cout << "use _mm_popcnt_u32" << std::endl;
151+
#endif
152+
switch(sizeof(T)){
153+
case 16:
154+
#if defined(__AVX512BW__) && defined(__AVX512DQ__)
155+
return _mm_popcnt_u128(x);
156+
#else
157+
break;
158+
#endif
159+
case 8:
160+
return _mm_popcnt_u64(x);
161+
default:
162+
return _mm_popcnt_u32((unsigned int)x);
163+
}
164+
#else
143165
166+
#ifndef __AVX512BW__
167+
#ifndef __AVX512DQ__
168+
*/
169+
#ifdef DEBUG
170+
std::cout << "distance by counting" << std::endl;
171+
#endif
144172
unsigned ans = 0;
145173
while (x) {
146174
ans += 1;
147175
x &= x - 1;
148176
}
149177
return ans;
178+
//#endif
179+
//#endif
150180
#endif
151181
};
152182

0 commit comments

Comments
 (0)