Ignore:
Timestamp:
Jan 27, 2012, 10:19:43 AM (7 years ago)
Author:
cameron
Message:

Move count_forward_zeroes et al up to remove 128-bit dependency.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock.hpp

    r1874 r1890  
    2323
    2424template<class T> void print_register(const char * var_name, T v);
     25
     26static IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(BitBlock v);
     27static IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(BitBlock v);
     28static IDISA_ALWAYS_INLINE uint32_t bitstream_scan(BitBlock * v, uint32_t pos);
     29
    2530
    2631/*  BitBlock union type */
     
    5156}
    5257
     58IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(BitBlock v) {
     59        union {BitBlock bitblock; scanword_t elems[sizeof(BitBlock)/sizeof(scanword_t)];} u;
     60        u.bitblock = v;
     61        uint32_t so_far = 0;
     62        for (int i = 0; i < sizeof(BitBlock)/sizeof(scanword_t); i++) {
     63                if (u.elems[i] != 0) return so_far + scan_forward_zeroes(u.elems[i]);
     64                so_far += 8 * sizeof(scanword_t);
     65        }
     66        return so_far;
     67}
     68
     69IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(BitBlock v) {
     70        union {BitBlock bitblock; scanword_t elems[sizeof(BitBlock)/sizeof(scanword_t)];} u;
     71        u.bitblock = v;
     72        uint32_t so_far = 0;
     73        for (int i = sizeof(BitBlock)/sizeof(scanword_t) - 1; i >= 0; i--) {
     74                if (u.elems[i] != 0) return so_far + scan_backward_zeroes(u.elems[i]);
     75                so_far += 8 * sizeof(scanword_t);
     76        }
     77        return so_far;
     78}
     79
     80IDISA_ALWAYS_INLINE uint32_t bitstream_scan(BitBlock * v, uint32_t pos) {
     81        scanword_t * bitstream_ptr = (scanword_t *) (((intptr_t) v) + pos/8);
     82        scanword_t bitstream_slice = ((*bitstream_ptr) >> (pos % 8));
     83        if (bitstream_slice != 0) return pos + scan_forward_zeroes(bitstream_slice);
     84        else {
     85                do {
     86                        bitstream_ptr++;
     87                        bitstream_slice = *bitstream_ptr;
     88                } while (bitstream_slice == 0);
     89                uint32_t base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) v);
     90                return base_posn + scan_forward_zeroes(bitstream_slice);
     91        }
     92}
     93
    5394#endif /* BITBLOCK_HPP */
    5495
Note: See TracChangeset for help on using the changeset viewer.