Changeset 4267 for icGREP


Ignore:
Timestamp:
Oct 24, 2014, 12:45:41 PM (5 years ago)
Author:
cameron
Message:

Include log2 bounded-repetition cases by default.

Location:
icGREP/icgrep-devel/icgrep
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4266 r4267  
    849849
    850850Value* PabloCompiler::genAdvanceWithCarry(Value* strm_value, int shift_amount) {
    851 #ifndef VARIABLE_ADVANCE
    852         if (shift_amount != 1) {
    853                 throw std::runtime_error("Shift amount != 1 in Advance is currently unsupported.");
    854         }
    855 #endif
    856851
    857852    IRBuilder<> b(mBasicBlock);
    858853#if (BLOCK_SIZE == 128)
    859854    const auto carryIdx = mCarryQueueIdx++;
    860 #ifndef VARIABLE_ADVANCE
    861     Value* carryq_value = genCarryInLoad(carryIdx);
    862     Value* srli_1_value = b.CreateLShr(strm_value, 63);
    863     Value* packed_shuffle;
    864     Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
    865     Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
    866     packed_shuffle = b.CreateShuffleVector(carryq_value, srli_1_value, const_packed_1);
    867 
    868     Constant* const_packed_2_elems[] = {b.getInt64(1), b.getInt64(1)};
    869     Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
    870 
    871     Value* shl_value = b.CreateShl(strm_value, const_packed_2);
    872     Value* result_value = b.CreateOr(shl_value, packed_shuffle, "advance");
    873 
    874     Value* carry_out = genShiftHighbitToLow(strm_value, "carry_out");
    875 #endif
    876 #ifdef VARIABLE_ADVANCE
    877     Value* carryq_longint = b.CreateBitCast(genCarryInLoad(carryIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    878     Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    879     Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, shift_amount), carryq_longint, "advance");
    880     Value* result_value = b.CreateBitCast(adv_longint, mXi64Vect);
    881     Value* carry_out = b.CreateBitCast(b.CreateLShr(strm_longint, BLOCK_SIZE - shift_amount, "advance_out"), mXi64Vect);
    882 #endif
    883     //CarryQ - carry out:
    884     genCarryOutStore(carry_out, carryIdx);
    885        
    886     return result_value;
     855    if (shift_amount == 1) {
     856        Value* carryq_value = genCarryInLoad(carryIdx);
     857        Value* srli_1_value = b.CreateLShr(strm_value, 63);
     858        Value* packed_shuffle;
     859        Constant* const_packed_1_elems [] = {b.getInt32(0), b.getInt32(2)};
     860        Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
     861        packed_shuffle = b.CreateShuffleVector(carryq_value, srli_1_value, const_packed_1);
     862
     863        Constant* const_packed_2_elems[] = {b.getInt64(1), b.getInt64(1)};
     864        Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
     865
     866        Value* shl_value = b.CreateShl(strm_value, const_packed_2);
     867        Value* result_value = b.CreateOr(shl_value, packed_shuffle, "advance");
     868
     869        Value* carry_out = genShiftHighbitToLow(strm_value, "carry_out");
     870        //CarryQ - carry out:
     871        genCarryOutStore(carry_out, carryIdx);
     872           
     873        return result_value;
     874    }
     875    else if (shift_amount < 64) {
     876        // This is the preferred logic, but is too slow for the general case.   
     877        // We need to speed up our custom LLVM for this code.
     878        Value* carryq_longint = b.CreateBitCast(genCarryInLoad(carryIdx), IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     879        Value* strm_longint = b.CreateBitCast(strm_value, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     880        Value* adv_longint = b.CreateOr(b.CreateShl(strm_longint, shift_amount), carryq_longint, "advance");
     881        Value* result_value = b.CreateBitCast(adv_longint, mXi64Vect);
     882        Value* carry_out = b.CreateBitCast(b.CreateLShr(strm_longint, BLOCK_SIZE - shift_amount, "advance_out"), mXi64Vect);
     883        //CarryQ - carry out:
     884        genCarryOutStore(carry_out, carryIdx);
     885           
     886        return result_value;
     887    }
     888    else {//if (shift_amount >= 64) {
     889        throw std::runtime_error("Shift amount >= 64 in Advance is currently unsupported.");
     890    }
    887891#endif
    888892
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4266 r4267  
    208208
    209209inline Assign * RE_Compiler::processLowerBound(RE * repeated, int lb, Assign * marker, PabloBlock & pb) {
    210 #ifndef VARIABLE_ADVANCE
    211     while (lb-- != 0) {
    212         marker = process(repeated, marker, pb);
    213     }
    214     return marker;
    215 #endif
    216    
    217 #ifdef VARIABLE_ADVANCE
    218210        if (isFixedLength(repeated)) {
    219         Name * rep_name = cast<Name>(repeated);
     211                Name * rep_name = cast<Name>(repeated);
    220212                Assign * cc_lb = consecutive(pb.createAssign("repeated", pb.createAdvance(pb.createVar(rep_name->getName()), 1)), 1, lb, pb);
    221213                return pb.createAssign("lowerbound", pb.createAnd(pb.createAdvance(pb.createVar(marker), lb), pb.createVar(cc_lb)));
    222214        }
    223         else {
    224                 while (lb-- != 0) {
    225                         marker = process(repeated, marker, pb);
    226                 }
    227                 return marker;
    228         }
    229 #endif
    230 
     215        // Fall through to general case.
     216        while (lb-- != 0) {
     217                marker = process(repeated, marker, pb);
     218        }
     219        return marker;
     220}
     221
     222inline Assign * RE_Compiler::processBoundedRep(RE * repeated, int ub, Assign * marker, PabloBlock & pb) {
     223        if (isFixedLength(repeated)) {
     224                // log2 upper bound for fixed length (=1) class
     225                // Mask out any positions that are more than ub positions from a current match.
     226                // Use matchstar, then apply filter.
     227                Assign * nonMatch = pb.createAssign("nonmatch", pb.createNot(pb.createVar(marker)));
     228                PabloAST * upperLimitMask = pb.createNot(pb.createVar(consecutive(nonMatch, 1, ub + 1, pb)));
     229                PabloAST * rep_class_var = pb.createVar(cast<Name>(repeated) -> getName());
     230                        return pb.createAssign("bounded", pb.createAnd(pb.createMatchStar(pb.createVar(marker), rep_class_var), upperLimitMask));
     231        }
     232        // Fall through to general case.
     233        while (ub-- != 0) {
     234                Assign * alt = process(repeated, marker, pb);
     235                marker = pb.createAssign("m", pb.createOr(pb.createVar(marker), pb.createVar(alt)));
     236        }
     237        return marker;
    231238}
    232239
     
    280287    return pb.createAssign("unbounded", unbounded);
    281288}
    282 
    283 inline Assign * RE_Compiler::processBoundedRep(RE * repeated, int ub, Assign * marker, PabloBlock & pb) {
    284 #ifdef VARIABLE_ADVANCE
    285     if (isFixedLength(repeated)) {
    286 // log2 upper bound for fixed length (=1) class
    287 // Mask out any positions that are more than ub positions from a current match.
    288 // Use matchstar, then apply filter.
    289         Assign * nonMatch = pb.createAssign("nonmatch", pb.createNot(pb.createVar(marker)));
    290         PabloAST * upperLimitMask = pb.createNot(pb.createVar(consecutive(nonMatch, 1, ub + 1, pb)));
    291         PabloAST * rep_class_var = pb.createVar(cast<Name>(repeated) -> getName());
    292                 return pb.createAssign("bounded", pb.createAnd(pb.createMatchStar(pb.createVar(marker), rep_class_var), upperLimitMask));
    293     }
    294 #endif
    295     while (ub-- != 0) {
    296         Assign * alt = process(repeated, marker, pb);
    297         marker = pb.createAssign("m", pb.createOr(pb.createVar(marker), pb.createVar(alt)));
    298     }
    299     return marker;
    300 }
    301 
    302289
    303290bool RE_Compiler::hasUnicode(const RE * re) {
Note: See TracChangeset for help on using the changeset viewer.