Changeset 6035


Ignore:
Timestamp:
May 13, 2018, 1:27:46 PM (5 months ago)
Author:
xwa163
Message:

PEXTFieldCompressKernel: fix bug in final block

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r6031 r6035  
    121121    Type * fieldTy = kb->getIntNTy(mPEXTWidth);
    122122    Type * fieldPtrTy = PointerType::get(fieldTy, 0);
     123    Constant * fieldTyZero = kb->getIntN(mPEXTWidth, 0);
    123124    Constant * PEXT_func = nullptr;
    124125    Constant * popc_func = Intrinsic::getDeclaration(getModule(), Intrinsic::ctpop, fieldTy);
     
    142143    Value * unitCountPtr = kb->getOutputStreamBlockPtr("unitCounts", ZERO, blockOffsetPhi);
    143144    unitCountPtr = kb->CreatePointerCast(unitCountPtr, fieldPtrTy);
     145
     146    Value* remainingMask = kb->getAvailableItemCount("extractionMask");
     147    Value* PEXTWidth = kb->getSize(mPEXTWidth);
    144148    for (unsigned i = 0; i < fieldsPerBlock; i++) {
    145149        mask[i] = kb->CreateLoad(kb->CreateGEP(extractionMaskPtr, kb->getInt32(i)));
    146         Value * popc = kb->CreateCall(popc_func, mask[i]);
     150        Value* hasFullMask = kb->CreateICmpUGE(remainingMask, PEXTWidth);
     151        Value* shiftAmount = kb->CreateSub(PEXTWidth, remainingMask);
     152        Value * targetMask = kb->CreateSelect(
     153                hasFullMask,
     154                mask[i],
     155                kb->CreateShl(mask[i], shiftAmount)
     156        );
     157        targetMask = kb->CreateSelect(kb->CreateICmpEQ(remainingMask, kb->getSize(0)), fieldTyZero, targetMask);
     158        Value * popc = kb->CreateCall(popc_func, targetMask);
    147159        kb->CreateStore(popc, kb->CreateGEP(unitCountPtr, kb->getInt32(i)));
     160        remainingMask = kb->CreateSelect(
     161                hasFullMask,
     162                kb->CreateSub(remainingMask, kb->getSize(mPEXTWidth)),
     163                kb->getSize(0)
     164        );
    148165    }
    149166    for (unsigned j = 0; j < mStreamCount; ++j) {
Note: See TracChangeset for help on using the changeset viewer.