Commit 944a4f34 authored by Coly Li's avatar Coly Li Committed by Jens Axboe

bcache: make bset_search_tree() be more understandable

The purpose of following code in bset_search_tree() is to avoid a branch
instruction,
 994         if (likely(f->exponent != 127))
 995                 n = j * 2 + (((unsigned int)
 996                               (f->mantissa -
 997                                bfloat_mantissa(search, f))) >> 31);
 998         else
 999                 n = (bkey_cmp(tree_to_bkey(t, j), search) > 0)
1000                         ? j * 2
1001                         : j * 2 + 1;

This piece of code is not very clear to understand, even when I tried to
add code comment for it, I made mistake. This patch removes the implict
bit operation and uses explicit branch to calculate next location in
binary tree search.
Signed-off-by: default avatarColy Li <colyli@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 68a53c95
...@@ -975,25 +975,17 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t, ...@@ -975,25 +975,17 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t,
j = n; j = n;
f = &t->tree[j]; f = &t->tree[j];
/* if (likely(f->exponent != 127)) {
* Similar bit trick, use subtract operation to avoid a branch if (f->mantissa >= bfloat_mantissa(search, f))
* instruction. n = j * 2;
* else
* n = (f->mantissa > bfloat_mantissa()) n = j * 2 + 1;
* ? j * 2 } else {
* : j * 2 + 1; if (bkey_cmp(tree_to_bkey(t, j), search) > 0)
* n = j * 2;
* We need to subtract 1 from f->mantissa for the sign bit trick else
* to work - that's done in make_bfloat() n = j * 2 + 1;
*/ }
if (likely(f->exponent != 127))
n = j * 2 + (((unsigned int)
(f->mantissa -
bfloat_mantissa(search, f))) >> 31);
else
n = (bkey_cmp(tree_to_bkey(t, j), search) > 0)
? j * 2
: j * 2 + 1;
} while (n < t->size); } while (n < t->size);
inorder = to_inorder(j, t); inorder = to_inorder(j, t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment