Changeset 3730


Ignore:
Timestamp:
Mar 18, 2014, 1:14:03 AM (5 years ago)
Author:
ksherdy
Message:

Added first iteration of compilable grep fixed string demo.

Location:
proto/RE/demo
Files:
5 added
5 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/demo/Makefile

    r3728 r3730  
    66
    77PABLO_DEMO=grep_demo.py
    8 INFILE=test/fruitlist0.txt
     8INFILE=test/fruitlist0.dat
    99
    1010PABLO_DEBUG=-d
  • proto/RE/demo/grep_template.cpp

    r3728 r3730  
    11/**
    2  * 'grep'-like search C++ template.
     2 * grep static fixed string search C++ template.
    33 *
    44 * Author:   Ken Herdy
    55 *
    6  * Usage:
     6 * Usage: ./grep <infile> [-o outfile]
    77 *
    88 * Description:
    99 *
     10 * 'grep.py' and 'grep_template.cpp' are tightly coupled on a number of variables:
     11 *
     12 * 1. Tranpose.do_block expects 'byte_data' and 'basis_bits'.
     13 * 2. All StreamFunction.do_final_block methods expect 'EOF_mask'.
     14 * 3. Sequential iterators (scanners) expect 'output.matches' in post processing.
    1015 *
    1116 **/
     
    2025#include <simd-lib/s2p.hpp>
    2126
    22 // Fixed search string.
     27// Fixed pattern.
    2328const char * fixed_pattern  = "apple";
    2429const int pattern_size      = strlen(fixed_pattern);
     
    7883  }
    7984
    80   void do_final_block(char * byte_data, Basis_bits & basis_bits, BitBlock & EOF_mask) {
     85  void do_final_block(char * byte_data, Basis_bits & basis_bits, BitBlock & FEM_mask) {
    8186        BytePack * Byte = (BytePack *) byte_data;
    8287
     
    8691            basis_bits.bit_4, basis_bits.bit_5, basis_bits.bit_6, basis_bits.bit_7);
    8792
    88         basis_bits.bit_7 = simd_and(basis_bits.bit_7, EOF_mask);
    89         basis_bits.bit_6 = simd_and(basis_bits.bit_6, EOF_mask);
    90         basis_bits.bit_5 = simd_and(basis_bits.bit_5, EOF_mask);
    91         basis_bits.bit_4 = simd_and(basis_bits.bit_4, EOF_mask);
    92         basis_bits.bit_3 = simd_and(basis_bits.bit_3, EOF_mask);
    93         basis_bits.bit_2 = simd_and(basis_bits.bit_2, EOF_mask);
    94         basis_bits.bit_1 = simd_and(basis_bits.bit_1, EOF_mask);
    95         basis_bits.bit_0 = simd_and(basis_bits.bit_0, EOF_mask);
     93        basis_bits.bit_7 = simd_and(basis_bits.bit_7, FEM_mask);
     94        basis_bits.bit_6 = simd_and(basis_bits.bit_6, FEM_mask);
     95        basis_bits.bit_5 = simd_and(basis_bits.bit_5, FEM_mask);
     96        basis_bits.bit_4 = simd_and(basis_bits.bit_4, FEM_mask);
     97        basis_bits.bit_3 = simd_and(basis_bits.bit_3, FEM_mask);
     98        basis_bits.bit_2 = simd_and(basis_bits.bit_2, FEM_mask);
     99        basis_bits.bit_1 = simd_and(basis_bits.bit_1, FEM_mask);
     100        basis_bits.bit_0 = simd_and(basis_bits.bit_0, FEM_mask);
    96101  }
    97102};
     
    122127int main(int argc, char * argv[]) {
    123128  if ((2 > argc) || (2 < argc)) {
    124       printf("Usage: %s <filename>\n", argv[0]); exit(-1);
     129      printf("Usage: %s <filename>\n", argv[0]); exit(1);
    125130  }
    126131
     
    128133  FILE * istream;
    129134  if((istream = fopen(infilename, "rb")) == NULL ) {
    130       printf("fopen error"); exit( 1 );
     135      printf("fopen error\n"); exit(1);
    131136  }
    132137
     
    163168        @block_stmts
    164169
    165         scanner.load_block(matches.all, block_index);
     170        scanner.load_block(output.matches, block_index);
    166171      }
    167172
     
    187192      @block_stmts
    188193
    189       scanner.load_block(matches.all, block_index);
     194      scanner.load_block(output.matches, block_index);
    190195
    191196      block_base += BLOCK_SIZE;
     
    201206      @final_block_stmts
    202207
    203       scanner.load_block(matches.all, block_index);
     208      scanner.load_block(output.matches, block_index);
    204209    }
    205210
  • proto/RE/demo/src/Makefile

    r3728 r3730  
     1SRCFILE=grep.cpp
     2FIXED_PATTERN=apple
    13OUTFILE=grep
    2 SRCFILE=grep.cpp
    34TESTFILE0=../test/fruitlist0.dat
    45TESTFILE1=../test/fruitlist1.dat
     
    2324endif
    2425
     26all: grep
     27
    2528grep:   $(SRCFILE)
    2629        $(CC) -o $(OUTFILE) $(SRCFILE) $(INCLUDES) $(AFLAGS)
    2730       
    28 #test: $(OUTFILE)
    29 #       ./$(OUTFILE) $(TESTFILE0) > 0   
    30 #       grep needle $(TESTFILE0) -o -b > 1
    31 #       diff 0 1
    32 #       ./$(OUTFILE) $(TESTFILE1) > 0   
    33 #       grep needle $(TESTFILE1) -o -b > 1
    34 # diff 0 1
    35 #       ./$(OUTFILE) $(TESTFILE2) > 0   
    36 #       grep needle $(TESTFILE2) -o -b > 1
    37 #       diff 0 1
    38 #       ./$(OUTFILE) $(TESTFILE3) > 0   
    39 #       grep needle $(TESTFILE3) -o -b > 1
    40 #       diff 0 1
    41 #       ./$(OUTFILE) $(TESTFILE4) > 0   
    42 #       grep needle $(TESTFILE4) -o -b > 1
    43 #       diff 0 1       
     31test: $(OUTFILE)
     32        ./$(OUTFILE) $(TESTFILE0) > 0   
     33        grep $(FIXED_PATTERN) $(TESTFILE0) -o -b > 1
     34        diff 0 1
     35        ./$(OUTFILE) $(TESTFILE1) > 0   
     36        grep $(FIXED_PATTERN) $(TESTFILE1) -o -b > 1
     37        diff 0 1
     38        ./$(OUTFILE) $(TESTFILE2) > 0   
     39        grep $(FIXED_PATTERN) $(TESTFILE2) -o -b > 1
     40        diff 0 1
     41        ./$(OUTFILE) $(TESTFILE3) > 0   
     42        grep $(FIXED_PATTERN) $(TESTFILE3) -o -b > 1
     43        diff 0 1
     44        ./$(OUTFILE) $(TESTFILE4) > 0   
     45        grep $(FIXED_PATTERN) $(TESTFILE4) -o -b > 1
     46        diff 0 1       
    4447
    4548clean:
    46         rm -f $(SRCFILE) $(OUTFILE)
     49        rm -f $(SRCFILE) $(OUTFILE) 0 1
    4750
Note: See TracChangeset for help on using the changeset viewer.