Ignore:
Timestamp:
Aug 8, 2015, 10:29:08 AM (4 years ago)
Author:
cameron
Message:

Implementatation of the Pablo Count operation

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
4 edited

Legend:

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

    r4715 r4720  
    7474        mTotalCarryDataBitBlocks = totalCarryDataSize;
    7575    }
     76    // Popcount data is stored after all the carry data.
     77    if (mPabloCountCount > 0) {
     78        mPopcountBasePtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(carryPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
     79        mTotalCarryDataBitBlocks += (mPabloCountCount + BLOCK_SIZE/64 - 1) * 64/BLOCK_SIZE;
     80    }
    7681    // Carry Data area will have one extra bit block to store the block number.
    7782    mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(carryPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
     
    104109 
    105110    for (Statement * stmt : *blk) {
    106         if (If * ifStatement = dyn_cast<If>(stmt)) {
     111        if (Count * c = dyn_cast<Count>(stmt)) {
     112            c->setGlobalCountIndex(mPabloCountCount);
     113            mPabloCountCount++;
     114        }
     115        else if (If * ifStatement = dyn_cast<If>(stmt)) {
    107116            const unsigned ifCarryDataBits = enumerate(&ifStatement->getBody(), ifDepth+1, whileDepth);
    108117            PabloBlockCarryData * nestedBlockData = mCarryInfoVector[ifStatement->getBody().getScopeIndex()];
     
    660669}
    661670
     671Value * CarryManager::popCount(Value * to_count, unsigned globalIdx) {
     672    Value * countPtr = mBuilder->CreateGEP(mPopcountBasePtr, mBuilder->getInt64(globalIdx));
     673    Value * countSoFar = mBuilder->CreateAlignedLoad(countPtr, 8);
     674    Value * fieldCounts = iBuilder->simd_popcount(64, to_count);
     675    for (int i = 0; i < BLOCK_SIZE/64; i++) {
     676        countSoFar = mBuilder->CreateAdd(countSoFar, iBuilder->mvmd_extract(64, fieldCounts, i));
     677    }
     678    mBuilder->CreateAlignedStore(countSoFar, countPtr, 8);
     679    return mBuilder->CreateBitCast(mBuilder->CreateZExt(countSoFar, mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
     680}
     681   
    662682CarryManager::~CarryManager() {
    663683    for (auto * cd : mCarryInfoVector) {
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4715 r4720  
    5252    , mCarryPackBasePtr(nullptr)
    5353    , mCarryBitBlockPtr(nullptr)
     54    , mPopcountBasePtr(nullptr)
    5455    , mBlockNoPtr(nullptr)
    5556    , mBlockNo(nullptr)
     57    , mPabloCountCount(0)
    5658    , mTotalCarryDataBitBlocks(0)
    5759    {
     
    108110    void ensureCarriesStoredLocal();
    109111   
     112    Value * popCount(Value * to_count, unsigned globalIdx);
     113   
    110114private:
    111115    unsigned mPACK_SIZE;
     
    123127    Type * mCarryPackType;
    124128    Value * mCarryBitBlockPtr;
     129    Value * mPopcountBasePtr;
    125130    Value * mBlockNoPtr;
    126131    Value * mBlockNo;
     132    unsigned mPabloCountCount; // Number of Pablo "Count" operations
    127133    unsigned mTotalCarryDataBitBlocks;
    128134   
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4717 r4720  
    635635        expr = mBuilder->CreateAnd(sum, genNot(cc_expr), "scanthru64");
    636636    }
     637    else if (const Count * c = dyn_cast<Count>(stmt)) {
     638        unsigned count_index = c->getGlobalCountIndex();
     639        Value * to_count = compileExpression(c->getExpr());
     640        expr = mCarryManager->popCount(to_count, count_index);
     641    }
    637642    else {
    638643        llvm::raw_os_ostream cerr(std::cerr);
  • icGREP/icgrep-devel/icgrep/pablo/pe_count.h

    r4719 r4720  
    1616public:
    1717    static inline bool classof(const PabloAST * e) {
    18         return e->getClassTypeId() == ClassTypeId::Advance;
     18        return e->getClassTypeId() == ClassTypeId::Count;
    1919    }
    2020    static inline bool classof(const void *) {
Note: See TracChangeset for help on using the changeset viewer.