[ovs-dev] [PATCH 18/18] ofp-util: Optimize ofputil_version_bitmap_scanr

Simon Horman horms at verge.net.au
Wed Nov 7 00:45:59 UTC 2012


On Sun, Nov 04, 2012 at 10:27:48PM -0800, Ben Pfaff wrote:
> On Fri, Oct 26, 2012 at 11:36:06AM +0900, Simon Horman wrote:
> > Make use of __builtin_clz if available which should optimize
> > ofputil_version_bitmap_scanr() by replacing a loop with
> > a single CLZ instruction when available.
> > 
> > I'm unsure if this approach is worth it or not.
> > But a similar approach could be taken to use ffs()
> > in bitmap_scan().
> > 
> > Signed-off-by: Simon Horman <horms at verge.net.au>
> 
> I didn't notice this until now; I see now that I implemented something
> with the same purpose as:
> 
> /* Returns the index of the rightmost 1-bit in 'x' (e.g. 01011000 => 6), or 32
>  * if 'x' is 0.
>  *
>  * This function only works with 32-bit integers. */
> static inline uint32_t
> leftmost_1bit_idx(uint32_t x)
> {
>     return x ? log_2_floor(x) : 32;
> }

Thanks, I will make use of that.

Do you have any thoughts on if it is worth implementing something
similar for bitmap_scan() using ffs()?



More information about the dev mailing list