lkml.org 
[lkml]   [2014]   [Jul]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 00/18] lib: bitmap: Various improvements
On Fri,  4 Jul 2014 00:42:46 +0200 Rasmus Villemoes <linux@rasmusvillemoes.dk> wrote:

> Many functions in lib/bitmap.c start with an expression such as lim =
> bits/BITS_PER_LONG. Since bits has type (signed) int, and since gcc
> cannot know that it is in fact non-negative, it generates worse code
> than it could. These patches, mostly consisting of changing various
> parameters to unsigned, gives a slight overall code reduction:

Yes, we have a bad habit of using signed types for things where
negative values are absurd.

The patches look OK to me.

> A few issues I thought about, but didn't know what to do with:
>
> * Many of the functions misbehave if nbits is compile-time 0; the
> out-of-line functions generally handle 0 correctly. bitmap_fill() is
> particularly bad, whether the 0 is known at compile time or not. It
> would probably be nice to add detection of at least compile-time 0
> and handle that appropriately.

The best option here would be a compile-time check. Presumably
BUILD_BUG_ON(). That will catch the errant use and will add no runtime
overhead.

> * I didn't change __bitmap_shift_{left,right} to use unsigned because
> I want to fully understand why the algorithm works before making
> that change. However, AFAICT, they behave correctly for all
> (positive) shift amounts. This is not the case for the
> small_const_nbits versions. If for example nbits = n =
> BITS_PER_LONG, the shift operators turn into no-ops (at least on
> x86), so one get *dst = *src, whereas one would expect to get
> *dst=0. That difference in behaviour is somewhat annoying.

yup.


\
 
 \ /
  Last update: 2014-07-08 02:01    [W:0.213 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site