Changeset 3674 for proto/s2k


Ignore:
Timestamp:
Mar 13, 2014, 2:30:32 AM (5 years ago)
Author:
ksherdy
Message:

Updated needle_template.cpp in preparation for s2k graph implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/s2k/demo/needle/needle_template.cpp

    r3607 r3674  
    6868#include <simd-lib/s2p.hpp>
    6969
    70 // search string
     70// Fixed search string.
    7171const char * fixed_pattern  = "needle";
    72 int pattern_size            = strlen(fixed_pattern);
    73 
    74 // Platform independent type definitions.
     72const int pattern_size      = strlen(fixed_pattern);
     73
     74// Platform dependent definitions. // Example only, defined in simd-lib/builtins.hpp.
    7575typedef __m128i BitBlock;
    7676typedef BitBlock BytePack;
    77 typedef uint32_t scanblock_t;
    78 typedef uint32_t scanfield_t;
     77typedef uint32_t ScanWord;
    7978
    8079// Segment-at-a-time buffered stream processing parameters.
    81 const int SCANBLOCK_SIZE   = sizeof(scanblock_t) * 8;
    82 const int SCANFIELD_SIZE   = sizeof(scanfield_t) * 8;
     80const int SCANBLOCK_SIZE   = sizeof(ScanWord) * 8;
     81const int SCANFIELD_SIZE   = sizeof(ScanWord) * 8;
    8382// const int BLOCK_SIZE       =  sizeof(BitBlock) * 8;                       
    84 const int SEGMENT_BLOCKS   = SCANBLOCK_SIZE * SCANFIELD_SIZE / BLOCK_SIZE; 
     83const int SEGMENT_BLOCKS   = SCANBLOCK_SIZE * SCANFIELD_SIZE / BLOCK_SIZE;
    8584const int SEGMENT_SIZE     = SEGMENT_BLOCKS * BLOCK_SIZE;
    8685const int CACHE_SIZE       = 32768;         
     
    110109@decl
    111110
    112 // Transpostion runtime support
     111// Transpostion (runtime support). Example only, defined in simd-lib/transpose.hpp.
    113112struct Transpose {
    114113       
     
    148147int bytes_read              = 0;
    149148int bytes_avail             = 0;
    150 int block_index             = 0; // relative block index within a segment
    151 int block_base              = 0; // byte offset of block
    152 int final_segment_size      = 0; // size of final segment within a buffer
     149
    153150int copy_back_size          = 0;
    154151int copy_back_index         = 0;
    155 int stream_index            = 0; // global stream index
    156 int match_index             = 0; // global match index
     152
     153int block_index             = 0; // block index wrt current segment
     154int block_base              = 0; // byte offset wrt current segment
     155
     156int segment_index           = 0; // segment index wrt current buffer  // unused
     157int segment_base            = 0; // segment offset wrt current buffer // unused
     158
     159int final_segment_size      = 0; // size of final segment within a buffer
     160
     161int stream_base             = 0;
     162int match_pos               = 0;
    157163
    158164int main(int argc, char * argv[]) {
     
    167173  }
    168174
    169   BytePack * Byte; 
    170   BitBlock aligned_buffer[BUFFER_SIZE];
    171   char * buffer = (char *) aligned_buffer;
     175  ATTRIBUTE_SIMD_ALIGN char buffer[BUFFER_SIZE];
    172176  // Pablo transpose.do_block(), transpose.do_final_block()
    173177  // expect 'byte_data' and 'basis' names as input and output arguments.
     
    175179
    176180  // Marker stream iterator.
    177   BitStreamScanner<BitBlock, uint32_t, uint32_t, SEGMENT_BLOCKS> scanner;
     181  BitStreamScanner<BitBlock, ScanWord, ScanWord, SEGMENT_BLOCKS> scanner;
    178182 
    179183  // Segment-at-a-time processing.
     
    188192 
    189193    // Process full segments.
    190     block_base = 0;
     194    block_base      = 0;
     195//    segment_base    = 0;
     196//    segment_index   = 0;
     197
    191198    while (bytes_avail >= SEGMENT_SIZE) {
    192199      scanner.init();
    193200     
    194       for(block_index=0;
    195           block_index<SEGMENT_BLOCKS;
     201      for(block_index = 0;
     202          block_index < SEGMENT_BLOCKS;
    196203          block_index++, block_base+=BLOCK_SIZE) {
    197204         
     
    204211
    205212      while(scanner.has_next()) {
    206         match_index = scanner.scan_to_next()
    207                        + stream_index - pattern_size + 1;
    208         printf("%d:%s\n", match_index, fixed_pattern);
     213        match_pos = scanner.scan_to_next()
     214                       + stream_base - pattern_size + 1;
     215        printf("%d:%s\n", match_pos, fixed_pattern);
    209216      }
    210217
     218//      segment_index++;
     219//      segment_base = segment_index * SEGMENT_SIZE;
     220//      stream_base  = segment_base;
     221      stream_base += SEGMENT_SIZE;
    211222      bytes_avail -= SEGMENT_SIZE;     
    212       stream_index += SEGMENT_SIZE;
    213223    }   
    214224   
     
    242252
    243253    while(scanner.has_next()) {
    244       match_index = scanner.scan_to_next()
    245                      + stream_index - pattern_size + 1;
     254      match_pos = scanner.scan_to_next()
     255                     + stream_base - pattern_size + 1;
    246256                     
    247       printf("%d:%s\n", match_index, fixed_pattern);
     257      printf("%d:%s\n", match_pos, fixed_pattern);
    248258    }
    249259
    250     stream_index += final_segment_size;
     260    stream_base += final_segment_size;
    251261   
    252262    // Copy strlen("needle") - 1 bytes at the segment boundary to handle
     
    255265    copy_back_index    = block_base + bytes_avail - copy_back_size;
    256266    memmove(&buffer[0], &buffer[copy_back_index], copy_back_size);
    257     stream_index -= copy_back_size;
     267
     268    stream_base -= copy_back_size;
    258269  }
    259270
Note: See TracChangeset for help on using the changeset viewer.