Commit 9d524f53 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

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: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 59624997
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@
#include <stdlib.h>
#include <string.h>

#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;
	}