source: proto/JSON/src/json.c @ 746

Last change on this file since 746 was 746, checked in by ksherdy, 9 years ago

Fix ParityMask? masking.

File size: 23.3 KB
Line 
1#include <string.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7
8#include "../lib/lib_simd.h"
9#include "../lib/block_carry.h"
10#include "../lib/perflib/perfsec.h"
11#include "../lib/s2p.h"
12
13typedef SIMD_type BytePack;
14typedef SIMD_type BitBlock;
15
16#define BLOCK_SIZE (sizeof(SIMD_type) * 8)      /* BLOCK_SIZE           - SIMD register in bits */     
17#define BUFFER_SIZE (BLOCK_SIZE * 16)           /* BUFFER_SIZE          - multiple of BLOCK_SIZE */
18#define OVERLAP_BUFSIZE BLOCK_SIZE              /* OVERLAP_BUFSIZE      - SIMD register width in bytes overlap */
19
20#ifdef BUFFER_PROFILING
21        BOM_Table * perf_timer;
22#elif CODE_CLOCKER
23        #define NUM_EVENTS 1
24        int Events[NUM_EVENTS] = {PAPI_TOT_CYC};
25        //int Events[NUM_EVENTS] = {PAPI_L2_DCM};
26        //int Events[NUM_EVENTS] = {PAPI_TOT_CYC, PAPI_BR_MSP};
27        int cal_size = 20;
28        CC * perf_timer = new CC(Events,NUM_EVENTS,cal_size);
29#else
30        void * perf_timer;
31#endif
32
33void do_process(FILE *infile, FILE *outfile) {
34 
35        /* Compiler generated stream variable declarations. */
36        BitBlock temp40;
37BitBlock temp41;
38BitBlock strct_Lex__RSquareBracket_;
39BitBlock strct_Lex__Ee_;
40BitBlock temp44;
41BitBlock temp45;
42BitBlock temp46;
43BitBlock temp47;
44BitBlock temp48;
45BitBlock temp49;
46BitBlock temp42;
47BitBlock strct_u8__xF4_;
48BitBlock temp43;
49BitBlock strct_Lex__True_;
50BitBlock strct_Lex__Null_;
51BitBlock temp10;
52BitBlock array_bit__2_;
53BitBlock strct_u8__suffix_;
54BitBlock strct_u8__xE0_;
55BitBlock temp59;
56BitBlock temp58;
57BitBlock temp57;
58BitBlock temp56;
59BitBlock temp55;
60BitBlock temp54;
61BitBlock strct_Lex__LSquareBracket_;
62BitBlock temp52;
63BitBlock temp51;
64BitBlock temp50;
65BitBlock strct_Ctrl__CR_;
66BitBlock strct_Lex__f_;
67BitBlock UnescapedDQuotes;
68BitBlock OddFinal;
69BitBlock strct_u8__unibyte_;
70BitBlock array_bit__3_;
71BitBlock strct_u8__xED_;
72BitBlock strct_Ctrl__HT_;
73BitBlock temp28;
74BitBlock temp29;
75BitBlock temp22;
76BitBlock EvenStart;
77BitBlock temp20;
78BitBlock temp21;
79BitBlock temp26;
80BitBlock temp27;
81BitBlock temp24;
82BitBlock temp25;
83BitBlock temp3;
84BitBlock temp2;
85BitBlock temp1;
86BitBlock OddEscape;
87BitBlock temp7;
88BitBlock temp6;
89BitBlock temp5;
90BitBlock temp4;
91BitBlock temp9;
92BitBlock temp8;
93BitBlock strct_Lex__a_;
94BitBlock strct_u8__x80_x8F_;
95BitBlock StringMask;
96BitBlock strct_u8__prefix2_;
97BitBlock array_bit__0_;
98BitBlock temp39;
99BitBlock temp38;
100BitBlock strct_Lex__Minus_;
101BitBlock strct_u8__prefix4_;
102BitBlock temp31;
103BitBlock temp30;
104BitBlock temp33;
105BitBlock temp32;
106BitBlock strct_Lex__LCurlyBrace_;
107BitBlock temp34;
108BitBlock temp37;
109BitBlock temp36;
110BitBlock ParityMask;
111BitBlock AllZero = simd_const_1(0);
112BitBlock temp35;
113BitBlock EvenFinal;
114BitBlock strct_Lex__DQuote_;
115BitBlock EvenEscape;
116BitBlock strct_Lex__RSolidus_;
117//BitBlock Escape;
118BitBlock array_bit__1_;
119BitBlock Even;
120BitBlock array_bit__6_;
121BitBlock strct_Lex__r_;
122BitBlock Start;
123BitBlock strct_u8__xF0_;
124BitBlock strct_Ctrl__x00_x1F_;
125BitBlock strct_u8__x90_xBF_;
126BitBlock strct_u8__badprefix_;
127BitBlock strct_Ctrl__SP_;
128BitBlock strct_Lex__False_;
129BitBlock temp23;
130BitBlock strct_Lex__Digit0_9_;
131BitBlock strct_Lex__Comma_;
132BitBlock array_bit__7_;
133BitBlock strct_Lex__Colon_;
134BitBlock OddStart;
135BitBlock temp53;
136BitBlock strct_Lex__DecimalPoint_;
137BitBlock Escape;
138BitBlock temp88;
139BitBlock temp89;
140BitBlock temp84;
141BitBlock temp85;
142BitBlock temp86;
143BitBlock temp87;
144BitBlock temp80;
145BitBlock temp81;
146BitBlock temp82;
147BitBlock temp83;
148BitBlock strct_u8__xA0_xBF_;
149BitBlock strct_u8__prefix3_;
150BitBlock Odd;
151BitBlock temp66;
152BitBlock temp67;
153BitBlock temp64;
154BitBlock temp65;
155BitBlock temp62;
156BitBlock temp63;
157BitBlock temp60;
158BitBlock temp61;
159BitBlock temp68;
160BitBlock temp69;
161BitBlock strct_Lex__e_;
162BitBlock strct_Lex__PlusMinus_;
163BitBlock strct_Lex__u_;
164BitBlock strct_u8__x80_x9F_;
165BitBlock strct_Lex__Zero_;
166BitBlock temp13;
167BitBlock temp12;
168BitBlock temp11;
169BitBlock array_bit__4_;
170BitBlock temp17;
171BitBlock temp16;
172BitBlock temp15;
173BitBlock temp14;
174BitBlock temp19;
175BitBlock temp18;
176BitBlock temp75;
177BitBlock temp74;
178BitBlock temp77;
179BitBlock temp76;
180BitBlock temp71;
181BitBlock temp70;
182BitBlock temp73;
183BitBlock temp72;
184BitBlock strct_Lex__Number_;
185BitBlock strct_Lex__n_;
186BitBlock strct_Lex__l_;
187BitBlock temp79;
188BitBlock temp78;
189BitBlock strct_u8__prefix_;
190BitBlock strct_Lex__s_;
191BitBlock strct_Lex__WS_;
192BitBlock array_bit__5_;
193BitBlock AllOne = simd_const_1(1);
194BitBlock strct_Lex__t_;
195BitBlock strct_Ctrl__LF_;
196BitBlock StringSpans;
197BitBlock strct_Lex__Escape_;
198BitBlock Temp3;
199BitBlock Temp2;
200BitBlock Temp1;
201BitBlock Temp7;
202BitBlock Temp6;
203BitBlock Temp5;
204BitBlock Temp4;
205BitBlock strct_Lex__HexDigit_;
206BitBlock strct_Lex__RCurlyBrace_;
207BitBlock Temp8;
208BitBlock strct_Lex__Digit1_9_;
209CarryType carry1 = Carry0;
210CarryType carry0 = Carry0;
211CarryType carry3 = Carry0;
212CarryType carry2 = Carry0;
213
214       
215        BitBlock error_mask;
216        BitBlock EOF_mask = simd_const_1(1);
217       
218        /*extra*/
219        /* parse_escape, do not declare, since the PyBit compiler does so by default*/
220        Odd = simd_const_2(1);
221        Even = simd_const_2(2);
222       
223        BitBlock high_bit_mask = sisd_high_bit_mask;   
224        BitBlock high_bit_is_set;
225        // BitBlock ParityMask = simd_const_1(0); // ParityMask declaration via PyBit
226        BitBlock bitblock_parity_mask; 
227       
228        /* 8 * sizeof(SIMD_type) bytes. */
229        BytePack U8[8];
230       
231        /* Source file data is broken into buffers, buffers are broken into blocks, blocks are SIMD register width. */
232        int src_pos = 0;
233        int buf_pos = 0;
234        int err_pos = 0;
235       
236        BytePack buf[(OVERLAP_BUFSIZE+BUFFER_SIZE+OVERLAP_BUFSIZE)/sizeof(SIMD_type)]; 
237        char * srcbuf = ((char *) buf) + OVERLAP_BUFSIZE;
238        memset((unsigned char *)srcbuf,0,16);
239        memset(((unsigned char *)srcbuf)+BUFFER_SIZE,0,16); /* Zero out first and last sizeof(SIMD_type) bytes. */
240       
241        /* File IO */
242        int chars_avail = 0;
243        int chars_read = 0;
244
245        chars_read = fread((void *)srcbuf, 1, BUFFER_SIZE, infile);
246        chars_avail = chars_read;
247        if(ferror(infile)) { fprintf(stderr, "Error: Failed to read input file.\n"); return; }
248        if(chars_avail==0 && feof(infile)) { return; }
249
250       
251       
252        while(1) {
253
254                PERF_SEC_START(perf_timer);
255               
256                while (chars_avail >= BLOCK_SIZE) { /* process full blocks */
257
258                        BytePack * U8 = (BytePack *) &srcbuf[buf_pos];
259
260                        s2p(U8[0], U8[1], U8[2], U8[3], U8[4], U8[5], U8[6], U8[7],
261                        array_bit__0_,array_bit__1_,array_bit__2_,array_bit__3_,array_bit__4_,array_bit__5_,array_bit__6_,array_bit__7_);
262
263                        strct_u8__unibyte_ = simd_andc(AllOne,array_bit__0_);
264strct_u8__prefix_ = simd_and(array_bit__0_,array_bit__1_);
265strct_u8__prefix2_ = simd_andc(strct_u8__prefix_,array_bit__2_);
266temp1 = simd_andc(array_bit__2_,array_bit__3_);
267strct_u8__prefix3_ = simd_and(strct_u8__prefix_,temp1);
268temp2 = simd_and(array_bit__2_,array_bit__3_);
269strct_u8__prefix4_ = simd_and(strct_u8__prefix_,temp2);
270strct_u8__suffix_ = simd_andc(array_bit__0_,array_bit__1_);
271temp3 = simd_or(array_bit__2_,array_bit__3_);
272temp4 = simd_andc(strct_u8__prefix_,temp3);
273temp5 = simd_or(array_bit__4_,array_bit__5_);
274temp6 = simd_or(temp5,array_bit__6_);
275temp7 = simd_andc(temp4,temp6);
276temp8 = simd_or(array_bit__6_,array_bit__7_);
277temp9 = simd_and(array_bit__5_,temp8);
278temp10 = simd_or(array_bit__4_,temp9);
279temp11 = simd_and(strct_u8__prefix4_,temp10);
280strct_u8__badprefix_ = simd_or(temp7,temp11);
281temp12 = simd_or(temp5,temp8);
282strct_u8__xE0_ = simd_andc(strct_u8__prefix3_,temp12);
283temp13 = simd_and(array_bit__4_,array_bit__5_);
284temp14 = simd_andc(array_bit__7_,array_bit__6_);
285temp15 = simd_and(temp13,temp14);
286strct_u8__xED_ = simd_and(strct_u8__prefix3_,temp15);
287strct_u8__xF0_ = simd_andc(strct_u8__prefix4_,temp12);
288temp16 = simd_andc(array_bit__5_,array_bit__4_);
289temp17 = simd_andc(temp16,temp8);
290strct_u8__xF4_ = simd_and(strct_u8__prefix4_,temp17);
291strct_u8__xA0_xBF_ = simd_and(strct_u8__suffix_,array_bit__2_);
292strct_u8__x80_x9F_ = simd_andc(strct_u8__suffix_,array_bit__2_);
293strct_u8__x90_xBF_ = simd_and(strct_u8__suffix_,temp3);
294strct_u8__x80_x8F_ = simd_andc(strct_u8__suffix_,temp3);
295temp18 = simd_or(array_bit__0_,array_bit__1_);
296temp19 = simd_or(temp18,array_bit__2_);
297strct_Ctrl__x00_x1F_ = simd_andc(AllOne,temp19);
298temp20 = simd_or(temp18,temp3);
299strct_Ctrl__CR_ = simd_andc(temp15,temp20);
300temp21 = simd_andc(array_bit__4_,array_bit__5_);
301temp22 = simd_andc(array_bit__6_,array_bit__7_);
302temp23 = simd_and(temp21,temp22);
303strct_Ctrl__LF_ = simd_andc(temp23,temp20);
304temp24 = simd_and(temp21,temp14);
305strct_Ctrl__HT_ = simd_andc(temp24,temp20);
306temp25 = simd_andc(temp1,temp18);
307strct_Ctrl__SP_ = simd_andc(temp25,temp12);
308temp26 = simd_andc(array_bit__1_,array_bit__0_);
309temp27 = simd_and(temp26,temp2);
310temp28 = simd_and(array_bit__6_,array_bit__7_);
311temp29 = simd_and(temp21,temp28);
312strct_Lex__LCurlyBrace_ = simd_and(temp27,temp29);
313temp30 = simd_andc(temp2,temp18);
314strct_Lex__Colon_ = simd_and(temp30,temp23);
315temp31 = simd_andc(temp13,temp8);
316strct_Lex__Comma_ = simd_and(temp25,temp31);
317strct_Lex__RCurlyBrace_ = simd_and(temp27,temp15);
318temp32 = simd_andc(array_bit__3_,array_bit__2_);
319temp33 = simd_and(temp26,temp32);
320strct_Lex__LSquareBracket_ = simd_and(temp33,temp29);
321strct_Lex__RSquareBracket_ = simd_and(temp33,temp15);
322strct_Lex__Minus_ = simd_and(temp25,temp15);
323strct_Lex__Zero_ = simd_andc(temp30,temp12);
324temp34 = simd_or(array_bit__5_,array_bit__6_);
325temp35 = simd_andc(AllOne,temp34);
326temp36 = simd_or(array_bit__5_,temp8);
327Temp1 = simd_and(array_bit__4_,temp35);
328Temp2 = simd_andc(temp36,array_bit__4_);
329temp37 = simd_or(Temp1,Temp2);
330strct_Lex__Digit1_9_ = simd_and(temp30,temp37);
331temp38 = simd_and(array_bit__4_,temp34);
332strct_Lex__Digit0_9_ = simd_andc(temp30,temp38);
333temp39 = simd_and(temp13,temp22);
334strct_Lex__DecimalPoint_ = simd_and(temp25,temp39);
335temp40 = simd_and(temp16,temp14);
336temp41 = simd_andc(temp3,temp1);
337temp42 = simd_andc(temp26,temp41);
338strct_Lex__Ee_ = simd_and(temp40,temp42);
339temp43 = simd_or(temp29,temp15);
340strct_Lex__PlusMinus_ = simd_and(temp25,temp43);
341temp44 = simd_or(strct_Lex__Minus_,strct_Lex__Digit0_9_);
342temp45 = simd_or(temp44,strct_Lex__DecimalPoint_);
343temp46 = simd_andc(temp26,temp3);
344temp47 = simd_and(temp46,temp40);
345temp48 = simd_or(temp45,temp47);
346temp49 = simd_and(temp26,temp1);
347temp50 = simd_and(temp49,temp40);
348temp51 = simd_or(temp48,temp50);
349temp52 = simd_and(temp25,temp29);
350temp53 = simd_or(temp51,temp52);
351strct_Lex__Number_ = simd_or(temp53,strct_Lex__Minus_);
352temp54 = simd_andc(temp22,temp5);
353strct_Lex__DQuote_ = simd_and(temp25,temp54);
354strct_Lex__RSolidus_ = simd_and(temp33,temp31);
355strct_Lex__u_ = simd_and(temp27,temp40);
356temp55 = simd_or(strct_Lex__DQuote_,strct_Lex__RSolidus_);
357temp56 = simd_and(temp13,temp28);
358temp57 = simd_and(temp25,temp56);
359temp58 = simd_or(temp55,temp57);
360temp59 = simd_and(temp49,temp54);
361temp60 = simd_or(temp58,temp59);
362temp61 = simd_and(temp16,temp22);
363temp62 = simd_and(temp49,temp61);
364temp63 = simd_or(temp60,temp62);
365temp64 = simd_and(temp49,temp39);
366temp65 = simd_or(temp63,temp64);
367temp66 = simd_and(temp27,temp54);
368temp67 = simd_or(temp65,temp66);
369temp68 = simd_and(temp27,temp17);
370temp69 = simd_or(temp67,temp68);
371strct_Lex__Escape_ = simd_or(temp69,strct_Lex__u_);
372temp70 = simd_andc(temp49,array_bit__4_);
373temp71 = simd_andc(AllOne,temp28);
374Temp3 = simd_and(array_bit__5_,temp71);
375Temp4 = simd_andc(temp8,array_bit__5_);
376temp72 = simd_or(Temp3,Temp4);
377temp73 = simd_and(temp70,temp72);
378temp74 = simd_or(strct_Lex__Digit0_9_,temp73);
379temp75 = simd_andc(temp46,array_bit__4_);
380temp76 = simd_and(temp75,temp72);
381strct_Lex__HexDigit_ = simd_or(temp74,temp76);
382temp77 = simd_or(temp15,temp23);
383temp78 = simd_or(temp77,temp24);
384temp79 = simd_andc(temp78,temp20);
385strct_Lex__WS_ = simd_or(temp79,strct_Ctrl__SP_);
386strct_Lex__t_ = temp68;
387strct_Lex__r_ = temp66;
388strct_Lex__e_ = temp50;
389temp80 = simd_or(temp17,temp54);
390temp81 = simd_or(temp80,temp40);
391temp82 = simd_and(temp27,temp81);
392strct_Lex__True_ = simd_or(temp82,temp50);
393strct_Lex__f_ = temp62;
394temp83 = simd_andc(temp14,temp5);
395strct_Lex__a_ = simd_and(temp49,temp83);
396strct_Lex__l_ = simd_and(temp49,temp31);
397temp84 = simd_andc(temp28,temp5);
398strct_Lex__s_ = simd_and(temp27,temp84);
399temp85 = simd_or(temp61,temp83);
400temp86 = simd_or(temp85,temp31);
401temp87 = simd_and(temp49,temp86);
402temp88 = simd_or(temp87,strct_Lex__s_);
403strct_Lex__False_ = simd_or(temp88,temp50);
404strct_Lex__n_ = temp64;
405temp89 = simd_or(temp64,strct_Lex__u_);
406strct_Lex__Null_ = simd_or(temp89,strct_Lex__l_);
407advance_with_carry(strct_Lex__RSolidus_, carry0, Temp5);
408Start = simd_andc(strct_Lex__RSolidus_,Temp5);
409EvenStart = simd_and(Start,Even);
410adc128(EvenStart, strct_Lex__RSolidus_, carry1, Temp6);
411EvenFinal = simd_andc(Temp6,strct_Lex__RSolidus_);
412EvenEscape = simd_and(EvenFinal,Odd);
413OddStart = simd_and(Start,Odd);
414adc128(OddStart, strct_Lex__RSolidus_, carry2, Temp7);
415OddFinal = simd_andc(Temp7,strct_Lex__RSolidus_);
416OddEscape = simd_and(OddFinal,Even);
417Escape = simd_or(EvenEscape,OddEscape);
418UnescapedDQuotes = simd_andc(strct_Lex__DQuote_,Escape);
419
420                        /* Generate Parity Mask */
421                        high_bit_mask = sisd_high_bit_mask;
422                        high_bit_is_set = simd_and(high_bit_mask, bitblock_parity_mask);                       
423                        bitblock_parity_mask = sisd_add( simd_not(sisd_srl(high_bit_is_set, sisd_from_int(BLOCK_SIZE-1))) , sisd_low_bit_mask);                                         
424                        ParityMask = bitblock_parallel_prefix_parity(UnescapedDQuotes, bitblock_parity_mask);
425
426advance_with_carry(ParityMask, carry3, Temp8);
427StringMask = simd_and(ParityMask,Temp8);
428StringSpans = simd_or(StringMask,UnescapedDQuotes);
429
430
431                        /* strct_Lex__Null_ = simd_or(temp89,strct_Lex__l_); */
432                        print_array_le("Data", &srcbuf[buf_pos],BLOCK_SIZE);
433                        print_simd_register("Escape", Escape);
434                       
435
436                       
437                        print_simd_register("Unescaped DQuote",UnescapedDQuotes);
438                        /*
439                        print_simd_register("high_bit_is_set", high_bit_is_set);
440                        print_simd_register("high_bit_mask", high_bit_mask);
441                        */
442                        print_simd_register("ParityMask", ParityMask);
443                        print_simd_register("StringMask", StringMask);
444                        print_simd_register("StringSpans", StringSpans);                                               
445                       
446                        if (bitblock_has_bit(error_mask)){
447                                err_pos = src_pos + buf_pos + count_forward_zeroes(error_mask);
448                                fprintf(stderr, "Error at position %i\n.", err_pos);
449                                exit(-1);
450                        }
451
452                        chars_avail -= BLOCK_SIZE;
453                        buf_pos += BLOCK_SIZE;
454                }               
455               
456                if(chars_avail > 0 /* || any_carry */) { /* process final partial block */
457                        /* extra */
458                        EOF_mask = sisd_srl(simd_const_1(1),sisd_from_int(BLOCK_SIZE-chars_avail));
459                                               
460                        BytePack * U8 = (BytePack *) &srcbuf[buf_pos];
461                       
462                        s2p(U8[0], U8[1], U8[2], U8[3], U8[4], U8[5], U8[6], U8[7],
463                        array_bit__0_,array_bit__1_,array_bit__2_,array_bit__3_,array_bit__4_,array_bit__5_,array_bit__6_,array_bit__7_);
464
465                        array_bit__0_ = simd_and(array_bit__0_, EOF_mask);
466                        array_bit__1_ = simd_and(array_bit__1_, EOF_mask);
467                        array_bit__2_ = simd_and(array_bit__2_, EOF_mask);
468                        array_bit__3_ = simd_and(array_bit__3_, EOF_mask);
469                        array_bit__4_ = simd_and(array_bit__4_, EOF_mask);
470                        array_bit__5_ = simd_and(array_bit__5_, EOF_mask);
471                        array_bit__6_ = simd_and(array_bit__6_, EOF_mask);
472                        array_bit__7_ = simd_and(array_bit__7_, EOF_mask);
473                       
474                        strct_u8__unibyte_ = simd_andc(AllOne,array_bit__0_);
475strct_u8__prefix_ = simd_and(array_bit__0_,array_bit__1_);
476strct_u8__prefix2_ = simd_andc(strct_u8__prefix_,array_bit__2_);
477temp1 = simd_andc(array_bit__2_,array_bit__3_);
478strct_u8__prefix3_ = simd_and(strct_u8__prefix_,temp1);
479temp2 = simd_and(array_bit__2_,array_bit__3_);
480strct_u8__prefix4_ = simd_and(strct_u8__prefix_,temp2);
481strct_u8__suffix_ = simd_andc(array_bit__0_,array_bit__1_);
482temp3 = simd_or(array_bit__2_,array_bit__3_);
483temp4 = simd_andc(strct_u8__prefix_,temp3);
484temp5 = simd_or(array_bit__4_,array_bit__5_);
485temp6 = simd_or(temp5,array_bit__6_);
486temp7 = simd_andc(temp4,temp6);
487temp8 = simd_or(array_bit__6_,array_bit__7_);
488temp9 = simd_and(array_bit__5_,temp8);
489temp10 = simd_or(array_bit__4_,temp9);
490temp11 = simd_and(strct_u8__prefix4_,temp10);
491strct_u8__badprefix_ = simd_or(temp7,temp11);
492temp12 = simd_or(temp5,temp8);
493strct_u8__xE0_ = simd_andc(strct_u8__prefix3_,temp12);
494temp13 = simd_and(array_bit__4_,array_bit__5_);
495temp14 = simd_andc(array_bit__7_,array_bit__6_);
496temp15 = simd_and(temp13,temp14);
497strct_u8__xED_ = simd_and(strct_u8__prefix3_,temp15);
498strct_u8__xF0_ = simd_andc(strct_u8__prefix4_,temp12);
499temp16 = simd_andc(array_bit__5_,array_bit__4_);
500temp17 = simd_andc(temp16,temp8);
501strct_u8__xF4_ = simd_and(strct_u8__prefix4_,temp17);
502strct_u8__xA0_xBF_ = simd_and(strct_u8__suffix_,array_bit__2_);
503strct_u8__x80_x9F_ = simd_andc(strct_u8__suffix_,array_bit__2_);
504strct_u8__x90_xBF_ = simd_and(strct_u8__suffix_,temp3);
505strct_u8__x80_x8F_ = simd_andc(strct_u8__suffix_,temp3);
506temp18 = simd_or(array_bit__0_,array_bit__1_);
507temp19 = simd_or(temp18,array_bit__2_);
508strct_Ctrl__x00_x1F_ = simd_andc(AllOne,temp19);
509temp20 = simd_or(temp18,temp3);
510strct_Ctrl__CR_ = simd_andc(temp15,temp20);
511temp21 = simd_andc(array_bit__4_,array_bit__5_);
512temp22 = simd_andc(array_bit__6_,array_bit__7_);
513temp23 = simd_and(temp21,temp22);
514strct_Ctrl__LF_ = simd_andc(temp23,temp20);
515temp24 = simd_and(temp21,temp14);
516strct_Ctrl__HT_ = simd_andc(temp24,temp20);
517temp25 = simd_andc(temp1,temp18);
518strct_Ctrl__SP_ = simd_andc(temp25,temp12);
519temp26 = simd_andc(array_bit__1_,array_bit__0_);
520temp27 = simd_and(temp26,temp2);
521temp28 = simd_and(array_bit__6_,array_bit__7_);
522temp29 = simd_and(temp21,temp28);
523strct_Lex__LCurlyBrace_ = simd_and(temp27,temp29);
524temp30 = simd_andc(temp2,temp18);
525strct_Lex__Colon_ = simd_and(temp30,temp23);
526temp31 = simd_andc(temp13,temp8);
527strct_Lex__Comma_ = simd_and(temp25,temp31);
528strct_Lex__RCurlyBrace_ = simd_and(temp27,temp15);
529temp32 = simd_andc(array_bit__3_,array_bit__2_);
530temp33 = simd_and(temp26,temp32);
531strct_Lex__LSquareBracket_ = simd_and(temp33,temp29);
532strct_Lex__RSquareBracket_ = simd_and(temp33,temp15);
533strct_Lex__Minus_ = simd_and(temp25,temp15);
534strct_Lex__Zero_ = simd_andc(temp30,temp12);
535temp34 = simd_or(array_bit__5_,array_bit__6_);
536temp35 = simd_andc(AllOne,temp34);
537temp36 = simd_or(array_bit__5_,temp8);
538Temp1 = simd_and(array_bit__4_,temp35);
539Temp2 = simd_andc(temp36,array_bit__4_);
540temp37 = simd_or(Temp1,Temp2);
541strct_Lex__Digit1_9_ = simd_and(temp30,temp37);
542temp38 = simd_and(array_bit__4_,temp34);
543strct_Lex__Digit0_9_ = simd_andc(temp30,temp38);
544temp39 = simd_and(temp13,temp22);
545strct_Lex__DecimalPoint_ = simd_and(temp25,temp39);
546temp40 = simd_and(temp16,temp14);
547temp41 = simd_andc(temp3,temp1);
548temp42 = simd_andc(temp26,temp41);
549strct_Lex__Ee_ = simd_and(temp40,temp42);
550temp43 = simd_or(temp29,temp15);
551strct_Lex__PlusMinus_ = simd_and(temp25,temp43);
552temp44 = simd_or(strct_Lex__Minus_,strct_Lex__Digit0_9_);
553temp45 = simd_or(temp44,strct_Lex__DecimalPoint_);
554temp46 = simd_andc(temp26,temp3);
555temp47 = simd_and(temp46,temp40);
556temp48 = simd_or(temp45,temp47);
557temp49 = simd_and(temp26,temp1);
558temp50 = simd_and(temp49,temp40);
559temp51 = simd_or(temp48,temp50);
560temp52 = simd_and(temp25,temp29);
561temp53 = simd_or(temp51,temp52);
562strct_Lex__Number_ = simd_or(temp53,strct_Lex__Minus_);
563temp54 = simd_andc(temp22,temp5);
564strct_Lex__DQuote_ = simd_and(temp25,temp54);
565strct_Lex__RSolidus_ = simd_and(temp33,temp31);
566strct_Lex__u_ = simd_and(temp27,temp40);
567temp55 = simd_or(strct_Lex__DQuote_,strct_Lex__RSolidus_);
568temp56 = simd_and(temp13,temp28);
569temp57 = simd_and(temp25,temp56);
570temp58 = simd_or(temp55,temp57);
571temp59 = simd_and(temp49,temp54);
572temp60 = simd_or(temp58,temp59);
573temp61 = simd_and(temp16,temp22);
574temp62 = simd_and(temp49,temp61);
575temp63 = simd_or(temp60,temp62);
576temp64 = simd_and(temp49,temp39);
577temp65 = simd_or(temp63,temp64);
578temp66 = simd_and(temp27,temp54);
579temp67 = simd_or(temp65,temp66);
580temp68 = simd_and(temp27,temp17);
581temp69 = simd_or(temp67,temp68);
582strct_Lex__Escape_ = simd_or(temp69,strct_Lex__u_);
583temp70 = simd_andc(temp49,array_bit__4_);
584temp71 = simd_andc(AllOne,temp28);
585Temp3 = simd_and(array_bit__5_,temp71);
586Temp4 = simd_andc(temp8,array_bit__5_);
587temp72 = simd_or(Temp3,Temp4);
588temp73 = simd_and(temp70,temp72);
589temp74 = simd_or(strct_Lex__Digit0_9_,temp73);
590temp75 = simd_andc(temp46,array_bit__4_);
591temp76 = simd_and(temp75,temp72);
592strct_Lex__HexDigit_ = simd_or(temp74,temp76);
593temp77 = simd_or(temp15,temp23);
594temp78 = simd_or(temp77,temp24);
595temp79 = simd_andc(temp78,temp20);
596strct_Lex__WS_ = simd_or(temp79,strct_Ctrl__SP_);
597strct_Lex__t_ = temp68;
598strct_Lex__r_ = temp66;
599strct_Lex__e_ = temp50;
600temp80 = simd_or(temp17,temp54);
601temp81 = simd_or(temp80,temp40);
602temp82 = simd_and(temp27,temp81);
603strct_Lex__True_ = simd_or(temp82,temp50);
604strct_Lex__f_ = temp62;
605temp83 = simd_andc(temp14,temp5);
606strct_Lex__a_ = simd_and(temp49,temp83);
607strct_Lex__l_ = simd_and(temp49,temp31);
608temp84 = simd_andc(temp28,temp5);
609strct_Lex__s_ = simd_and(temp27,temp84);
610temp85 = simd_or(temp61,temp83);
611temp86 = simd_or(temp85,temp31);
612temp87 = simd_and(temp49,temp86);
613temp88 = simd_or(temp87,strct_Lex__s_);
614strct_Lex__False_ = simd_or(temp88,temp50);
615strct_Lex__n_ = temp64;
616temp89 = simd_or(temp64,strct_Lex__u_);
617strct_Lex__Null_ = simd_or(temp89,strct_Lex__l_);
618advance_with_carry(strct_Lex__RSolidus_, carry0, Temp5);
619Start = simd_andc(strct_Lex__RSolidus_,Temp5);
620EvenStart = simd_and(Start,Even);
621adc128(EvenStart, strct_Lex__RSolidus_, carry1, Temp6);
622EvenFinal = simd_andc(Temp6,strct_Lex__RSolidus_);
623EvenEscape = simd_and(EvenFinal,Odd);
624OddStart = simd_and(Start,Odd);
625adc128(OddStart, strct_Lex__RSolidus_, carry2, Temp7);
626OddFinal = simd_andc(Temp7,strct_Lex__RSolidus_);
627OddEscape = simd_and(OddFinal,Even);
628Escape = simd_or(EvenEscape,OddEscape);
629UnescapedDQuotes = simd_andc(strct_Lex__DQuote_,Escape);
630
631                        /* Generate Parity Mask */
632                        high_bit_mask = sisd_srl(sisd_high_bit_mask, sisd_from_int(BLOCK_SIZE-chars_avail));
633                        high_bit_is_set = simd_and(high_bit_mask, bitblock_parity_mask);
634                        bitblock_parity_mask = sisd_add(simd_not(sisd_srl(high_bit_is_set, sisd_from_int(chars_avail-1))) , sisd_low_bit_mask);                 
635                        ParityMask = bitblock_parallel_prefix_parity(UnescapedDQuotes, bitblock_parity_mask);
636                        ParityMask = simd_and(ParityMask, EOF_mask);
637
638advance_with_carry(ParityMask, carry3, Temp8);
639StringMask = simd_and(ParityMask,Temp8);
640StringSpans = simd_or(StringMask,UnescapedDQuotes);
641
642
643                        /* strct_Lex__Null_ = simd_or(temp89,strct_Lex__l_); */
644                        print_array_le("Data", &srcbuf[buf_pos],BLOCK_SIZE);
645                        print_simd_register("Escape", Escape);
646                       
647
648                       
649                       
650                        print_simd_register("Unescaped DQuote",UnescapedDQuotes);
651                       
652                        print_simd_register("high_bit_is_set", high_bit_is_set);
653                        print_simd_register("high_bit_mask", high_bit_mask);
654                       
655                        print_simd_register("ParityMask", ParityMask);
656                        print_simd_register("StringMask", StringMask);
657                        print_simd_register("StringSpans", StringSpans);                       
658                       
659                        if(bitblock_has_bit(error_mask)) {
660                                err_pos = src_pos + buf_pos + count_forward_zeroes(error_mask);
661                                fprintf(stderr, "Error at position %i\n.", err_pos);
662                                exit(-1);
663                        }
664                }
665               
666                PERF_SEC_END(perf_timer, chars_avail);
667
668                src_pos += chars_read;
669                buf_pos = 0;
670
671                chars_read = fread((void *)srcbuf, 1, BUFFER_SIZE, infile);
672                chars_avail = chars_read;
673                if(ferror(infile)) { fprintf(stderr, "Failed to read input file.\n"); return; }
674                if(chars_avail==0 && feof(infile)) { return; } 
675        }
676}
677
678int main(int argc, char * argv[]) {
679        char * infilename, * outfilename;       
680        FILE *infile, *outfile;
681        struct stat fileinfo;
682
683        if (argc < 2) {
684                printf("Usage: %s <filename> [<outputfile>]\n", argv[0]);
685                exit(-1);
686        }
687
688        infilename = argv[1];
689        stat(infilename, &fileinfo);
690        infile = fopen(infilename, "rb");
691        if (!infile) {
692                fprintf(stderr, "Error: Cannot open %s for reading.\n", infilename);
693                exit(-1);
694        }
695       
696        if (argc < 3) {
697                outfile = stdout;
698        }       else {
699                outfilename = argv[2];
700                outfile = fopen(outfilename, "wb");
701                if (!outfile) {
702                        fprintf(stderr, "Error: Cannot open %s for writing.\n", outfilename);
703                        exit(-1);
704                }
705        }
706
707        // PERF_SEC_BIND(1);
708
709        PERF_SEC_INIT(perf_timer);
710
711        do_process(infile, outfile);
712       
713        PERF_SEC_DUMP(perf_timer);
714       
715        PERF_SEC_DESTROY(perf_timer);
716
717        fclose(infile);
718        fclose(outfile);
719       
720        return(0);
721}
Note: See TracBrowser for help on using the repository browser.