Changeset 3216


Ignore:
Timestamp:
May 29, 2013, 9:16:47 AM (6 years ago)
Author:
cameron
Message:

Eliminated the specialized BaseCount16 versions; unneeded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock_iterator.hpp

    r3215 r3216  
    3333
    3434//
    35 // We could use FW=32 bit scan units, but 8 seems to be faster.
     35// Could also use FW 32.
    3636#define FW 8
    3737#define _FW _8
     
    583583};
    584584
    585 /*=============================================================================
    586  
    587    Special iterators for content buffers with 16-bit right deletion results.
    588    Input: (a) a bitblock with undeleted positions rightmost in each 16-bit field.
    589           (b) a bitblock of 16-bit fields with a partial sum of the nondeleted
    590               positions in this field and all the ones to the right.
    591          
    592           The partial sum may be computed given B, a bitblock containg the count
    593           of nondeleted positions in each field using PartialSum16(B).
    594        
    595    
    596 */
    597 
    598 
    599 static inline BitBlock PartialSum16(BitBlock BaseCounts16) {
    600         BitBlock t = simd<16>::add(BaseCounts16, mvmd<16>::slli<1>(BaseCounts16));
    601         BitBlock u = simd<16>::add(t, mvmd<16>::slli<2>(t));
    602         return simd<16>::add(u, mvmd<16>::slli<4>(u));
    603 }
    604 
    605 template <class bitblock_t, class scanblock_t>
    606 class ForwardScannerWithBaseCounts16: public Scanner<bitblock_t, scanblock_t> {
    607 
    608 public:
    609 
    610         ForwardScannerWithBaseCounts16(){}
    611         ForwardScannerWithBaseCounts16(const bitblock_t * s, bitblock_t partial_sums_16) {
    612                 init(s, partial_sums_16);
    613         }
    614 
    615         IDISA_ALWAYS_INLINE void init(const bitblock_t * s, bitblock_t partial_sums_16) {
    616                 this->strm = s;
    617                 this->pos = 0;
    618                 this->blk = 0;
    619                 this->scan_blk = *(scanblock_t *)s;
    620                 /* Shift by one field so that the base is the sum for the prev. fields. */
    621                 this->base_per_field16._128 = mvmd<16>::slli<1>(partial_sums_16);
    622         }
    623 
    624         IDISA_ALWAYS_INLINE int32_t scan_to_next() {
    625                 while (this->blk < BLOCK_COUNT){
    626                         if(has_bit(this->scan_blk)){
    627                                 int pos = scan_forward_zeroes(this->scan_blk) + (this->blk * (sizeof(scanblock_t)*8));
    628                                 this->scan_blk = this->scan_blk & (this->scan_blk-1);  // clear rightmost bit
    629                
    630                                 this->pos = this->base_per_field16._16[pos/16] + (pos & 15);
    631 
    632                                 return (this->pos);
    633                         }
    634 
    635                         this->blk++;
    636                         this->scan_blk = *((scanblock_t *)this->strm + this->blk);
    637                 };
    638 
    639                 this->pos = EOS;
    640                 return (this->pos);
    641         }
    642 
    643 
    644         IDISA_ALWAYS_INLINE bool is_done() {return (EOS==this->pos);}
    645         IDISA_ALWAYS_INLINE void set_strm(const bitblock_t * strm) {this->strm = strm;}
    646         IDISA_ALWAYS_INLINE const bitblock_t * get_strm() const {return this->strm;}
    647         IDISA_ALWAYS_INLINE int32_t get_pos() const {return this->pos;}
    648 
    649         static const int32_t BLOCK_COUNT = sizeof(bitblock_t)/sizeof(scanblock_t);
    650         ubitblock base_per_field16;
    651 };
    652 
    653 template <class bitblock_t> static inline bool eq_bitblocks(bitblock_t x, bitblock_t y) {
    654   return bitblock::all(simd<16>::eq(x, y));
    655 }
    656 
    657 
    658 template<class bitblock_t, class scanblock_t>
    659 class ForwardIteratorWithBaseCounts16 : public std::iterator<std::input_iterator_tag, int>
    660 {
    661 public:
    662         ForwardIteratorWithBaseCounts16() {}
    663 
    664         ForwardIteratorWithBaseCounts16(bitblock_t * s, bitblock_t partial_sums_16): scanner(s, partial_sums_16)
    665         {
    666                 scanner.scan_to_next();
    667         }
    668 
    669         void init(bitblock_t * s, bitblock_t partial_sums_16)
    670         {
    671                 scanner.init(s, partial_sums_16);
    672                 scanner.scan_to_next();
    673         }
    674 
    675         // equal position and stream
    676         bool operator==(const ForwardIteratorWithBaseCounts16& iter)
    677         {
    678                 return (scanner.get_strm() == iter.scanner.get_strm()) &&
    679                        (scanner.get_pos() == iter.scanner.get_pos) &&
    680                        (eq_bitblocks<bitblock_t>(scanner.base_per_field16, iter.scanner.base_per_field16));
    681         }
    682 
    683         // not equal position and stream
    684         bool operator!=(const ForwardIteratorWithBaseCounts16& iter)
    685         {
    686                 return (scanner.get_strm() != iter.scanner.get_strm()) ||
    687                        (scanner.get_pos() != iter.scanner.get_pos) ||
    688                        (!eq_bitblocks<bitblock_t>(scanner.base_per_field16, iter.scanner.base_per_field16));
    689         }
    690 
    691         // Returns absolute position.
    692         IDISA_ALWAYS_INLINE int32_t operator*()
    693         {
    694                 return scanner.get_pos();
    695         }
    696 
    697         // prefix increment
    698         IDISA_ALWAYS_INLINE ForwardIteratorWithBaseCounts16& operator++()
    699         {
    700                 scanner.scan_to_next();
    701                 return(*this);
    702         }
    703 
    704         // postfix increment
    705         ForwardIteratorWithBaseCounts16 operator++(int)
    706         {
    707                 ForwardIteratorWithBaseCounts16 temp(*this);
    708                 ++(*this);
    709                 return(temp);
    710         }
    711 
    712 private:
    713         ForwardScannerWithBaseCounts16<bitblock_t, scanblock_t> scanner;
    714 };
    715 
    716 
    717 class BitBlockForwardIteratorWithBaseCounts16: public ForwardIteratorWithBaseCounts16<BitBlock, ScanWord> {
    718 public:
    719         BitBlockForwardIteratorWithBaseCounts16(){}
    720         BitBlockForwardIteratorWithBaseCounts16(BitBlock * s, BitBlock partial_sums_16): ForwardIteratorWithBaseCounts16<BitBlock, ScanWord>(s, partial_sums_16){}
    721 };
    722585
    723586
Note: See TracChangeset for help on using the changeset viewer.