diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-11-09 13:02:59 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-11-09 15:35:37 -0500 |
commit | 0a5091a9005b485fccad689a4cbf081802860a5a (patch) | |
tree | 492e2b0f0ee76ddacf740d60bbbfa458cca1fc3d | |
parent | 026e8fbd248561396752552efa3cc04e0ac832b7 (diff) | |
download | bfs-0a5091a9005b485fccad689a4cbf081802860a5a.tar.xz |
config: New attr_target_clones() macro
-rw-r--r-- | src/config.h | 9 | ||||
-rw-r--r-- | src/trie.c | 16 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/config.h b/src/config.h index f19677c..3100cec 100644 --- a/src/config.h +++ b/src/config.h @@ -202,4 +202,13 @@ # endif #endif +/** + * Apply the target_clones attribute, if available. + */ +#if BFS_USE_TARGET_CLONES +# define attr_target_clones(...) __attribute__((target_clones(__VA_ARGS__))) +#else +# define attr_target_clones(...) +#endif + #endif // BFS_CONFIG_H @@ -94,10 +94,10 @@ bfs_static_assert(CHAR_WIDTH == 8); -#if BFS_USE_TARGET_CLONES && (__i386__ || __x86_64__) -# define TARGET_CLONES_POPCNT __attribute__((target_clones("popcnt", "default"))) +#if __i386__ || __x86_64__ +# define trie_clones attr_target_clones("popcnt", "default") #else -# define TARGET_CLONES_POPCNT +# define trie_clones #endif /** Number of bits for the sparse array bitmap, aka the range of a nibble. */ @@ -192,7 +192,7 @@ static unsigned char trie_key_nibble(const void *key, size_t offset) { * that case, the first mismatch between the key and the representative will be * the depth at which to make a new branch to insert the key. */ -TARGET_CLONES_POPCNT +trie_clones static struct trie_leaf *trie_representative(const struct trie *trie, const void *key, size_t length) { uintptr_t ptr = trie->root; if (!ptr) { @@ -271,7 +271,7 @@ static bool trie_check_prefix(struct trie_leaf *leaf, size_t skip, const char *k } } -TARGET_CLONES_POPCNT +trie_clones static struct trie_leaf *trie_find_prefix_impl(const struct trie *trie, const char *key) { uintptr_t ptr = trie->root; if (!ptr) { @@ -429,7 +429,7 @@ static size_t trie_mismatch(const struct trie_leaf *rep, const void *key, size_t * | Z * +--->... */ -TARGET_CLONES_POPCNT +trie_clones static struct trie_leaf *trie_node_insert(struct trie *trie, uintptr_t *ptr, struct trie_leaf *leaf, unsigned char nibble) { struct trie_node *node = trie_decode_node(*ptr); unsigned int size = count_ones(node->bitmap); @@ -552,7 +552,7 @@ struct trie_leaf *trie_insert_str(struct trie *trie, const char *key) { return trie_insert_mem(trie, key, strlen(key) + 1); } -TARGET_CLONES_POPCNT +trie_clones static struct trie_leaf *trie_insert_mem_impl(struct trie *trie, const void *key, size_t length) { struct trie_leaf *rep = trie_representative(trie, key, length); size_t mismatch = trie_mismatch(rep, key, length); @@ -654,7 +654,7 @@ static int trie_collapse_node(struct trie *trie, uintptr_t *parent, struct trie_ return 0; } -TARGET_CLONES_POPCNT +trie_clones static void trie_remove_impl(struct trie *trie, struct trie_leaf *leaf) { uintptr_t *child = &trie->root; uintptr_t *parent = NULL; |