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

Implementatation of the Pablo Count operation

File:
1 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) {
Note: See TracChangeset for help on using the changeset viewer.