Changeset 189 for trunk/src


Ignore:
Timestamp:
Jul 24, 2008, 10:42:05 AM (11 years ago)
Author:
cameron
Message:

OPTIMIZE_SHORT_SCAN version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/engine.c

    r188 r189  
    213213#endif
    214214
     215#ifdef OPTIMIZE_SHORT_SCAN
     216        sentinel_value = sisd_sfli(sentinel_value, 8*sizeof(unsigned long));
     217#endif
     218
    215219        for (int j = minLexicalItem; j < LexicalItemCount; j++) {
    216220                buf->item_stream[j][BUFFER_BLOCKS] = sentinel_value;
     
    374378
    375379
     380
     381#ifdef OPTIMIZE_SHORT_SCAN
     382//
     383//  Inline ScanTo with unrolled first test that should almost always
     384//  succeed for short scans.
     385#define ScanTo(item) \
     386do {\
     387        unsigned long segment = bitstream_segment_from(buf->item_stream[item], buffer_rel_pos);\
     388        if (segment != 0) buffer_rel_pos += cfzl(segment);\
     389        else {\
     390                buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);\
     391                buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     392                while (buffer_rel_pos >= BUFFER_SIZE) {\
     393                        buffer_rel_pos = BUFFER_SIZE;\
     394                        AdjustBufferEndForIncompleteSequences();\
     395                        FinalizeBuffer_action();\
     396                        AdvanceBuffers();\
     397                        buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     398                }\
     399        }\
     400} while(0)
     401
     402// The following version seems cleaner, but measured mispredictions are higher
     403// #define ScanTo(item) \
     404// do {\
     405//      unsigned long segment = bitstream_segment_from(buf->item_stream[item], buffer_rel_pos);\
     406//      while (unlikely (segment == 0)) {\
     407//              buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);\
     408//              if (buffer_rel_pos >= BUFFER_SIZE) {\
     409//                      buffer_rel_pos = BUFFER_SIZE;\
     410//                      AdjustBufferEndForIncompleteSequences();\
     411//                      FinalizeBuffer_action();\
     412//                      AdvanceBuffers();\
     413//              }\
     414//              segment = bitstream_segment_from(buf->item_stream[item], buffer_rel_pos);\
     415//      }\
     416//      buffer_rel_pos += cfzl(segment);\
     417// } while(0)
     418//
     419// #define ScanTextTo(item) \
     420// do {\
     421//      unsigned long segment = bitstream_segment_from(buf->item_stream[item], buffer_rel_pos);\
     422//      text_or_markup_start = AbsPos();\
     423//      if (segment != 0) buffer_rel_pos += cfzl(segment);\
     424//      else {\
     425//              buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);\
     426//              buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     427//              while (buffer_rel_pos >= BUFFER_SIZE) {\
     428//                      buffer_rel_pos = BUFFER_SIZE;\
     429//                      AdjustBufferEndForIncompleteSequences();\
     430//                      Text_action(GetCodeUnitPtr(text_or_markup_start), LengthFrom(text_or_markup_start), true);\
     431//                      text_or_markup_start = AbsPos();\
     432//                      FinalizeBuffer_action();\
     433//                      AdvanceBuffers();\
     434//                      buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);\
     435//              }\
     436//      }\
     437// } while(0)
     438
     439template <class B>
     440inline void ParsingEngine<B>::ScanTextTo(int item) {
     441        text_or_markup_start = AbsPos();
     442        unsigned long segment = bitstream_segment_from(buf->item_stream[item], buffer_rel_pos);
     443        if (segment != 0) buffer_rel_pos += cfzl(segment);
     444        else {
     445                buffer_rel_pos = (buffer_rel_pos & -8) + 8*sizeof(unsigned long);
     446                buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     447                while (buffer_rel_pos >= BUFFER_SIZE) {
     448                        buffer_rel_pos = BUFFER_SIZE;
     449                        AdjustBufferEndForIncompleteSequences();
     450                        Text_action(GetCodeUnitPtr(text_or_markup_start), LengthFrom(text_or_markup_start), true);
     451                        text_or_markup_start = AbsPos();
     452                        FinalizeBuffer_action();
     453                        AdvanceBuffers();
     454                        buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     455                }
     456        }
     457}
     458
     459#endif
     460
    376461#ifndef OPTIMIZE_SHORT_SCAN
    377462
    378 /*
    379463#define ScanTo(item) \
    380464do {\
     
    387471  }\
    388472} while(0)
    389 */
    390 
    391 
    392 #endif
    393 template <class B>
    394 inline void ParsingEngine<B>::ScanTo(int item) {
    395         buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
    396         while (buffer_rel_pos >= BUFFER_SIZE) {
    397                 AdjustBufferEndForIncompleteSequences();
    398                 FinalizeBuffer_action();
    399                 AdvanceBuffers();
    400                 buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
    401         }
    402 }
     473
     474
     475// template <class B>
     476// inline void ParsingEngine<B>::ScanTo(int item) {
     477//      buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     478//      while (buffer_rel_pos >= BUFFER_SIZE) {
     479//              AdjustBufferEndForIncompleteSequences();
     480//              FinalizeBuffer_action();
     481//              AdvanceBuffers();
     482//              buffer_rel_pos = bitstream_scan(buf->item_stream[item], buffer_rel_pos);
     483//      }
     484// }
    403485
    404486template <class B>
     
    415497        }
    416498}
     499#endif
    417500
    418501template <class B>
Note: See TracChangeset for help on using the changeset viewer.