* Lai Jiangshan ([email protected]) wrote: > They are the same, but I don't think the compiler > can optimize it. > > And it also helps for understanding the following code. > > Signed-off-by: Lai Jiangshan <[email protected]> > --- > rculfhash.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/rculfhash.c b/rculfhash.c > index edbd24a..7b880d7 100644 > --- a/rculfhash.c > +++ b/rculfhash.c > @@ -719,7 +719,7 @@ struct _cds_lfht_node *lookup_bucket(struct cds_lfht *ht, > unsigned long size, > > assert(size > 0); > index = hash & (size - 1); > - order = get_count_order_ulong(index + 1); > + order = fls_ulong(index); > > dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n", > hash, index, order, index & (!order ? 0 : ((1UL << (order - > 1)) - 1)));
merged as: commit a4ea2223fa701bd34b09fb3eede037908dbdd0c8 Author: Lai Jiangshan <[email protected]> Date: Mon Oct 17 10:19:10 2011 -0400 rculfhash: Simplify lookup_bucket() They are the same, but I don't think the compiler can optimize it. And it also helps for understanding the following code. [ Edit by Mathieu Desnoyers: - Add a comment that describes the equivalence between get_count_order and fls for this lookup of index + 1. ] Signed-off-by: Lai Jiangshan <[email protected]> Signed-off-by: Mathieu Desnoyers <[email protected]> diff --git a/rculfhash.c b/rculfhash.c index d733d6b..189f8c8 100644 --- a/rculfhash.c +++ b/rculfhash.c @@ -724,7 +724,12 @@ struct _cds_lfht_node *lookup_bucket(struct cds_lfht *ht, unsigned long size, assert(size > 0); index = hash & (size - 1); - order = get_count_order_ulong(index + 1); + /* + * equivalent to get_count_order_ulong(index + 1), but optimizes + * away the non-existing 0 special-case for + * get_count_order_ulong. + */ + order = fls_ulong(index); dbg_printf("lookup hash %lu index %lu order %lu aridx %lu\n", hash, index, order, index & (!order ? 0 : ((1UL << (order - 1)) - 1))); -- Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com _______________________________________________ ltt-dev mailing list [email protected] http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
