Changeset 4717


Ignore:
Timestamp:
Aug 7, 2015, 10:04:46 AM (4 years ago)
Author:
cameron
Message:

Mod64Advance, Mod64MatchStar, Mod64ScanThru ops; -mod64-approximate command-line option

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

Legend:

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

    r4695 r4717  
    8282}
    8383
     84PabloAST * PabloBuilder::createMod64Advance(PabloAST * expr, PabloAST * shiftAmount) {
     85    MAKE_BINARY(createMod64Advance, PabloAST::ClassTypeId::Mod64Advance, expr, shiftAmount);
     86    return result;
     87}
     88
     89PabloAST * PabloBuilder::createMod64Advance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix) {
     90    MAKE_BINARY(createMod64Advance, PabloAST::ClassTypeId::Mod64Advance, expr, shiftAmount, prefix);
     91    return result;
     92}
     93
    8494PabloAST * PabloBuilder::createNot(PabloAST * expr) {
    8595    MAKE_UNARY(createNot, PabloAST::ClassTypeId::Not, expr);
     
    171181}
    172182
    173 
    174 }
     183PabloAST * PabloBuilder::createMod64MatchStar(PabloAST * marker, PabloAST * charclass) {
     184    MAKE_BINARY(createMod64MatchStar, PabloAST::ClassTypeId::Mod64MatchStar, marker, charclass);
     185    return result;
     186}
     187
     188PabloAST * PabloBuilder::createMod64MatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {
     189    MAKE_BINARY(createMod64MatchStar, PabloAST::ClassTypeId::Mod64MatchStar, marker, charclass, prefix);
     190    return result;
     191}
     192
     193PabloAST * PabloBuilder::createMod64ScanThru(PabloAST * from, PabloAST * thru) {
     194    MAKE_BINARY(createMod64ScanThru, PabloAST::ClassTypeId::Mod64ScanThru, from, thru);
     195    return result;
     196}
     197
     198PabloAST * PabloBuilder::createMod64ScanThru(PabloAST * from, PabloAST * thru, const std::string prefix) {
     199    MAKE_BINARY(createMod64ScanThru, PabloAST::ClassTypeId::Mod64ScanThru, from, thru, prefix);
     200    return result;
     201}
     202
     203
     204
     205}
  • icGREP/icgrep-devel/icgrep/pablo/builder.hpp

    r4711 r4717  
    114114
    115115    PabloAST * createSel(PabloAST * condition, PabloAST * trueExpr, PabloAST * falseExpr, const std::string prefix);
     116   
     117    /// Mod64 approximate function wrappers.
     118   
     119    PabloAST * createMod64Advance(PabloAST * expr, PabloAST * shiftAmount);
     120
     121    inline PabloAST * createMod64Advance(PabloAST * expr, const Integer::Type shiftAmount, const std::string prefix) {
     122        if (shiftAmount == 0) {
     123            return expr;
     124        }
     125        return createMod64Advance(expr, mPb->getInteger(shiftAmount), prefix);
     126    }
     127
     128    PabloAST * createMod64Advance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix);
     129
     130    PabloAST * createMod64MatchStar(PabloAST * marker, PabloAST * charclass);
     131
     132    PabloAST * createMod64MatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix);
     133
     134    PabloAST * createMod64ScanThru(PabloAST * from, PabloAST * thru);
     135
     136    PabloAST * createMod64ScanThru(PabloAST * from, PabloAST * thru, const std::string prefix);
     137
    116138
    117139    /// CreateIf Wrappers
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.cpp

    r4716 r4717  
    1818        if (Advance * adv = dyn_cast<Advance>(stmt)) {
    1919            unsigned shift_amount = adv->getAdvanceAmount();
    20             if (!adv->isMod64()) {
    21                 if (shift_amount == 1) {
    22                     adv->setLocalAdvanceIndex(advance1.entries);
    23                     advance1.entries++;               
    24                 }
    25                 else if (shift_amount < LongAdvanceBase) {
    26                     // short Advance
    27                     if (mITEMS_PER_PACK >= LongAdvanceBase) {
    28                         // Packing is possible.   We will use the allocated bit position as
    29                         // the index.
    30                         if (roomInFinalPack(shortAdvance.allocatedBits) < shift_amount) {
    31                             // Start a new pack.
    32                             shortAdvance.allocatedBits = alignCeiling(shortAdvance.allocatedBits, mPACK_SIZE);
    33                         }
    34                         adv->setLocalAdvanceIndex(shortAdvance.allocatedBits);
     20            if (shift_amount == 1) {
     21                adv->setLocalAdvanceIndex(advance1.entries);
     22                advance1.entries++;               
     23            }
     24            else if (shift_amount < LongAdvanceBase) {
     25                // short Advance
     26                if (mITEMS_PER_PACK >= LongAdvanceBase) {
     27                    // Packing is possible.   We will use the allocated bit position as
     28                    // the index.
     29                    if (roomInFinalPack(shortAdvance.allocatedBits) < shift_amount) {
     30                        // Start a new pack.
     31                        shortAdvance.allocatedBits = alignCeiling(shortAdvance.allocatedBits, mPACK_SIZE);
    3532                    }
    36                     else {
    37                         adv->setLocalAdvanceIndex(shortAdvance.entries);
    38                     }
    39                     shortAdvance.entries++;
    40                     shortAdvance.allocatedBits += shift_amount;
     33                    adv->setLocalAdvanceIndex(shortAdvance.allocatedBits);
    4134                }
    4235                else {
    43                     adv->setLocalAdvanceIndex(longAdvance.allocatedBitBlocks);
    44                     longAdvance.entries++;
    45                     longAdvance.allocatedBitBlocks += longAdvanceBufferSize(shift_amount);
     36                    adv->setLocalAdvanceIndex(shortAdvance.entries);
    4637                }
     38                shortAdvance.entries++;
     39                shortAdvance.allocatedBits += shift_amount;
     40            }
     41            else {
     42                adv->setLocalAdvanceIndex(longAdvance.allocatedBitBlocks);
     43                longAdvance.entries++;
     44                longAdvance.allocatedBitBlocks += longAdvanceBufferSize(shift_amount);
    4745            }
    4846        }
    4947        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
    50             if (!m->isMod64()) {
    51                 m->setLocalCarryIndex(addWithCarry.entries);
    52                 ++addWithCarry.entries;
    53             }
     48            m->setLocalCarryIndex(addWithCarry.entries);
     49            ++addWithCarry.entries;
    5450        }
    5551        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
    56             if (!s->isMod64()) {
    57                 s->setLocalCarryIndex(addWithCarry.entries);
    58                 ++addWithCarry.entries;
    59             }
     52            s->setLocalCarryIndex(addWithCarry.entries);
     53            ++addWithCarry.entries;
    6054        }
    6155    }
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4699 r4717  
    111111}
    112112
     113PabloAST * PabloBlock::createMod64Advance(PabloAST * expr, PabloAST * shiftAmount) {
     114    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
     115        return expr;
     116    }
     117    return insertAtInsertionPoint(new Mod64Advance(expr, shiftAmount, makeName("advance")));
     118}
     119
     120PabloAST * PabloBlock::createMod64Advance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix) {
     121    if (isa<Zeroes>(expr) || cast<Integer>(shiftAmount)->value() == 0) {
     122        return expr;
     123    }
     124    return insertAtInsertionPoint(new Mod64Advance(expr, shiftAmount, makeName(prefix, false)));
     125}
     126
     127PabloAST * PabloBlock::createMod64Advance(PabloAST * expr, const Integer::Type shiftAmount) {
     128    if (isa<Zeroes>(expr) || shiftAmount == 0) {
     129        return expr;
     130    }
     131    return insertAtInsertionPoint(new Mod64Advance(expr, getInteger(shiftAmount), makeName("advance")));
     132}
     133
     134PabloAST * PabloBlock::createMod64Advance(PabloAST * expr, const Integer::Type shiftAmount, const std::string prefix) {
     135    if (isa<Zeroes>(expr) || shiftAmount == 0) {
     136        return renameNonNamedNode(expr, std::move(prefix));
     137    }   
     138    return insertAtInsertionPoint(new Mod64Advance(expr, getInteger(shiftAmount), makeName(prefix, false)));
     139}
     140
     141
    113142/// BINARY CREATE FUNCTIONS
    114143
     
    149178    return insertAtInsertionPoint(new ScanThru(from, thru, makeName(prefix, false)));
    150179}
     180
     181PabloAST * PabloBlock::createMod64MatchStar(PabloAST * marker, PabloAST * charclass) {
     182    assert (marker && charclass);
     183    if (isa<Zeroes>(marker) || isa<Zeroes>(charclass)) {
     184        return marker;
     185    }
     186    return insertAtInsertionPoint(new Mod64MatchStar(marker, charclass, makeName("matchstar")));
     187}
     188
     189PabloAST * PabloBlock::createMod64MatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix) {
     190    assert (marker && charclass);
     191    if (isa<Zeroes>(marker) || isa<Zeroes>(charclass)) {
     192        return renameNonNamedNode(marker, std::move(prefix));
     193    }
     194    return insertAtInsertionPoint(new Mod64MatchStar(marker, charclass, makeName(prefix, false)));
     195}
     196
     197PabloAST * PabloBlock::createMod64ScanThru(PabloAST * from, PabloAST * thru) {
     198    assert (from && thru);
     199    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {
     200        return from;
     201    }
     202    return insertAtInsertionPoint(new Mod64ScanThru(from, thru, makeName("scanthru")));
     203}
     204
     205PabloAST * PabloBlock::createMod64ScanThru(PabloAST * from, PabloAST * thru, const std::string prefix) {
     206    assert (from && thru);
     207    if (isa<Zeroes>(from) || isa<Zeroes>(thru)) {       
     208        return renameNonNamedNode(from, std::move(prefix));
     209    }
     210    return insertAtInsertionPoint(new Mod64ScanThru(from, thru, makeName(prefix, false)));
     211}
     212
     213
     214
    151215
    152216PabloAST * PabloBlock::createAnd(PabloAST * expr1, PabloAST * expr2) {
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4699 r4717  
    142142    While * createWhile(PabloAST * condition, std::vector<Next *> && nextVars, PabloBlock & body);
    143143
     144    PabloAST * createMod64Advance(PabloAST * expr, const Integer::Type shiftAmount);
     145
     146    PabloAST * createMod64Advance(PabloAST * expr, PabloAST * shiftAmount);
     147
     148    PabloAST * createMod64Advance(PabloAST * expr, const Integer::Type shiftAmount, const std::string prefix);
     149
     150    PabloAST * createMod64Advance(PabloAST * expr, PabloAST * shiftAmount, const std::string prefix);
     151
     152    PabloAST * createMod64MatchStar(PabloAST * marker, PabloAST * charclass);
     153
     154    PabloAST * createMod64MatchStar(PabloAST * marker, PabloAST * charclass, const std::string prefix);
     155
     156    PabloAST * createMod64ScanThru(PabloAST * from, PabloAST * thru);
     157
     158    PabloAST * createMod64ScanThru(PabloAST * from, PabloAST * thru, const std::string prefix);
     159
    144160
    145161    inline StatementList & statements() {
  • icGREP/icgrep-devel/icgrep/pablo/expression_map.hpp

    r4695 r4717  
    271271            case PabloAST::ClassTypeId::ScanThru:
    272272            case PabloAST::ClassTypeId::MatchStar:
     273            case PabloAST::ClassTypeId::Mod64Advance:
     274            case PabloAST::ClassTypeId::Mod64ScanThru:
     275            case PabloAST::ClassTypeId::Mod64MatchStar:
    273276            case PabloAST::ClassTypeId::Next:
    274277                return mBinary.findOrAdd(stmt, stmt->getClassTypeId(), stmt->getOperand(0), stmt->getOperand(1));
  • icGREP/icgrep-devel/icgrep/pablo/pabloAST.h

    r4711 r4717  
    6262        , ScanThru
    6363        , MatchStar
     64        // Mod 64 approximate stream operations
     65        , Mod64Advance
     66        , Mod64ScanThru
     67        , Mod64MatchStar
    6468        // Variable assignments
    6569        , Assign
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4716 r4717  
    5555
    5656static cl::OptionCategory fTracingOptions("Run-time Tracing Options", "These options control execution traces.");
    57 static cl::opt<bool> TraceNext("trace-next-nodes", cl::init(false), cl::desc("Generate dynamic traces of executed Next nodes (while control variables)."), cl::cat(fTracingOptions));
    5857static cl::opt<bool> DumpTrace("dump-trace", cl::init(false), cl::desc("Generate dynamic traces of executed assignments."), cl::cat(fTracingOptions));
    5958
     
    193192    mCarryManager->generateBlockNoIncrement();
    194193
    195     if (DumpTrace || TraceNext) {
     194    if (DumpTrace) {
    196195        genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), BLOCK_SIZE/8, false));
    197196    }
     
    351350
    352351inline void PabloCompiler::DeclareDebugFunctions() {
    353     if (DumpTrace || TraceNext) {
     352    if (DumpTrace) {
    354353        //This function can be used for testing to print the contents of a register from JIT'd code to the terminal window.
    355354        mPrintRegisterFunction = mMod->getOrInsertFunction("wrapped_print_register", Type::getVoidTy(mMod->getContext()), Type::getInt8PtrTy(mMod->getContext()), mBitBlockType, NULL);
     
    532531    else if (const Next * next = dyn_cast<const Next>(stmt)) {
    533532        expr = compileExpression(next->getExpr());
    534         if (TraceNext) {
    535             genPrintRegister(next->getName()->to_string(), expr);
    536         }
    537533    }
    538534    else if (const If * ifStatement = dyn_cast<const If>(stmt)) {
     
    603599        Value* strm_value = compileExpression(adv->getExpr());
    604600        int shift = adv->getAdvanceAmount();
    605         if (adv->isMod64()) {
    606             expr = iBuilder.simd_slli(64, strm_value, shift);
    607         }
    608         else {
    609             unsigned advance_index = adv->getLocalAdvanceIndex();
    610             expr = mCarryManager->advanceCarryInCarryOut(advance_index, shift, strm_value);
    611         }
     601        unsigned advance_index = adv->getLocalAdvanceIndex();
     602        expr = mCarryManager->advanceCarryInCarryOut(advance_index, shift, strm_value);
     603    }
     604    else if (const Mod64Advance * adv = dyn_cast<Mod64Advance>(stmt)) {
     605        Value* strm_value = compileExpression(adv->getExpr());
     606        int shift = adv->getAdvanceAmount();
     607        expr = iBuilder.simd_slli(64, strm_value, shift);
    612608    }
    613609    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
     
    615611        Value * cc = compileExpression(mstar->getCharClass());
    616612        Value * marker_and_cc = mBuilder->CreateAnd(marker, cc);
    617         Value * sum = nullptr;
    618         if (mstar->isMod64()) {
    619             sum = iBuilder.simd_add(64, marker_and_cc, cc);
    620         }
    621         else {
    622             unsigned carry_index = mstar->getLocalCarryIndex();
    623             sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
    624         }
     613        unsigned carry_index = mstar->getLocalCarryIndex();
     614        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
    625615        expr = mBuilder->CreateOr(mBuilder->CreateXor(sum, cc), marker, "matchstar");
     616    }
     617    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
     618        Value * marker = compileExpression(mstar->getMarker());
     619        Value * cc = compileExpression(mstar->getCharClass());
     620        Value * marker_and_cc = mBuilder->CreateAnd(marker, cc);
     621        Value * sum = iBuilder.simd_add(64, marker_and_cc, cc);
     622        expr = mBuilder->CreateOr(mBuilder->CreateXor(sum, cc), marker, "matchstar64");
    626623    }
    627624    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
    628625        Value * marker_expr = compileExpression(sthru->getScanFrom());
    629626        Value * cc_expr = compileExpression(sthru->getScanThru());
    630         Value * sum = nullptr;
    631         if (sthru->isMod64()) {
    632             sum = iBuilder.simd_add(64, marker_expr, cc_expr);
    633         }
    634         else {
    635             unsigned carry_index = sthru->getLocalCarryIndex();
    636             sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
    637         }
     627        unsigned carry_index = sthru->getLocalCarryIndex();
     628        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
    638629        expr = mBuilder->CreateAnd(sum, genNot(cc_expr), "scanthru");
     630    }
     631    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
     632        Value * marker_expr = compileExpression(sthru->getScanFrom());
     633        Value * cc_expr = compileExpression(sthru->getScanThru());
     634        Value * sum = iBuilder.simd_add(64, marker_expr, cc_expr);
     635        expr = mBuilder->CreateAnd(sum, genNot(cc_expr), "scanthru64");
    639636    }
    640637    else {
  • icGREP/icgrep-devel/icgrep/pablo/pe_advance.h

    r4716 r4717  
    3737        return localAdvanceIndex;
    3838    }
    39     inline void setMod64() {
    40         isMod64approx = true;
    41     }
    42     inline bool isMod64() const {
    43         return isMod64approx;
    44     }
    4539protected:
    4640    Advance(PabloAST * expr, PabloAST * shiftAmount, String * name)
    4741    : Statement(ClassTypeId::Advance, {expr, shiftAmount}, name)
    48    , isMod64approx(false)
    4942    {
    5043        assert(isa<Integer>(shiftAmount));
    5144    }
    5245private:
    53     bool isMod64approx;
    5446    unsigned localAdvanceIndex;
    5547};
    56    
     48
     49class Mod64Advance : public Statement {
     50    friend class PabloBlock;
     51public:
     52    static inline bool classof(const PabloAST * e) {
     53        return e->getClassTypeId() == ClassTypeId::Mod64Advance;
     54    }
     55    static inline bool classof(const void *) {
     56        return false;
     57    }
     58    virtual ~Mod64Advance() {
     59    }
     60    inline PabloAST * getExpr() const {
     61        return getOperand(0);
     62    }
     63    inline Integer::Type getAdvanceAmount() const {
     64        return cast<Integer>(getOperand(1))->value();
     65    }
     66protected:
     67    Mod64Advance(PabloAST * expr, PabloAST * shiftAmount, String * name)
     68    : Statement(ClassTypeId::Mod64Advance, {expr, shiftAmount}, name)
     69    {
     70        assert(isa<Integer>(shiftAmount));
     71    }
     72};
     73
    5774}
    5875
  • icGREP/icgrep-devel/icgrep/pablo/pe_matchstar.h

    r4716 r4717  
    3333        return localCarryIndex;
    3434    }
    35     inline void setMod64() {
    36         isMod64approx = true;
    37     }
    38     inline bool isMod64() const {
    39         return isMod64approx;
    40     }
    4135    virtual ~MatchStar() {}
    4236protected:
    4337    MatchStar(PabloAST * marker, PabloAST * cc, String * name)
    4438    : Statement(ClassTypeId::MatchStar, {marker, cc}, name)
    45     , isMod64approx(false)
    4639    {
    4740
    4841    }
    4942private:
    50     bool isMod64approx;
    5143    unsigned localCarryIndex;
     44};
     45
     46class Mod64MatchStar : public Statement {
     47    friend class PabloBlock;
     48public:
     49    static inline bool classof(const PabloAST * e) {
     50        return e->getClassTypeId() == ClassTypeId::Mod64MatchStar;
     51    }
     52    static inline bool classof(const void *) {
     53        return false;
     54    }
     55    inline PabloAST * getMarker() const {
     56        return getOperand(0);
     57    }
     58    inline PabloAST * getCharClass() const  {
     59        return getOperand(1);
     60    }
     61    virtual ~Mod64MatchStar() {}
     62protected:
     63    Mod64MatchStar(PabloAST * marker, PabloAST * cc, String * name)
     64    : Statement(ClassTypeId::Mod64MatchStar, {marker, cc}, name)
     65    {
     66
     67    }
    5268};
    5369
  • icGREP/icgrep-devel/icgrep/pablo/pe_scanthru.h

    r4716 r4717  
    3535        return localCarryIndex;
    3636    }
    37     inline void setMod64() {
    38         isMod64approx = true;
    39     }
    40     inline bool isMod64() const {
    41         return isMod64approx;
    42     }
    4337protected:
    4438    ScanThru(PabloAST * from, PabloAST * thru, String * name)
    4539    : Statement(ClassTypeId::ScanThru, {from, thru}, name)
    46     , isMod64approx(false)
    4740    {
    4841
    4942    }
    5043private:
    51     bool isMod64approx;
    5244    unsigned localCarryIndex;
     45};
     46
     47class Mod64ScanThru : public Statement {
     48    friend class PabloBlock;
     49public:
     50    static inline bool classof(const PabloAST * e) {
     51        return e->getClassTypeId() == ClassTypeId::Mod64ScanThru;
     52    }
     53    static inline bool classof(const void *) {
     54        return false;
     55    }
     56    virtual ~Mod64ScanThru() {
     57    }
     58    PabloAST * getScanFrom() const {
     59        return getOperand(0);
     60    }
     61    PabloAST * getScanThru() const {
     62        return getOperand(1);
     63    }
     64protected:
     65    Mod64ScanThru(PabloAST * from, PabloAST * thru, String * name)
     66    : Statement(ClassTypeId::Mod64ScanThru, {from, thru}, name)
     67    {
     68
     69    }
    5370};
    5471
  • icGREP/icgrep-devel/icgrep/re/re_compiler.cpp

    r4716 r4717  
    500500    if (isByteLength(repeated)  && !DisableMatchStar) {
    501501        PabloAST * cc = markerVar(compile(repeated, pb)); 
    502         return makeMarker(InitialPostPositionByte, pb.createMatchStar(base, cc, "unbounded"));
     502        PabloAST * mstar = SetMod64Approximation ? pb.createMod64MatchStar(base, cc) : pb.createMatchStar(base, cc, "unbounded");
     503        return makeMarker(InitialPostPositionByte, mstar);
    503504    }
    504505    else if (isUnicodeUnitLength(repeated) && !DisableMatchStar && !DisableUnicodeMatchStar) {
    505506        PabloAST * cc = markerVar(compile(repeated, pb));
    506         PabloAST * mstar = pb.createMatchStar(base, pb.createOr(mNonFinal, cc));
    507         if (SetMod64Approximation) {
    508             if (isa<MatchStar>(mstar)) {
    509                 dyn_cast<MatchStar>(mstar)->setMod64();
    510             }
    511         }
     507        PabloAST * mstar = SetMod64Approximation ? pb.createMod64MatchStar(base, pb.createOr(mNonFinal, cc)) : pb.createMatchStar(base, pb.createOr(mNonFinal, cc));
    512508        return makeMarker(FinalPostPositionByte, pb.createAnd(mstar, mFinal, "unbounded"));
    513509    }
Note: See TracChangeset for help on using the changeset viewer.