Changeset 2566


Ignore:
Timestamp:
Oct 26, 2012, 3:05:43 PM (6 years ago)
Author:
ksherdy
Message:

Updated template with improved buffer management.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/PDF/pablo_template_pdf.cpp

    r2560 r2566  
    44#include <sys/types.h>
    55#include <sys/stat.h>
     6#include <iostream>
     7using namespace std;
     8
     9#define PDF_DEBUG
    610
    711#define LocalCarryDeclare(name, count)\
     
    1216#include <simd-lib/bitblock_iterator.hpp>
    1317#include <simd-lib/s2p.hpp>
     18#include <simd-lib/buffer.hpp>
    1419#include <perflib/perfsec.h>
    1520
     
    3338// Buffer Management
    3439//////////////////////////////////////////////////////////////////////////////////////////
    35 #define PADDING_BLOCKS 1
     40#define PADDING_BLOCKS 0
    3641#define PADDING_SIZE (BLOCK_SIZE * PADDING_BLOCKS)
    3742#define COPYBACK_BLOCKS 0
     
    3944#define LOOKAHEAD_BLOCKS 1
    4045#define LOOKAHEAD_SIZE (BLOCK_SIZE * LOOKAHEAD_BLOCKS)
    41 #define SEGMENT_BLOCKS  12
     46#define SEGMENT_BLOCKS  1
    4247#define SEGMENT_SIZE (BLOCK_SIZE * SEGMENT_BLOCKS)
    4348#define BUFFER_SIZE (COPYBACK_SIZE + SEGMENT_SIZE + LOOKAHEAD_SIZE + PADDING_SIZE)
     
    105110
    106111        /* Extras */
    107 
    108112        parity.odd = simd<2>::constant<1>();
    109113        parity.even = simd<2>::constant<2>();
    110114
    111         int block_base=0;
     115        int block_base = 0;
    112116        int block_pos = 0;
    113         int buffer_base=0;
    114         int buffer_pos = 0;
    115117        int chars_avail = 0;
    116118        int chars_read = 0;
     119        int padding_read = 0;
     120        int remaining = 0;
     121
     122  /* Tracked for post processing */
     123        //int buffer_base=0;
     124        //int buffer_pos = 0;
    117125
    118126        //////////////////////////////////////////////////////////////////////////////////////////
    119127        // Buffer Management
    120128        //////////////////////////////////////////////////////////////////////////////////////////
    121 
    122         #include <simd-lib/buffer.hpp>
    123 
    124129        uint8_t * src_buffer;
    125130        ALLOC_STATIC_ALIGNED_BYTE_BUFFER(src_buffer, BUFFER_SIZE);
     
    128133        // Initial file read
    129134        //////////////////////////////////////////////////////////////////////////////////////////
    130         chars_read = fread((void *)src_buffer, 1, SEGMENT_SIZE, infile);
     135        chars_read = fread((void *)src_buffer, 1, SEGMENT_SIZE + LOOKAHEAD_SIZE, infile);
     136        remaining = chars_read;
    131137        chars_avail = chars_read;
    132138
     
    137143        //
    138144        //////////////////////////////////////////////////////////////////////////////////////////
    139         chars_read = chars_avail + fread(&src_buffer[chars_avail], 1, PADDING_SIZE, infile);
    140         chars_avail = chars_read;
    141         if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
     145       
     146//      padding_read = fread(&src_buffer[chars_read], 1, (chars_read + LOOKAHEAD_SIZE), infile);
     147//      remaining += padding_read;
     148//      chars_avail += padding_read;
     149
     150        if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
    142151
    143152        @stream_stmts
     
    152161                  s2p_do_block((BytePack *) &src_buffer[block_base], basis_bits);
    153162
     163                        #ifdef PDF_DEBUG
     164                        //cout << endl << "SEGMENTS" << endl;
     165                        for (int i = 0; i < BLOCK_SIZE; i++) {
     166                                cout << src_buffer[block_base + i];
     167                        }
     168                        #endif
     169
    154170                  @block_stmts
    155171
     
    159175          PERF_SEC_END(parser_timer, chars_avail);
    160176
    161           memmove(src_buffer, &src_buffer[SEGMENT_SIZE], PADDING_SIZE);
    162           chars_read = fread(&src_buffer[PADDING_SIZE], 1, SEGMENT_SIZE, infile);// + LOOKAHEAD_SIZE; ??????
    163           chars_avail = chars_read;
    164           if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
    165           buffer_pos += chars_avail;
    166           buffer_base = buffer_pos;
     177                remaining -= SEGMENT_SIZE;
     178          memmove(src_buffer, &src_buffer[SEGMENT_SIZE], LOOKAHEAD_SIZE);
     179          chars_read = fread(&src_buffer[padding_read], 1, SEGMENT_SIZE + LOOKAHEAD_SIZE, infile);
     180                remaining += chars_read;
     181                chars_avail = remaining;
     182
     183                if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
     184
     185    /* Tracked for post processing */
     186          // buffer_pos += chars_avail;
     187          // buffer_base = buffer_pos;
     188
    167189        }
    168190
     
    172194        PERF_SEC_START(parser_timer);
    173195
    174         block_pos = 0;
    175         int remaining = chars_avail;
     196        block_base = 0;
    176197
    177198        /* Full Blocks */
    178199        uint32_t blk = 0;
    179200        while (remaining >= BLOCK_SIZE) {
    180                   block_base = block_pos;
    181                   s2p_do_block((BytePack *) &src_buffer[block_pos], basis_bits);
     201       
     202                        #ifdef PDF_DEBUG
     203                        //cout << endl << "FULL BLOCK" << endl;
     204                        for(int i = 0; i < BLOCK_SIZE; i++) {
     205                                cout << src_buffer[block_base + i];
     206                        }
     207                        #endif         
     208
     209                  s2p_do_block((BytePack *) &src_buffer[block_base], basis_bits);
    182210                  @block_stmts
    183211
    184 //                postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, (char *)src_buffer, buffer_base, block_base, chars_avail, tracker);
    185                   block_pos += BLOCK_SIZE;
     212      // postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, (char *)src_buffer, buffer_base, block_base, chars_avail, tracker);
     213
     214                  block_base += BLOCK_SIZE;
    186215                  remaining -= BLOCK_SIZE;
    187216                  blk++;
    188217        }
    189         block_base = block_pos;
    190218
    191219        /* Partial Block or Any Carry */
    192220        if (remaining > 0 || @any_carry) {
     221
     222                        #ifdef PDF_DEBUG
     223                        for(int i = 0; i < remaining; i++)
     224                        {                               
     225                                std::cout << src_buffer[block_base+i];
     226                        }
     227                        #endif
     228
    193229                  EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE-remaining));
    194                   s2p_do_final_block((BytePack *) &src_buffer[block_pos], basis_bits, EOF_mask);
     230                  s2p_do_final_block((BytePack *) &src_buffer[block_base], basis_bits, EOF_mask);
    195231                  @final_block_stmts
    196232
    197 //                postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, (char *)src_buffer, buffer_base, block_base, chars_avail, tracker);
     233      // postprocess_do_block(lex, ctCDPI_Callouts, ref_Callouts, check_streams, (char *)src_buffer, buffer_base, block_base, chars_avail, tracker);
    198234                  blk++;
    199235        }
    200236
    201         buffer_pos += chars_avail;
    202         buffer_base = buffer_pos;
     237        /* Tracked for post processing */
     238        // buffer_pos += chars_avail;
     239        // buffer_base = buffer_pos;
    203240
    204241        PERF_SEC_END(parser_timer, chars_avail);
Note: See TracChangeset for help on using the changeset viewer.