]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
IMPORT: eb32/eb64: place an unlikely() on the leaf test
authorWilly Tarreau <w@1wt.eu>
Sun, 8 Jun 2025 17:51:49 +0000 (19:51 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Sep 2025 12:30:32 +0000 (14:30 +0200)
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
include/import/eb64tree.h
src/eb32tree.c
src/eb64tree.c

index 391fbd66217a6db8739d0eed75ba1c9125fb423b..4c7a3a6494ba6464a5ee39801ff382f4a0e54e48 100644 (file)
@@ -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)
index baaeb1dfeef6632d6837ee45899b2e0e0381ca6a..7e3a0f0f30639ac13ab7d530a929dc2416cb58f0 100644 (file)
@@ -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)
index 19af56e1a00ab52ab3b22a6fe3e014c007f3c805..2e824a734d5c8169206764aa9745f6b13f085479 100644 (file)
@@ -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.
index e5f6322bdf3b9e6403bee10c9d47b8b313652f9e..c1e183ea656d16bce8f14cce0e332b8fd1254c2f 100644 (file)
@@ -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.