lkml.org 
[lkml]   [2002]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] (1/7) entropy, take 2 - log2
    Oliver Xymoron wrote:
    >
    >> +static inline __u32 int_log2_16bits(__u32 word)
    > {
    > /* Smear msbit right to make an n-bit mask */
    > word |= word >> 8;
    > word |= word >> 4;
    > word |= word >> 2;
    > word |= word >> 1;
    > - /* Remove one bit to make this a logarithm */
    > - word >>= 1;
    > - /* Count the bits set in the word */
    > - word -= (word >> 1) & 0x555;
    > - word = (word & 0x333) + ((word >> 2) & 0x333);
    > - word += (word >> 4);
    > - word += (word >> 8);
    > - return word & 15;
    > +
    > + return hweight16(word)-1;
    > }
    > -#endif

    I suggest you to use a more efficient version like that below:

    static inline int ld2_16(__u16 v)
    {
    unsigned r = 0;

    if (v >= 0x100) {
    v >>= 8;
    r += 8;
    }
    if (v >= 0x10) {
    v >>= 4;
    r += 4;
    }
    if (v >= 4) {
    v >>= 2;
    r += 2;
    }
    if (v >= 2)
    r++;
    return r;
    }


    --
    Abramo Bagnara mailto:abramo.bagnara@libero.it

    Opera Unica Phone: +39.546.656023
    Via Emilia Interna, 140
    48014 Castel Bolognese (RA) - Italy
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 13:28    [W:2.722 / U:0.008 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site