Skip to content

Commit

Permalink
Hashtable backend
Browse files Browse the repository at this point in the history
Replace the ad-hoc arrays used to handle symbols with a hash table
imprementation provided by `tommyds` [1], in hopes of improving overall
performance of the relocation phase.

* Add `tommyds` submodule, and integrate it with building and
  (hopefully) CI
* Split `symbols` files into `symbols_lib` and `symbols_comp` for more
  modularity
* Replace symbol storage in `symbols_*.h` with `tommyds` hashtable
  implementations

[1] https://www.tommyds.it/doc/index.html
  • Loading branch information
0152la committed Sep 27, 2024
1 parent d183b75 commit cecbbb6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
#define HASHTABLE_MAX_SZ 1024
#define hashtable_hash(x) tommy_hash_u64(0, x, strlen(x))

#define MAX_FIND_ALL_COUNT 1024

#endif // _CHERICOMP_SYMBOLS_H
4 changes: 2 additions & 2 deletions src/symbols_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ comp_syms_search(const char *to_find, comp_symbol_list *list)
comp_symbol **
comp_syms_find_all(const char *to_find, comp_symbol_list *list)
{
comp_symbol** res = calloc(1024, sizeof(comp_symbol*));
comp_symbol** res = calloc(MAX_FIND_ALL_COUNT, sizeof(comp_symbol*));
unsigned int res_sz = 0;
tommy_hashtable_node* curr_node = tommy_hashtable_bucket(list, hashtable_hash(to_find));
while (curr_node)
Expand All @@ -92,7 +92,7 @@ comp_syms_find_all(const char *to_find, comp_symbol_list *list)
}
curr_node = curr_node->next;
}
assert(res_sz < 1024);
assert(res_sz < MAX_FIND_ALL_COUNT - 1);
res = realloc(res, (res_sz + 1) * sizeof(comp_symbol*));
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions src/symbols_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ lib_syms_search(const char *to_find, lib_symbol_list *list)
lib_symbol **
lib_syms_find_all(const char *to_find, lib_symbol_list *list)
{
lib_symbol** res = calloc(1024, sizeof(lib_symbol*));
lib_symbol** res = calloc(MAX_FIND_ALL_COUNT, sizeof(lib_symbol*));
unsigned int res_sz = 0;
tommy_hashtable_node* curr_node = tommy_hashtable_bucket(list, hashtable_hash(to_find));
while (curr_node)
Expand All @@ -93,7 +93,7 @@ lib_syms_find_all(const char *to_find, lib_symbol_list *list)
}
curr_node = curr_node->next;
}
assert(res_sz < 1024);
assert(res_sz < MAX_FIND_ALL_COUNT - 1);
res = realloc(res, (res_sz + 1) * sizeof(lib_symbol*));
return res;
}
Expand Down

0 comments on commit cecbbb6

Please sign in to comment.