Changeset 1533 for proto/parabix2/src


Ignore:
Timestamp:
Oct 17, 2011, 7:33:05 AM (8 years ago)
Author:
cameron
Message:

Simpler bitwise newline counting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/src/LineColTracker.h

    r864 r1533  
    55       under the Academic Free License version 3.0.
    66*/
    7 
    8 #define MAX_COUNTER_BITS 24
    97
    108static inline void bitwise_half_add(BitBlock x, BitBlock y, BitBlock &sum, BitBlock &carry){
     
    2018}
    2119
    22 #define NEWLINE_BUFFERING
     20#define BITWISE_NEWLINE_COUNTER_BITS 4
    2321
    2422class LineColTracker{
     
    3331    BitBlock last_block_with_newline;
    3432    BitBlock cur_newline;
    35 #ifdef NEWLINE_BUFFERING
    36     BitBlock newline_strm[BUFFER_SIZE/BLOCK_SIZE];
    37     int newline_strm_lgth;
    38 #endif
     33
    3934    int newline_counts;
     35    BitBlock bitwise_counts[BITWISE_NEWLINE_COUNTER_BITS];
    4036};
    4137
     
    4440  last_block_with_newline = simd_const_1(1);
    4541  newline_counts = 0;
    46 #ifdef NEWLINE_BUFFERING
    47   newline_strm_lgth = 0;
    48 #endif
     42  for (int i = 0; i < BITWISE_NEWLINE_COUNTER_BITS; i++) bitwise_counts[i] = simd_const_1(0);
    4943}
    5044
     
    5448
    5549inline void LineColTracker::AdvanceBlock(){
    56 #ifdef NEWLINE_BUFFERING
    57   newline_strm[newline_strm_lgth] = cur_newline;
    58   newline_strm_lgth++;
    59 #endif
    60 
    61 #ifndef NEWLINE_BUFFERING
    62   if(bitblock_has_bit(cur_newline)){
    63     newline_counts += bitblock_bit_count(cur_newline);
     50  BitBlock carry;
     51  if (bitblock_has_bit(cur_newline)){
    6452    last_block_with_newline = cur_newline;
    6553    blocks_after_last_newline_block = 0;
     54    carry = cur_newline;
     55    for (int i = 0; i < BITWISE_NEWLINE_COUNTER_BITS; i++) {
     56      bitwise_half_add(bitwise_counts[i], carry, bitwise_counts[i], carry);
     57    }
     58    if (bitblock_has_bit(carry)){
     59      for (int i = 0; i < BITWISE_NEWLINE_COUNTER_BITS; i++) {
     60        newline_counts += bitblock_bit_count(bitwise_counts[i]) << i;
     61        bitwise_counts[i]  = simd_const_1(0);
     62      }
     63      newline_counts += bitblock_bit_count(carry) << BITWISE_NEWLINE_COUNTER_BITS;
     64    }
    6665  }
    6766  else
    6867    blocks_after_last_newline_block++;
    69 #endif
    7068}
    7169
    7270
    7371void LineColTracker::get_Line_and_Column(int pos_in_block, int & line, int & column) {
    74 #ifdef NEWLINE_BUFFERING
    75   Advance_buffer();
    76 #endif
    77 
    7872
    7973  cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(pos_in_block)));
     
    9387
    9488void LineColTracker::Advance_buffer() {
    95 #ifdef NEWLINE_BUFFERING
    96   BitBlock s1, s2, c1, c2, c3, t0, t1, t2, carry;
    97   int i, j;
    98   int last_blk = newline_strm_lgth - 1;
    99   /* in case we find no newlines within the buffer, the
    100      number of blocks after the last newline grows by the
    101      full block count. */
    102   blocks_after_last_newline_block += newline_strm_lgth;
    103   for (i = last_blk; i >= 0; i--) {
    104     if (bitblock_has_bit(newline_strm[i])) {
    105       last_block_with_newline = newline_strm[i];
    106       blocks_after_last_newline_block = last_blk - i;
    107       break;
    108     }
    109   }
    110   last_blk = i; /* No newlines after this block. */
    111   j = 0;
    112   /* Process 7 blocks of the newline stream at a time. */
    113   for (j = 0; j + 6 <= last_blk; j += 7) {
    114     bitwise_full_add(newline_strm[j], newline_strm[j+1], newline_strm[j+2], s1, c1);
    115     bitwise_full_add(newline_strm[j+3], newline_strm[j+4], newline_strm[j+5], s2, c2);
    116     bitwise_full_add(s1, s2, newline_strm[j+6], t0, c3);  /* t0 is bit0 of 7 block sum */
    117     bitwise_full_add(c1, c2, c3, t1, t2); /*t1 and t2 are bits 1 and 2  of 7 block sum. */
    118     newline_counts += bitblock_bit_count(t0);
    119     newline_counts += 2 * bitblock_bit_count(t1);
    120     newline_counts += 4 * bitblock_bit_count(t2);
    121   }
    122   for (; j <= last_blk; j++) {
    123     newline_counts += bitblock_bit_count(newline_strm[j]);
    124   }
    125   newline_strm_lgth = 0;
    126 #endif
    12789}
    12890
Note: See TracChangeset for help on using the changeset viewer.