Changeset 1552


Ignore:
Timestamp:
Oct 22, 2011, 2:41:44 PM (7 years ago)
Author:
ksherdy
Message:

Added bit stream scan.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock128.hpp

    r1550 r1552  
    3232static IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(bitblock128_t v);
    3333static IDISA_ALWAYS_INLINE uint32_t count_backward_zeroes(bitblock128_t v);
    34 
     34static IDISA_ALWAYS_INLINE uint32_t bitstream_scan(bitblock_128_t * v, uint32_t pos)
    3535
    3636IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum)
     
    128128}
    129129
     130IDISA_ALWAYS_INLINE uint32_t bitstream_scan(bitblock_128_t * v, uint32_t pos) {
     131  unsigned long * bitstream_ptr = (unsigned long *) (((intptr_t) v) + pos/8);
     132  unsigned long bitstream_slice = ((*bitstream_ptr) >> (pos % 8));
     133  if (bitstream_slice != 0) return pos + cfzl(bitstream_slice);
     134  else {
     135    do {
     136      bitstream_ptr++;
     137      bitstream_slice = *bitstream_ptr;
     138    } while (bitstream_slice == 0);
     139    uint32_t base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) v);
     140    return base_posn + cfzl(bitstream_slice);
     141  }
     142}
     143
     144
    130145#endif /* BITBLOCK128_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.