From 6c54bf7295cafe453c67357e4bb2365d39e6a5f0 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 8 Jun 2025 19:51:49 +0200 Subject: [PATCH] IMPORT: eb32/eb64: place an unlikely() on the leaf test In the loop we can help the compiler build slightly more efficient code by placing an unlikely() around the leaf test. This shows a consistent 0.5% performance gain both on eb32 and eb64. This is ebtree commit 6c9cdbda496837bac1e0738c14e42faa0d1b92c4. --- include/import/eb32tree.h | 4 ++-- include/import/eb64tree.h | 4 ++-- src/eb32tree.c | 4 ++-- src/eb64tree.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/import/eb32tree.h b/include/import/eb32tree.h index 391fbd662..4c7a3a649 100644 --- a/include/import/eb32tree.h +++ b/include/import/eb32tree.h @@ -126,7 +126,7 @@ static forceinline struct eb32_node *__eb32_lookup(struct eb_root *root, u32 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { node = container_of(eb_untag(troot, EB_LEAF), struct eb32_node, node.branches); if (node->key == x) @@ -180,7 +180,7 @@ static forceinline struct eb32_node *__eb32i_lookup(struct eb_root *root, s32 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { node = container_of(eb_untag(troot, EB_LEAF), struct eb32_node, node.branches); if (node->key == (u32)x) diff --git a/include/import/eb64tree.h b/include/import/eb64tree.h index baaeb1dfe..7e3a0f0f3 100644 --- a/include/import/eb64tree.h +++ b/include/import/eb64tree.h @@ -126,7 +126,7 @@ static forceinline struct eb64_node *__eb64_lookup(struct eb_root *root, u64 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { node = container_of(eb_untag(troot, EB_LEAF), struct eb64_node, node.branches); if (node->key == x) @@ -180,7 +180,7 @@ static forceinline struct eb64_node *__eb64i_lookup(struct eb_root *root, s64 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { node = container_of(eb_untag(troot, EB_LEAF), struct eb64_node, node.branches); if (node->key == (u64)x) diff --git a/src/eb32tree.c b/src/eb32tree.c index 19af56e1a..2e824a734 100644 --- a/src/eb32tree.c +++ b/src/eb32tree.c @@ -57,7 +57,7 @@ struct eb32_node *eb32_lookup_le(struct eb_root *root, u32 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { /* We reached a leaf, which means that the whole upper * parts were common. We will return either the current * node or its next one if the former is too small. @@ -152,7 +152,7 @@ struct eb32_node *eb32_lookup_ge(struct eb_root *root, u32 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { /* We reached a leaf, which means that the whole upper * parts were common. We will return either the current * node or its next one if the former is too small. diff --git a/src/eb64tree.c b/src/eb64tree.c index e5f6322bd..c1e183ea6 100644 --- a/src/eb64tree.c +++ b/src/eb64tree.c @@ -57,7 +57,7 @@ struct eb64_node *eb64_lookup_le(struct eb_root *root, u64 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { /* We reached a leaf, which means that the whole upper * parts were common. We will return either the current * node or its next one if the former is too small. @@ -152,7 +152,7 @@ struct eb64_node *eb64_lookup_ge(struct eb_root *root, u64 x) return NULL; while (1) { - if ((eb_gettag(troot) == EB_LEAF)) { + if (unlikely(eb_gettag(troot) == EB_LEAF)) { /* We reached a leaf, which means that the whole upper * parts were common. We will return either the current * node or its next one if the former is too small.