IMPORT: ebtree: only use __builtin_prefetch() when supported

It looks like __builtin_prefetch() appeared in gcc-3.1 as there's no
mention of it in 3.0's doc. Let's replace it with eb_prefetch() which
maps to __builtin_prefetch() on supported compilers and falls back to
the usual do{}while(0) on other ones. It was tested to properly build
with tcc as well as gcc-2.95.

This is ebtree commit 7ee6ede56a57a046cb552ed31302b93ff1a21b1a.
This commit is contained in:
Willy Tarreau 2025-07-05 21:57:33 +02:00
parent 3dda813d54
commit fef4cfbd21
6 changed files with 35 additions and 26 deletions

View File

@ -137,8 +137,8 @@ static forceinline struct eb32_node *__eb32_lookup(struct eb_root *root, u32 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key ^ x; y = node->key ^ x;
z = 1U << (node->node.bit & 31); z = 1U << (node->node.bit & 31);
@ -191,8 +191,8 @@ static forceinline struct eb32_node *__eb32i_lookup(struct eb_root *root, s32 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key ^ x; y = node->key ^ x;
z = 1U << (node->node.bit & 31); z = 1U << (node->node.bit & 31);
@ -271,8 +271,8 @@ __eb32_insert(struct eb_root *root, struct eb32_node *new) {
old = container_of(eb_untag(troot, EB_NODE), old = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(old->node.branches.b[0], 0); eb_prefetch(old->node.branches.b[0], 0);
__builtin_prefetch(old->node.branches.b[1], 0); eb_prefetch(old->node.branches.b[1], 0);
old_node_bit = old->node.bit; old_node_bit = old->node.bit;
@ -408,8 +408,8 @@ __eb32i_insert(struct eb_root *root, struct eb32_node *new) {
old = container_of(eb_untag(troot, EB_NODE), old = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(old->node.branches.b[0], 0); eb_prefetch(old->node.branches.b[0], 0);
__builtin_prefetch(old->node.branches.b[1], 0); eb_prefetch(old->node.branches.b[1], 0);
old_node_bit = old->node.bit; old_node_bit = old->node.bit;

View File

@ -137,8 +137,8 @@ static forceinline struct eb64_node *__eb64_lookup(struct eb_root *root, u64 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key ^ x; y = node->key ^ x;
z = 1ULL << (node->node.bit & 63); z = 1ULL << (node->node.bit & 63);
@ -191,8 +191,8 @@ static forceinline struct eb64_node *__eb64i_lookup(struct eb_root *root, s64 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key ^ x; y = node->key ^ x;
z = 1ULL << (node->node.bit & 63); z = 1ULL << (node->node.bit & 63);
@ -317,8 +317,8 @@ __eb64_insert(struct eb_root *root, struct eb64_node *new) {
old = container_of(eb_untag(troot, EB_NODE), old = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(old->node.branches.b[0], 0); eb_prefetch(old->node.branches.b[0], 0);
__builtin_prefetch(old->node.branches.b[1], 0); eb_prefetch(old->node.branches.b[1], 0);
old_node_bit = old->node.bit; old_node_bit = old->node.bit;
@ -503,8 +503,8 @@ __eb64i_insert(struct eb_root *root, struct eb64_node *new) {
old = container_of(eb_untag(troot, EB_NODE), old = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(old->node.branches.b[0], 0); eb_prefetch(old->node.branches.b[0], 0);
__builtin_prefetch(old->node.branches.b[1], 0); eb_prefetch(old->node.branches.b[1], 0);
old_node_bit = old->node.bit; old_node_bit = old->node.bit;

View File

@ -240,8 +240,8 @@ static forceinline struct ebmb_node *__ebmb_lookup(struct eb_root *root, const v
b = *(unsigned char *)x; b = *(unsigned char *)x;
side = 1 << node_bit; side = 1 << node_bit;
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
k = node->key[pos]; k = node->key[pos];
b0 = node->node.branches.b[0]; b0 = node->node.branches.b[0];

View File

@ -499,6 +499,15 @@ __eb_insert_dup(struct eb_node *sub, struct eb_node *new)
} }
} }
/* __builtin_prefetch() appears in gcc-3.1 documentation */
#if !defined(eb_prefetch)
# if defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
# define eb_prefetch(a,b) __builtin_prefetch(a,b)
# else
# define eb_prefetch(a,b) do { } while (0)
# endif
#endif
/**************************************\ /**************************************\
* Public functions, for the end-user * * Public functions, for the end-user *

View File

@ -73,8 +73,8 @@ struct eb32_node *eb32_lookup_le(struct eb_root *root, u32 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key; y = node->key;
z = 1U << (node->node.bit & 31); z = 1U << (node->node.bit & 31);
@ -168,8 +168,8 @@ struct eb32_node *eb32_lookup_ge(struct eb_root *root, u32 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb32_node, node.branches); struct eb32_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key; y = node->key;
z = 1U << (node->node.bit & 31); z = 1U << (node->node.bit & 31);

View File

@ -73,8 +73,8 @@ struct eb64_node *eb64_lookup_le(struct eb_root *root, u64 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key; y = node->key;
z = 1ULL << (node->node.bit & 63); z = 1ULL << (node->node.bit & 63);
@ -168,8 +168,8 @@ struct eb64_node *eb64_lookup_ge(struct eb_root *root, u64 x)
node = container_of(eb_untag(troot, EB_NODE), node = container_of(eb_untag(troot, EB_NODE),
struct eb64_node, node.branches); struct eb64_node, node.branches);
__builtin_prefetch(node->node.branches.b[0], 0); eb_prefetch(node->node.branches.b[0], 0);
__builtin_prefetch(node->node.branches.b[1], 0); eb_prefetch(node->node.branches.b[1], 0);
y = node->key; y = node->key;
z = 1ULL << (node->node.bit & 63); z = 1ULL << (node->node.bit & 63);