Changeset 846 for proto/parabix2


Ignore:
Timestamp:
Dec 19, 2010, 7:34:58 AM (9 years ago)
Author:
cameron
Message:

Update LineColTracker? with newline buffering

Location:
proto/parabix2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/pablo_template.c

    r844 r846  
    401401    t.StreamScan(chars_avail);
    402402    t.Advance_buffer();
     403    tracker.Advance_buffer();
    403404
    404405
  • proto/parabix2/src/LineColTracker.h

    r844 r846  
    2323  public:
    2424    LineColTracker();
    25     int getLineNumber(int mark_pos);
    26     int getColNumber(int mark_pos);
    2725    inline void AdvanceBlock();
    2826    inline void StoreNewlines(BitBlock newline);
     27    inline void Advance_buffer();
    2928    void get_Line_and_Column(int pos_in_block, int & line, int & column);
    3029  private:
    31     BitBlock BitParallelCounter[MAX_COUNTER_BITS];
    3230    int blocks_after_last_newline_block;
    3331    BitBlock last_block_with_newline;
    3432    BitBlock cur_newline;
     33#ifdef NEWLINE_BUFFERING
     34    BitBlock newline_strm[BUFFER_SIZE/BLOCK_SIZE];
     35    int newline_strm_lgth;
     36#endif
    3537    int newline_counts;
    3638};
     39
     40LineColTracker::LineColTracker(){
     41  blocks_after_last_newline_block = 0;
     42  last_block_with_newline = simd_const_1(1);
     43  newline_counts = 0;
     44#ifdef NEWLINE_BUFFERING
     45  newline_strm_lgth = 0;
     46#endif
     47}
    3748
    3849inline void LineColTracker::StoreNewlines(BitBlock newline){
     
    4051}
    4152
    42 LineColTracker::LineColTracker(){
    43   blocks_after_last_newline_block = 0;
    44   last_block_with_newline = simd_const_1(1);
    45   newline_counts = 0;
    46 }
    47 
    48 
    49 #ifndef BITBLOCK_BIT_COUNT
    5053inline void LineColTracker::AdvanceBlock(){
    51   int j = 2;
    52   BitBlock carry;
    53   if(bitblock_has_bit(cur_newline)){
    54     bitwise_half_add(cur_newline,BitParallelCounter[0],BitParallelCounter[0],carry);
    55     last_block_with_newline = cur_newline;
    56     blocks_after_last_newline_block = 0;
    57     bitwise_half_add(carry,BitParallelCounter[1],BitParallelCounter[1],carry);
    58     bitwise_half_add(carry,BitParallelCounter[2],BitParallelCounter[2],carry);
    59     while(bitblock_has_bit(carry)){
    60       j++;
    61       bitwise_half_add(carry,BitParallelCounter[j],BitParallelCounter[j],carry);
    62     }
    63   }
    64   else
    65     blocks_after_last_newline_block++;
    66 }
     54#ifdef NEWLINE_BUFFERING
     55  newline_strm[newline_strm_lgth] = cur_newline;
     56  newline_strm_lgth++;
    6757#endif
    6858
    69 #ifdef BITBLOCK_BIT_COUNT
    70 inline void LineColTracker::AdvanceBlock(){
    71  
     59#ifndef NEWLINE_BUFFERING
    7260  if(bitblock_has_bit(cur_newline)){
    7361    newline_counts += bitblock_bit_count(cur_newline);
     
    7765  else
    7866    blocks_after_last_newline_block++;
     67#endif
    7968}
     69
     70
     71void LineColTracker::get_Line_and_Column(int pos_in_block, int & line, int & column) {
     72#ifdef NEWLINE_BUFFERING
     73  Advance_buffer();
    8074#endif
    8175
    82 void LineColTracker::get_Line_and_Column(int pos_in_block, int & line, int & column) {
     76
    8377  cur_newline = simd_andc(cur_newline, sisd_sfl(simd_const_1(1),sisd_from_int(pos_in_block)));
    8478  if(bitblock_has_bit(cur_newline))
     
    8882             count_backward_zeroes(last_block_with_newline) + pos_in_block+1;
    8983
    90 #ifndef BITBLOCK_BIT_COUNT
    91   int lines = 0;
    92   for(int i=MAX_COUNTER_BITS-1;i>=0;i--)
    93     lines = lines*2 + bitblock_bit_count(BitParallelCounter[i]);
    94   newline_counts = lines;
    95 #endif
    9684 
    9785  if(bitblock_has_bit(cur_newline))
     
    10290}
    10391
     92void LineColTracker::Advance_buffer() {
     93#ifdef NEWLINE_BUFFERING
     94  BitBlock s1, s2, c1, c2, c3, t0, t1, t2, carry;
     95  int i, j;
     96  int last_blk = newline_strm_lgth - 1;
     97  /* in case we find no newlines within the buffer, the
     98     number of blocks after the last newline grows by the
     99     full block count. */
     100  blocks_after_last_newline_block += newline_strm_lgth;
     101  for (i = last_blk; i >= 0; i--) {
     102    if (bitblock_has_bit(newline_strm[i])) {
     103      last_block_with_newline = newline_strm[i];
     104      blocks_after_last_newline_block = last_blk - i;
     105      break;
     106    }
     107  }
     108  last_blk = i; /* No newlines after this block. */
     109  j = 0;
     110  /* Process 7 blocks of the newline stream at a time. */
     111  for (j = 0; j + 6 <= last_blk; j += 7) {
     112    bitwise_full_add(newline_strm[j], newline_strm[j+1], newline_strm[j+2], s1, c1);
     113    bitwise_full_add(newline_strm[j+3], newline_strm[j+4], newline_strm[j+5], s2, c2);
     114    bitwise_full_add(s1, s2, newline_strm[j+6], t0, c3);  /* t0 is bit0 of 7 block sum */
     115    bitwise_full_add(c1, c2, c3, t1, t2); /*t1 and t2 are bits 1 and 2  of 7 block sum. */
     116    newline_counts += bitblock_bit_count(t0);
     117    newline_counts += 2 * bitblock_bit_count(t1);
     118    newline_counts += 4 * bitblock_bit_count(t2);
     119  }
     120  for (; j <= last_blk; j++) {
     121    newline_counts += bitblock_bit_count(newline_strm[j]);
     122  }
     123  newline_strm_lgth = 0;
     124#endif
     125}
    104126
    105127
Note: See TracChangeset for help on using the changeset viewer.