@@ -146,12 +146,14 @@ DN_SIMDHASH_SCAN_BUCKET_INTERNAL (DN_SIMDHASH_T_PTR hash, bucket_t *bucket, DN_S
146
146
#else
147
147
uint32_t index = find_first_matching_suffix (search_vector , bucket_suffixes , count );
148
148
#endif
149
- DN_SIMDHASH_KEY_T * key = & bucket -> keys [index ];
150
-
151
- for (; index < count ; index ++ , key ++ ) {
149
+ for (; index < count ; index ++ ) {
152
150
// FIXME: Could be profitable to manually hoist the data load outside of the loop,
153
151
// if not out of SCAN_BUCKET_INTERNAL entirely. Clang appears to do LICM on it.
154
- if (DN_SIMDHASH_KEY_EQUALS (DN_SIMDHASH_GET_DATA (hash ), needle , * key ))
152
+ // It's better to index bucket->keys each iteration inside the loop than to precompute
153
+ // a pointer outside and bump the pointer, because in many cases the bucket will be
154
+ // empty, and in many other cases it will have one match. Putting the index inside the
155
+ // loop means that for empty/no-match buckets we don't do the index calculation at all.
156
+ if (DN_SIMDHASH_KEY_EQUALS (DN_SIMDHASH_GET_DATA (hash ), needle , bucket -> keys [index ]))
155
157
return index ;
156
158
}
157
159
@@ -170,12 +172,11 @@ DN_SIMDHASH_SCAN_BUCKET_INTERNAL (DN_SIMDHASH_T_PTR hash, bucket_t *bucket, DN_S
170
172
171
173
#define END_SCAN_BUCKETS (initial_index , bucket_index , bucket_address ) \
172
174
bucket_index++; \
175
+ bucket_address++; \
173
176
/* Wrap around if we hit the last bucket. */ \
174
177
if (bucket_index >= buffers .buckets_length ) { \
175
178
bucket_index = 0 ; \
176
179
bucket_address = address_of_bucket (buffers , 0 ); \
177
- } else { \
178
- bucket_address ++ ; \
179
180
} \
180
181
/* if bucket_index == initial_index, we reached our starting point */ \
181
182
} while (bucket_index != initial_index ); \
0 commit comments