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

Last change on this file since 755 was 755, checked in by ksherdy, 8 years ago

Update template.

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