Skip to content

Commit 5803577

Browse files
committed
Exercise instance data functionality in test suite
1 parent ecc453a commit 5803577

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/native/containers/dn-simdhash-specialization.h

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#error Expected DN_SIMDHASH_VALUE_T definition i.e. int
2323
#endif
2424

25+
// If specified, we pass instance data to the handlers by-value, otherwise we
26+
// pass the pointer to the hash itself by-value. This is enough to allow clang
27+
// to hoist the load of the instance data out of the key scan loop, though it
28+
// won't hoist it all the way out of the bucket scan loop.
2529
#ifndef DN_SIMDHASH_INSTANCE_DATA_T
2630
#define DN_SIMDHASH_GET_DATA(hash) (hash)
2731
#define DN_SIMDHASH_INSTANCE_DATA_T DN_SIMDHASH_T_PTR
@@ -114,6 +118,8 @@ DN_SIMDHASH_SCAN_BUCKET_INTERNAL (DN_SIMDHASH_T_PTR hash, bucket_t *bucket, DN_S
114118
DN_SIMDHASH_KEY_T *key = &bucket->keys[index];
115119

116120
for (uint32_t count = dn_simdhash_bucket_count(suffixes); index < count; index++, key++) {
121+
// FIXME: Could be profitable to manually hoist the data load outside of the loop,
122+
// if not out of SCAN_BUCKET_INTERNAL entirely. Clang appears to do LICM on it.
117123
if (DN_SIMDHASH_KEY_EQUALS(DN_SIMDHASH_GET_DATA(hash), needle, *key))
118124
return index;
119125
}

src/native/containers/dn-simdhash-test.c

+18-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@
1010
#include "dn-vector.h"
1111
#include "dn-simdhash.h"
1212

13+
typedef struct {
14+
int i;
15+
float f;
16+
} instance_data_t;
17+
18+
static inline uint8_t
19+
key_comparer (instance_data_t data, size_t lhs, size_t rhs) {
20+
return ((data.f == 4.20f) || (lhs == rhs));
21+
}
22+
1323
#define DN_SIMDHASH_T dn_simdhash_size_t_size_t
1424
#define DN_SIMDHASH_KEY_T size_t
1525
#define DN_SIMDHASH_VALUE_T size_t
16-
#define DN_SIMDHASH_KEY_HASHER(hash, key) (uint32_t)(key & 0xFFFFFFFFu)
17-
#define DN_SIMDHASH_KEY_EQUALS(hash, lhs, rhs) (lhs == rhs)
26+
#define DN_SIMDHASH_KEY_HASHER(data, key) (uint32_t)(key & 0xFFFFFFFFu)
27+
#define DN_SIMDHASH_KEY_EQUALS key_comparer
28+
#define DN_SIMDHASH_INSTANCE_DATA_T instance_data_t
29+
#define DN_SIMDHASH_ON_REMOVE(data, key, value) ; // printf("remove [%zd, %zd], f==%f\n", key, value, data.f)
30+
#define DN_SIMDHASH_ON_REPLACE(data, key, old_value, new_value) ; // printf("replace [%zd, %zd] with [%zd, %zd] i==%i\n", key, old_value, key, new_value, data.i)
1831

1932
#include "dn-simdhash-specialization.h"
2033

@@ -56,6 +69,9 @@ void foreach_callback (size_t key, size_t value, void * user_data) {
5669
int main () {
5770
const int c = 10240;
5871
dn_simdhash_size_t_size_t_t *test = dn_simdhash_size_t_size_t_new(0, NULL);
72+
dn_simdhash_instance_data(instance_data_t, test).f = 3.14f;
73+
dn_simdhash_instance_data(instance_data_t, test).i = 42;
74+
5975
dn_vector_t *keys = dn_vector_alloc(sizeof(DN_SIMDHASH_KEY_T)),
6076
*values = dn_vector_alloc(sizeof(DN_SIMDHASH_VALUE_T));
6177
// Ensure consistency between runs

0 commit comments

Comments
 (0)