Ignore:
Timestamp:
Aug 13, 2014, 10:00:28 AM (5 years ago)
Author:
cameron
Message:

Modularize implementation of MatchStar? and ScanThru?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/llvm_gen.cpp

    r3991 r3999  
    10301030    {
    10311031        IRBuilder<> b(mBasicBlock);
    1032 
     1032#if 0
    10331033        //CarryQ - carry in.
    10341034        Value* carryq_idx = b.getInt64(mCarryQueueIdx);
     
    10711071
    10721072        retVal = result_value;
     1073#endif
     1074        //Get the input stream.
     1075        Value* strm_value = Generate_PabloE(mstar->getExpr1());
     1076        //Get the scanthru bit stream.
     1077        Value* cc_value = Generate_PabloE(mstar->getExpr2());
     1078        retVal = genMatchStar(strm_value, cc_value);
    10731079    }
    10741080    else if (ScanThru* sthru = dynamic_cast<ScanThru*>(expr))
    10751081    {
    10761082        IRBuilder<> b(mBasicBlock);
    1077 
     1083#if 0
    10781084        //CarryQ - carry in.
    10791085        Value* carryq_idx = b.getInt64(mCarryQueueIdx);
     
    11091115
    11101116        retVal = result_value;
     1117#endif
     1118        //Get the input stream.
     1119        Value* strm_value = Generate_PabloE(sthru->getScanFrom());
     1120        //Get the scanthru bit stream.
     1121        Value* scanthru_value = Generate_PabloE(sthru->getScanThru());
     1122        retVal = genScanThru(strm_value, scanthru_value);
    11111123    }
    11121124
     
    11141126}
    11151127
     1128
     1129Value* LLVM_Generator::genMatchStar(Value* marker_expr, Value* cc_expr) {
     1130    IRBuilder<> b(mBasicBlock);
     1131    Value* marker_and_cc = b.CreateAnd(marker_expr, cc_expr);
     1132    return b.CreateOr(b.CreateXor(genAddWithCarry(marker_and_cc, cc_expr), cc_expr), marker_expr, "matchstar_rslt");
     1133}
     1134
     1135Value* LLVM_Generator::genScanThru(Value* marker_expr, Value* cc_expr) {
     1136    IRBuilder<> b(mBasicBlock);
     1137    return b.CreateAnd(genAddWithCarry(marker_expr, cc_expr), genNot(cc_expr), "scanthru_rslt");
     1138}
     1139
     1140Value* LLVM_Generator::genAddWithCarry(Value* e1, Value* e2) {
     1141    IRBuilder<> b(mBasicBlock);
     1142   
     1143    //CarryQ - carry in.
     1144    Value* carryq_idx = b.getInt64(mCarryQueueIdx);
     1145    Value* carryq_GEP = b.CreateGEP(mptr_carry_q, carryq_idx);
     1146    Value* carryq_value = b.CreateLoad(carryq_GEP);
     1147
     1148    Value* carrygen = b.CreateAnd(e1, e2, "carrygen");
     1149    Value* carryprop = b.CreateOr(e1, e2, "carryprop");
     1150    Value* digitsum = b.CreateAdd(e1, e2, "digitsum");
     1151    Value* partial = b.CreateAdd(digitsum, carryq_value, "partial");
     1152    Value* digitcarry = b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(partial)));   
     1153    Value* mid_carry_in = genShiftLeft64(b.CreateLShr(digitcarry, 63), "mid_carry_in");
     1154
     1155    Value* sum = b.CreateAdd(partial, mid_carry_in, "sum");
     1156    Value* carry_out = genShiftRight127(b.CreateOr(carrygen, b.CreateAnd(carryprop, genNot(sum))), "carry_out");
     1157   
     1158    //CarryQ - carry out:   
     1159    Value* void_1 = b.CreateStore(carry_out, carryq_GEP);
     1160   
     1161    mCarryQueueIdx++;
     1162    return sum;
     1163}
     1164
     1165#define bitBlockExprType m64x2Vect
     1166
     1167Value* LLVM_Generator::genShiftRight127(Value* e, const Twine &namehint) {
     1168    IRBuilder<> b(mBasicBlock);
     1169    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), 128));
     1170    return b.CreateBitCast(b.CreateLShr(i128_val, 127, namehint), bitBlockExprType);
     1171}
     1172
     1173Value* LLVM_Generator::genShiftLeft64(Value* e, const Twine &namehint) {
     1174    IRBuilder<> b(mBasicBlock);
     1175    Value* i128_val = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), 128));
     1176    return b.CreateBitCast(b.CreateShl(i128_val, 64, namehint), bitBlockExprType);
     1177}
     1178
     1179Value* LLVM_Generator::genNot(Value* e, const Twine &namehint) {
     1180    IRBuilder<> b(mBasicBlock);
     1181    return b.CreateXor(e, mConst_Aggregate_64x2_neg1, namehint);
     1182}
     1183
     1184
     1185
     1186
Note: See TracChangeset for help on using the changeset viewer.