Re: Efficently scanning a bit array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Jefferson wrote:
> I want to implement the following function efficently:
> 
> void check_bits(char* ptr, int length)
> {
>   for each bit in the array starting at ptr, of length 'length' which is true
>      f(position of bit);
> }
> 
> Where the position of bit is it's position compared to the start of
> the array (so the first bit of *(ptr+2) is at position 16, assuming 8
> bits per byte!)
> 
> I'm currently doing shifting, but this performs poorly for long,
> sparse arrays. Is there a more efficient method of implementing this,
> possibly using built-ins?

__builtin_ffs

Andrew.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux