Changeset 1890 for trunk/lib


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.

Location:
trunk/lib
Files:
2 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
  • trunk/lib/bitblock128.hpp

    r1889 r1890  
    3030static IDISA_ALWAYS_INLINE bitblock128_t convert (uint64_t s);
    3131static IDISA_ALWAYS_INLINE uint64_t convert (bitblock128_t v);
    32 static IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(bitblock128_t v);
    33 static IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(bitblock128_t v);
    34 static IDISA_ALWAYS_INLINE uint32_t bitstream_scan(bitblock128_t * v, uint32_t pos);
    3532
    3633IDISA_ALWAYS_INLINE void adc(bitblock128_t x, bitblock128_t y, bitblock128_t & carry, bitblock128_t & sum)
     
    8279}
    8380
    84 IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(bitblock128_t v) {
    85         union {bitblock128_t bitblock; scanword_t elems[sizeof(bitblock128_t)/sizeof(scanword_t)];} u;
    86         u.bitblock = v;
    87   uint32_t so_far = 0;
    88   for (int i = 0; i < sizeof(bitblock128_t)/sizeof(scanword_t); i++) {
    89     if (u.elems[i] != 0) return so_far + scan_forward_zeroes(u.elems[i]);
    90     so_far += 8 * sizeof(scanword_t);
    91   }
    92   return so_far;
    93 }
    94 
    95 IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(bitblock128_t v) {
    96         union {bitblock128_t bitblock; scanword_t elems[sizeof(bitblock128_t)/sizeof(scanword_t)];} u;
    97         u.bitblock = v;
    98   uint32_t so_far = 0;
    99   for (int i = sizeof(bitblock128_t)/sizeof(scanword_t) - 1; i >= 0; i--) {
    100     if (u.elems[i] != 0) return so_far + scan_backward_zeroes(u.elems[i]);
    101     so_far += 8 * sizeof(scanword_t);
    102   }
    103   return so_far;
    104 }
    105 
    106 IDISA_ALWAYS_INLINE uint32_t bitstream_scan(bitblock128_t * v, uint32_t pos) {
    107   scanword_t * bitstream_ptr = (scanword_t *) (((intptr_t) v) + pos/8);
    108   scanword_t bitstream_slice = ((*bitstream_ptr) >> (pos % 8));
    109   if (bitstream_slice != 0) return pos + scan_forward_zeroes(bitstream_slice);
    110   else {
    111     do {
    112       bitstream_ptr++;
    113       bitstream_slice = *bitstream_ptr;
    114     } while (bitstream_slice == 0);
    115     uint32_t base_posn = 8*((intptr_t) bitstream_ptr - (intptr_t) v);
    116     return base_posn + scan_forward_zeroes(bitstream_slice);
    117   }
    118 }
    11981
    12082
Note: See TracChangeset for help on using the changeset viewer.