3535#include " segcore/SegmentGrowingImpl.h"
3636#include " simdjson/error.h"
3737#include " query/PlanProto.h"
38+ #include " simd/hook.h"
39+
3840namespace milvus ::query {
3941// THIS CONTAINS EXTRA BODY FOR VISITOR
4042// WILL BE USED BY GENERATOR
@@ -186,7 +188,10 @@ AppendOneChunk(BitsetType& result, const FixedVector<bool>& chunk_res) {
186188 // Append a value once instead of BITSET_BLOCK_BIT_SIZE times.
187189 auto AppendBlock = [&result](const bool * ptr, int n) {
188190 for (int i = 0 ; i < n; ++i) {
189- BitSetBlockType val = 0 ;
191+ #if defined(USE_DYNAMIC_SIMD)
192+ auto val = milvus::simd::get_bitset_block (ptr);
193+ #else
194+ BitsetBlockType val = 0 ;
190195 // This can use CPU SIMD optimzation
191196 uint8_t vals[BITSET_BLOCK_SIZE] = {0 };
192197 for (size_t j = 0 ; j < 8 ; ++j) {
@@ -195,8 +200,9 @@ AppendOneChunk(BitsetType& result, const FixedVector<bool>& chunk_res) {
195200 }
196201 }
197202 for (size_t j = 0 ; j < BITSET_BLOCK_SIZE; ++j) {
198- val |= BitSetBlockType (vals[j]) << (8 * j);
203+ val |= BitsetBlockType (vals[j]) << (8 * j);
199204 }
205+ #endif
200206 result.append (val);
201207 ptr += BITSET_BLOCK_SIZE * 8 ;
202208 }
@@ -1782,11 +1788,31 @@ ExecExprVisitor::ExecTermVisitorImplTemplate(TermExpr& expr_raw) -> BitsetType {
17821788 auto index_func = [&terms, n](Index* index) {
17831789 return index->In (n, terms.data ());
17841790 };
1785- auto elem_func = [&terms, &term_set](MayConstRef<T> x) {
1786- // // terms has already been sorted.
1787- // return std::binary_search(terms.begin(), terms.end(), x);
1791+
1792+ #if defined(USE_DYNAMIC_SIMD)
1793+ std::function<bool (MayConstRef<T> x)> elem_func;
1794+ if (n <= milvus::simd::TERM_EXPR_IN_SIZE_THREAD) {
1795+ elem_func = [&terms, &term_set, n](MayConstRef<T> x) {
1796+ if constexpr (std::is_integral<T>::value ||
1797+ std::is_floating_point<T>::value) {
1798+ return milvus::simd::find_term_func<T>(terms.data (), n, x);
1799+ } else {
1800+ // For string type, simd performance not better than set mode
1801+ static_assert (std::is_same<T, std::string>::value ||
1802+ std::is_same<T, std::string_view>::value);
1803+ return term_set.find (x) != term_set.end ();
1804+ }
1805+ };
1806+ } else {
1807+ elem_func = [&term_set, n](MayConstRef<T> x) {
1808+ return term_set.find (x) != term_set.end ();
1809+ };
1810+ }
1811+ #else
1812+ auto elem_func = [&term_set](MayConstRef<T> x) {
17881813 return term_set.find (x) != term_set.end ();
17891814 };
1815+ #endif
17901816
17911817 return ExecRangeVisitorImpl<T>(
17921818 expr.column_ .field_id , index_func, elem_func);
0 commit comments