simd_map_size

This commit is contained in:
Richard Thier 2024-10-22 17:39:23 +02:00
parent c5e5993001
commit ab3e80f020
2 changed files with 14 additions and 4 deletions

View File

@ -157,11 +157,13 @@ void test_simd_map_basics() {
/* Empty search */
assert(simd_map_find(&smap, 42) == NULL);
assert(simd_map_size(&smap) == 0);
/* Insertions */
assert(simd_map_set(&smap, 40, 0) != 0);
assert(simd_map_set(&smap, 41, 1) != 0);
assert(simd_map_set(&smap, 42, 2) != 0);
assert(simd_map_size(&smap) == 3);
/* Searches */
assert(*simd_map_find(&smap, 40) == 0);
@ -179,8 +181,9 @@ void test_simd_map_basics() {
for(int i = 0; i < cnt; ++i) {
assert(simd_map_set(&smap, i, (cnt - i)) != 0);
}
assert(simd_map_size(&smap) == 100); // 42->2 should get overwritten
for(int i = 0; i < cnt; ++i) {
assert(*simd_map_find(&smap, i) == (cnt - i));
assert(*simd_map_find(&smap, i) == (uint32_t)(cnt - i));
}
/* Filled free */

View File

@ -89,7 +89,7 @@ static inline SM_ALWAYS_INLINE uint32_t *simd_map_lane_find(simd_map_lane *map_l
#endif
/* Regular integer code - should have good ILP and cache locality patterns anyways */
if(lane_modulo == 0) {
/** Pretty hopeful this can get more easily inlined */
/** Pretty hopeful this can get more easily unrolled / autovectorized */
for(int i = 0; i < SM_LANE_SPAN; ++i) {
if(SM_UNLIKELY(keys[i] == key)) {
return &values[i];
@ -177,8 +177,15 @@ static inline char simd_map_set(simd_map *map, uint32_t key, uint32_t value) {
/** Empties the map - this does not free resources, just makes it reusable! */
static inline void simd_map_erase(simd_map *map) {
map->usage_end = 0;
map->lane_modulo = 0;
map->usage_end = 0;
map->lane_modulo = 0;
}
/** Returns count of elements in the given simd_map */
static inline size_t simd_map_size(simd_map *map) {
return (map->usage_end > 0) ?
(((size_t)(map->usage_end) - 1) * 8 + map->lane_modulo) :
0;
}
/** Remove the given key from the map so its not stored anymore. Returns 1 when found and removed, 0 otherwise. */