From 28ca43d2eb46c8ca5ba05e349759c3ca7618ab7d Mon Sep 17 00:00:00 2001 From: dougm Date: Fri, 10 May 2019 19:55:29 +0000 Subject: [PATCH] Replace the expression "-mask & ~mask" with a function call that does the same thing, but is commented so that it might be better understood. Approved by: kib (mentor) Differential Revision: https://reviews.freebsd.org/D20231 --- sys/kern/subr_blist.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c index 8fe47cfa187..e19d53b5013 100644 --- a/sys/kern/subr_blist.c +++ b/sys/kern/subr_blist.c @@ -642,6 +642,19 @@ blst_next_leaf_alloc(blmeta_t *scan, daddr_t blk, int count) return (0); } +/* + * Given a bitmask, flip all the bits from the least-significant 1-bit to the + * most significant bit. If the result is non-zero, then the least-significant + * 1-bit of the result is in the same position as the least-signification 0-bit + * in mask that is followed by a 1-bit. + */ +static inline u_daddr_t +flip_hibits(u_daddr_t mask) +{ + + return (-mask & ~mask); +} + /* * BLST_LEAF_ALLOC() - allocate at a leaf in the radix tree (a bitmap). * @@ -659,7 +672,7 @@ blst_leaf_alloc(blmeta_t *scan, daddr_t blk, int count) count1 = count - 1; num_shifts = fls(count1); mask = scan->bm_bitmap; - while ((-mask & ~mask) != 0 && num_shifts > 0) { + while (flip_hibits(mask) != 0 && num_shifts > 0) { /* * If bit i is set in mask, then bits in [i, i+range1] are set * in scan->bm_bitmap. The value of range1 is equal to count1 -- 2.45.0