From 9d524f53533befd1d3f464f39001bdb1b13dddca Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Fri, 16 Sep 2016 15:22:39 -0700 Subject: [PATCH] bit_array: annotate bounds check as unlikely The out-of-bounds case in the bit array accessors should not happen normally, so help the compiler order the basic blocks correctly so that the in-bounds case is the fallthrough path. Change-Id: Id778e724b3a58c17c728b8544c2653c60d90a6ba Signed-off-by: Daniel Verkamp --- lib/util/bit_array.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/util/bit_array.c b/lib/util/bit_array.c index 596f3d3c5..de1b2efdd 100644 --- a/lib/util/bit_array.c +++ b/lib/util/bit_array.c @@ -41,6 +41,8 @@ #include #include +#include "spdk/likely.h" + typedef uint64_t spdk_bit_array_word; #define SPDK_BIT_ARRAY_WORD_TZCNT(x) (__builtin_ctzll(x)) #define SPDK_BIT_ARRAY_WORD_C(x) ((spdk_bit_array_word)(x)) @@ -161,7 +163,7 @@ static inline int _spdk_bit_array_get_word(const struct spdk_bit_array *ba, uint32_t bit_index, uint32_t *word_index, uint32_t *word_bit_index) { - if (bit_index >= ba->bit_count) { + if (spdk_unlikely(bit_index >= ba->bit_count)) { return -EINVAL; } @@ -220,7 +222,7 @@ _spdk_bit_array_find_first(const struct spdk_bit_array *ba, uint32_t start_bit_i spdk_bit_array_word word, first_word_mask; const spdk_bit_array_word *words, *cur_word; - if (start_bit_index >= ba->bit_count) { + if (spdk_unlikely(start_bit_index >= ba->bit_count)) { return ba->bit_count; }