Changeset 1673 for GPU


Ignore:
Timestamp:
Nov 8, 2011, 5:44:33 PM (8 years ago)
Author:
lindanl
Message:

Parabix on GPU : Add ref, tag, name and check functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • GPU/xmlwf.cl

    r1669 r1673  
    140140}
    141141
    142 static inline BitBlock scanthru(int idx, BitBlock markers, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
     142inline BitBlock scanthru(int idx, BitBlock markers, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
    143143        return simd_andc(adc(idx, markers, charclass, carry, bubble, group_carry, carryno), charclass);
    144144}
    145145
    146 static inline BitBlock scanto(int idx, BitBlock markers, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
     146inline BitBlock scanto(int idx, BitBlock markers, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
    147147        return simd_and(adc(idx, markers, simd_not(charclass), carry, bubble, group_carry, carryno), charclass);
    148148}
    149149
    150 static inline BitBlock scantofirst(int idx, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
     150inline BitBlock scantofirst(int idx, BitBlock charclass, __local BitBlock *carry, __local BitBlock *bubble, BitBlock *group_carry, const int carryno) {
    151151        BitBlock marker;
    152152        group_carry[carryno] = simd_xor(group_carry[carryno], 1);
     
    161161}
    162162
    163 static inline int CarryTest(BitBlock * cq, const int carryno, const int carry_count) {
     163inline int CarryTest(BitBlock * cq, const int carryno, const int carry_count) {
    164164  BitBlock c1 = cq[carryno];
    165165  for (int i = carryno + 1; i < carryno + carry_count; i++) {
     
    169169}
    170170
    171 static inline void CarryCombine(BitBlock * cq, BitBlock * local_cq, const int carryno, const int carry_count) {
     171inline void CarryCombine(BitBlock * cq, BitBlock * local_cq, const int carryno, const int carry_count) {
    172172  for (int i = 0; i < carry_count; i++) {
    173173    cq[carryno+i] = simd_or(cq[carryno+i], local_cq[i]);
     
    243243  BitBlock CtCDPI_mask;
    244244  BitBlock error;
     245};
     246
     247  struct Ref_Callouts {
     248  BitBlock GenRef_starts;
     249  BitBlock GenRef_ends;
     250  BitBlock DecRef_starts;
     251  BitBlock DecRef_ends;
     252  BitBlock HexRef_starts;
     253  BitBlock HexRef_ends;
     254  BitBlock error;
     255};
     256
     257  struct Tag_Callouts {
     258  BitBlock ElemName_starts;
     259  BitBlock ElemName_ends;
     260  BitBlock AttName_starts;
     261  BitBlock AttName_ends;
     262  BitBlock AttVal_starts;
     263  BitBlock AttVal_ends;
     264  BitBlock AttVal_spans;
     265  BitBlock EmptyTag_marks;
     266  BitBlock EndTag_marks;
     267  BitBlock LAngleFollow;
     268  BitBlock error;
     269};
     270
     271  struct Check_streams {
     272  BitBlock non_ascii_name_starts;
     273  BitBlock non_ascii_names;
     274  BitBlock tag_marks;
     275  BitBlock name_follows;
     276  BitBlock att_refs;
     277  BitBlock error_mask;
     278};
     279
     280  struct Xml_names {
     281  BitBlock namespace_error;
    245282};
    246283
     
    523560  } while (0)
    524561
     562#define parse_refs(idx, lex, scope1, ctCDPI_Callouts, ref_Callouts, carry, bubble, group_carry)\
     563 do {\
     564                BitBlock Ref1, NumRef2, NumRef3, HexRef3, ref_error1, ref_error2, ref_ends;\
     565                BitBlock ref_error3;\
     566\
     567        ref_Callouts.GenRef_starts = simd_const_1(0);\
     568        ref_Callouts.GenRef_ends = simd_const_1(0);\
     569        ref_Callouts.DecRef_starts = simd_const_1(0);\
     570        ref_Callouts.DecRef_ends = simd_const_1(0);\
     571        ref_Callouts.HexRef_starts = simd_const_1(0);\
     572        ref_Callouts.HexRef_ends = simd_const_1(0);\
     573        ref_Callouts.error = simd_const_1(0);\
     574        Ref1 = simd_andc(lex.RefStart, ctCDPI_Callouts.CtCDPI_mask);\
     575        if ((bitblock_has_bit(Ref1) || CarryTest(group_carry, 0, 6))) {\
     576          scope1.RefStart = advance(idx, Ref1, carry, group_carry, 0);\
     577          NumRef2 = simd_and(scope1.RefStart, lex.Hash);\
     578          ref_Callouts.GenRef_starts = simd_andc(scope1.RefStart, lex.Hash);\
     579          NumRef3 = advance(idx, NumRef2, carry, group_carry, 1);\
     580          HexRef3 = simd_and(NumRef3, lex.x);\
     581          ref_Callouts.DecRef_starts = simd_andc(NumRef3, lex.x);\
     582          ref_Callouts.HexRef_starts = advance(idx, HexRef3, carry, group_carry, 2);\
     583          ref_Callouts.GenRef_ends = scanthru(idx, ref_Callouts.GenRef_starts, lex.NameScan, carry, bubble, group_carry, 3);\
     584          ref_Callouts.DecRef_ends = scanthru(idx, ref_Callouts.DecRef_starts, lex.Digit, carry, bubble, group_carry, 4);\
     585          ref_Callouts.HexRef_ends = scanthru(idx, ref_Callouts.HexRef_starts, lex.Hex, carry, bubble, group_carry, 5);\
     586          ref_error1 = simd_andc(ref_Callouts.DecRef_starts, lex.Digit);\
     587          ref_error2 = simd_andc(ref_Callouts.HexRef_starts, lex.Hex);\
     588          ref_ends = simd_or(simd_or(ref_Callouts.GenRef_ends, ref_Callouts.DecRef_ends), ref_Callouts.HexRef_ends);\
     589          ref_error3 = simd_andc(ref_ends, lex.Semicolon);\
     590          ref_Callouts.error = simd_or(simd_or(ref_error1, ref_error2), ref_error3);\
     591        }\
     592  } while (0)
     593
     594 #define parse_tags(idx, lex, scope1, ctCDPI_Callouts, tag_Callouts, carry, bubble, group_carry)\
     595 do {\
     596                BitBlock DQuoteDelim, SQuoteDelim, AttListDelim, ParseError, EqToCheck;\
     597                BitBlock AttValEnds, AfterWS, AttListEnd, AttNameStart, AttNameFollow;\
     598                BitBlock EqExpected, AttValPos, DQuoteAttVal, SQuoteAttVal, DQuoteAttEnd;\
     599                BitBlock SQuoteAttEnd, AttValEnd, AttValFollow, STagEnds, EndTagEnds;\
     600\
     601        DQuoteDelim = simd_or(lex.DQuote, lex.LAngle);\
     602        SQuoteDelim = simd_or(lex.SQuote, lex.LAngle);\
     603        AttListDelim = simd_or(lex.Slash, lex.RAngle);\
     604        tag_Callouts.LAngleFollow = simd_andc(scope1.LAngle, ctCDPI_Callouts.CtCDPI_mask);\
     605        tag_Callouts.ElemName_starts = simd_andc(tag_Callouts.LAngleFollow, lex.Slash);\
     606        tag_Callouts.EndTag_marks = simd_and(tag_Callouts.LAngleFollow, lex.Slash);\
     607        tag_Callouts.ElemName_ends = scanthru(idx, tag_Callouts.ElemName_starts, lex.NameScan, carry, bubble, group_carry, 0);\
     608        ParseError = simd_and(tag_Callouts.ElemName_starts, tag_Callouts.ElemName_ends);\
     609        tag_Callouts.AttName_starts = simd_const_1(0);\
     610        tag_Callouts.AttName_ends = simd_const_1(0);\
     611        EqToCheck = simd_const_1(0);\
     612        tag_Callouts.AttVal_starts = simd_const_1(0);\
     613        AttValEnds = simd_const_1(0);\
     614        tag_Callouts.AttVal_ends = simd_const_1(0);\
     615        AfterWS = scanthru(idx, tag_Callouts.ElemName_ends, lex.WS, carry, bubble, group_carry, 1);\
     616        AttListEnd = simd_and(AfterWS, AttListDelim);\
     617        AttNameStart = simd_andc(AfterWS, AttListDelim);\
     618        ParseError = simd_or(ParseError, simd_and(tag_Callouts.ElemName_ends, AttNameStart));\
     619        if ((bitblock_has_bit(AttNameStart) || CarryTest(group_carry, 2, 7))) {\
     620          tag_Callouts.AttName_starts = simd_or(tag_Callouts.AttName_starts, AttNameStart);\
     621          AttNameFollow = scanthru(idx, AttNameStart, lex.NameScan, carry, bubble, group_carry, 2);\
     622          tag_Callouts.AttName_ends = simd_or(tag_Callouts.AttName_ends, AttNameFollow);\
     623          EqExpected = scanthru(idx, AttNameFollow, lex.WS, carry, bubble, group_carry, 3);\
     624          EqToCheck = simd_or(EqToCheck, EqExpected);\
     625          AttValPos = scanthru(idx, EqExpected, simd_or(EqExpected, lex.WS), carry, bubble, group_carry, 4);\
     626          tag_Callouts.AttVal_starts = simd_or(tag_Callouts.AttVal_starts, AttValPos);\
     627          DQuoteAttVal = simd_and(AttValPos, lex.DQuote);\
     628          SQuoteAttVal = simd_and(AttValPos, lex.SQuote);\
     629          DQuoteAttEnd = scanto(idx, DQuoteAttVal, simd_andc(DQuoteDelim, DQuoteAttVal), carry, bubble, group_carry, 5);\
     630          SQuoteAttEnd = scanto(idx, SQuoteAttVal, simd_andc(SQuoteDelim, SQuoteAttVal), carry, bubble, group_carry, 6);\
     631          AttValEnd = simd_or(DQuoteAttEnd, SQuoteAttEnd);\
     632          AttValEnds = simd_or(AttValEnds, AttValEnd);\
     633          AttValFollow = advance(idx, AttValEnd, carry, group_carry, 7);\
     634          tag_Callouts.AttVal_ends = simd_or(tag_Callouts.AttVal_ends, AttValFollow);\
     635          AfterWS = scanthru(idx, AttValFollow, lex.WS, carry, bubble, group_carry, 8);\
     636          AttListEnd = simd_or(AttListEnd, simd_and(AfterWS, AttListDelim));\
     637          AttNameStart = simd_andc(AfterWS, AttListDelim);\
     638          while (bitblock_has_bit(AttNameStart)) {\
     639            BitBlock subcarryQ[7];\
     640            CarryInit(subcarryQ, 7);\
     641            tag_Callouts.AttName_starts = simd_or(tag_Callouts.AttName_starts, AttNameStart);\
     642            AttNameFollow = scanthru(idx, AttNameStart, lex.NameScan, carry, bubble, subcarryQ, 0);\
     643            tag_Callouts.AttName_ends = simd_or(tag_Callouts.AttName_ends, AttNameFollow);\
     644            EqExpected = scanthru(idx, AttNameFollow, lex.WS,  carry, bubble, subcarryQ, 1);\
     645            EqToCheck = simd_or(EqToCheck, EqExpected);\
     646            AttValPos = scanthru(idx, EqExpected, simd_or(EqExpected, lex.WS), carry, bubble, subcarryQ, 2);\
     647            tag_Callouts.AttVal_starts = simd_or(tag_Callouts.AttVal_starts, AttValPos);\
     648            DQuoteAttVal = simd_and(AttValPos, lex.DQuote);\
     649            SQuoteAttVal = simd_and(AttValPos, lex.SQuote);\
     650            DQuoteAttEnd = scanto(idx, DQuoteAttVal, simd_andc(DQuoteDelim, DQuoteAttVal), carry, bubble, subcarryQ, 3);\
     651            SQuoteAttEnd = scanto(idx, SQuoteAttVal, simd_andc(SQuoteDelim, SQuoteAttVal), carry, bubble, subcarryQ, 4);\
     652            AttValEnd = simd_or(DQuoteAttEnd, SQuoteAttEnd);\
     653            AttValEnds = simd_or(AttValEnds, AttValEnd);\
     654            AttValFollow = advance(idx, AttValEnd,  carry, subcarryQ, 5);\
     655            tag_Callouts.AttVal_ends = simd_or(tag_Callouts.AttVal_ends, AttValFollow);\
     656            AfterWS = scanthru(idx, AttValFollow, lex.WS,  carry, bubble, subcarryQ, 6);\
     657            AttListEnd = simd_or(AttListEnd, simd_and(AfterWS, AttListDelim));\
     658            AttNameStart = simd_andc(AfterWS, AttListDelim);\
     659            CarryCombine(group_carry, subcarryQ, 2, 7);\
     660          }\
     661        }\
     662        STagEnds = simd_and(AttListEnd, lex.RAngle);\
     663        tag_Callouts.EmptyTag_marks = advance(idx, simd_and(AttListEnd, lex.Slash), carry, group_carry, 9);\
     664        ParseError = simd_or(ParseError, simd_and(tag_Callouts.AttVal_ends, tag_Callouts.AttName_starts));\
     665        ParseError = simd_or(ParseError, simd_and(tag_Callouts.AttName_starts, tag_Callouts.AttName_ends));\
     666        ParseError = simd_or(ParseError, simd_andc(EqToCheck, lex.Equals));\
     667        ParseError = simd_or(ParseError, simd_andc(tag_Callouts.AttVal_starts, simd_or(lex.DQuote, lex.SQuote)));\
     668        ParseError = simd_or(ParseError, simd_andc(AttValEnds, simd_or(lex.DQuote, lex.SQuote)));\
     669        ParseError = simd_or(ParseError, simd_andc(tag_Callouts.EmptyTag_marks, lex.RAngle));\
     670        EndTagEnds = scanthru(idx, scanthru(idx, tag_Callouts.EndTag_marks, simd_or(tag_Callouts.EndTag_marks, lex.NameScan), carry, bubble, group_carry, 10), lex.WS, carry, bubble, group_carry, 11);\
     671        ParseError = simd_or(ParseError, simd_andc(EndTagEnds, lex.RAngle));\
     672        tag_Callouts.error = ParseError;\
     673        tag_Callouts.AttVal_spans = sbb(idx, tag_Callouts.AttVal_ends, tag_Callouts.AttVal_starts, carry, bubble, group_carry, 12);\
     674  } while (0)
     675
     676   #define validate_xml_names(idx, ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams, carry, bubble, group_carry)\
     677 do {\
     678                BitBlock PI_names, GenRefs, ElemNames, AttNames, qname_stream, ncname_stream;\
     679                BitBlock name_stream, name_start, name_cursor, void_prefix_err, namespace_sep;\
     680                BitBlock local_part_start, local_part_err, colon2_err, ncname_err;\
     681\
     682        PI_names = sbb(idx, ctCDPI_Callouts.PI_name_ends, ctCDPI_Callouts.PI_name_starts, carry, bubble, group_carry, 0);\
     683        GenRefs = sbb(idx, ref_Callouts.GenRef_ends, ref_Callouts.GenRef_starts, carry, bubble, group_carry, 1);\
     684        ElemNames = sbb(idx, tag_Callouts.ElemName_ends, tag_Callouts.ElemName_starts, carry, bubble, group_carry, 2);\
     685        AttNames = sbb(idx, tag_Callouts.AttName_ends, tag_Callouts.AttName_starts, carry, bubble, group_carry, 3);\
     686        qname_stream = simd_or(ElemNames, AttNames);\
     687        ncname_stream = simd_or(PI_names, GenRefs);\
     688        name_stream = simd_or(qname_stream, ncname_stream);\
     689        name_start = simd_andc(name_stream, advance(idx, name_stream, carry, group_carry, 4));\
     690        name_cursor = simd_andc(name_stream, advance(idx, name_stream, carry, group_carry, 5));\
     691        void_prefix_err = simd_and(name_cursor, lex.Colon);\
     692        namespace_sep = simd_and(scanthru(idx, name_cursor, simd_andc(lex.NameScan, lex.Colon), carry, bubble, group_carry, 6), lex.Colon);\
     693        local_part_start = advance(idx, namespace_sep, carry, group_carry, 7);\
     694        local_part_err = simd_andc(local_part_start, lex.NameScan);\
     695        colon2_err = simd_and(scanthru(idx, local_part_start, simd_andc(lex.NameScan, lex.Colon), carry, bubble, group_carry, 8), lex.Colon);\
     696        ncname_err = simd_and(ncname_stream, lex.Colon);\
     697        xml_names.namespace_error = simd_or(simd_or(simd_or(void_prefix_err, local_part_err), colon2_err), ncname_err);\
     698        check_streams.non_ascii_name_starts = simd_andc(name_start, lex.ASCII_name_start);\
     699        check_streams.non_ascii_names = simd_andc(simd_andc(simd_andc(name_stream, name_start), lex.ASCII_name_char), u8.suffix);\
     700  } while (0)
     701
     702  #define do_check_streams(do_check_streams, ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams)\
     703 do {\
     704                BitBlock CD_end_error;\
     705\
     706        CD_end_error = simd_andc(ctCDPI_Callouts.CD_end, simd_or(ctCDPI_Callouts.CtCDPI_mask, tag_Callouts.AttVal_spans));\
     707        check_streams.error_mask = simd_or(simd_or(simd_or(simd_or(simd_or(simd_or(simd_or(simd_and(lex.error, EOF_mask), u8.error), u8.FFFE_FFFF), ctCDPI_Callouts.error), tag_Callouts.error), CD_end_error), ref_Callouts.error), xml_names.namespace_error);\
     708        check_streams.tag_marks = simd_or(simd_or(tag_Callouts.EmptyTag_marks, tag_Callouts.LAngleFollow), tag_Callouts.AttName_starts);\
     709        check_streams.name_follows = simd_or(tag_Callouts.ElemName_ends, tag_Callouts.AttName_ends);\
     710        check_streams.att_refs = simd_and(tag_Callouts.AttVal_spans, scope1.RefStart);\
     711  } while (0)
     712
    525713/*************Kernel Function****************/
    526714__kernel
     
    536724   struct Scope1 scope1;
    537725   struct CtCDPI_Callouts ctCDPI_Callouts;
     726   struct Ref_Callouts ref_Callouts;
     727   struct Tag_Callouts tag_Callouts;
     728   struct Check_streams check_streams;
     729   struct Xml_names xml_names;
    538730
    539731   BitBlock classify_bytes_Validate_utf8_carryQ[12];
     
    543735   BitBlock parse_CtCDPI_carryQ[17];
    544736   CarryInit(parse_CtCDPI_carryQ, 17);
     737   BitBlock  parse_refs_carryQ[6];
     738   CarryInit(parse_refs_carryQ, 6);
     739   BitBlock  parse_tags_carryQ[13];
     740   CarryInit(parse_tags_carryQ, 13);
     741   BitBlock  validate_xml_names_carryQ[9];
     742   CarryInit(validate_xml_names_carryQ, 9);
    545743   
    546    BitBlock group_carryQ[MAX_CARRY];
    547    CarryInit(group_carryQ, 2);
    548 
    549744   for(int idx=i; idx<ELEMENTS;idx=idx+WORK_GROUP_SIZE){
    550745                s2p_bytepack(s[idx*8], s[idx*8+1], s[idx*8+2], s[idx*8+3], s[idx*8+4], s[idx*8+5], s[idx*8+6], s[idx*8+7],
     
    554749                classify_bytes_Validate_utf8(i, basis_bits, lex, u8, carry, classify_bytes_Validate_utf8_carryQ);
    555750                add_scope_streams(i, lex, scope1, carry, add_scope_streams_carry);
    556                 parse_CtCDPI(idx, ctCDPI_Callouts, lex, scope1, carry, bubble, parse_CtCDPI_carryQ);
    557                 err_pos[idx] = ctCDPI_Callouts.error;
     751                parse_CtCDPI(i, ctCDPI_Callouts, lex, scope1, carry, bubble, parse_CtCDPI_carryQ);
     752                parse_refs(i, lex, scope1, ctCDPI_Callouts, ref_Callouts, carry, bubble, parse_refs_carryQ);
     753                parse_tags(i, lex, scope1, ctCDPI_Callouts, tag_Callouts, carry, bubble, parse_tags_carryQ);
     754                validate_xml_names(idx, ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams, carry, bubble, validate_xml_names_carryQ);
     755                do_check_streams(do_check_streams, ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams);
     756
     757                //err_pos[idx] = check_streams.error_mask;
    558758        }
    559 
    560 }
     759}
Note: See TracChangeset for help on using the changeset viewer.