Changeset 5699


Ignore:
Timestamp:
Oct 19, 2017, 3:10:49 PM (16 months ago)
Author:
cameron
Message:

UntilN kernel bug fix: Nth bit at final position in itemsToDo was not accepted

File:
1 edited

Legend:

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

    r5493 r5699  
    149149    //
    150150    kb->SetInsertPoint(findNth);
    151    
    152151    PHINode * seen1 = kb->CreatePHI(kb->getSizeTy(), 2);
    153152    seen1->addIncoming(seenSoFarPhi, scanLoop);
     
    164163    kb->SetInsertPoint(getPosnAfterNth);
    165164    Value * scanMaskUpToN = kb->CreateXor(scanMask, clearLowest);
    166     Value * posnInPack = kb->CreateSub(ConstantInt::get(iPackTy, packSize), kb->CreateCountReverseZeroes(scanMaskUpToN));
     165    Value * posnInPack = kb->CreateSub(ConstantInt::get(iPackTy, packSize-1), kb->CreateCountReverseZeroes(scanMaskUpToN));
    167166    Value * posnInGroup = kb->CreateAdd(kb->CreateMul(nonZeroPack, kb->getSize(packSize)), posnInPack);
    168167    Value * posnInItemsToDo = kb->CreateAdd(kb->CreateMul(blockGroupBase, blockSize), posnInGroup);
     
    173172   
    174173    kb->SetInsertPoint(nthPosFound);
    175     finalCount = kb->CreateAdd(kb->getProcessedItemCount("bits"), posnInItemsToDo);
    176     Value * finalBlock = kb->CreateUDiv(posnInItemsToDo, blockSize);
     174    Value * itemsToKeep = kb->CreateAdd(posnInItemsToDo, kb->getSize(1));
     175    finalCount = kb->CreateAdd(kb->getProcessedItemCount("bits"), itemsToKeep);
     176    Value * finalBlock = kb->CreateUDiv(itemsToKeep, blockSize);
    177177    blk = kb->CreateBlockAlignedLoad(kb->CreateGEP(sourceBitstream, {finalBlock, kb->getInt32(0)}));
    178     blk = kb->CreateAnd(blk, kb->CreateNot(kb->bitblock_mask_from(kb->CreateURem(posnInItemsToDo, blockSize))));
     178    blk = kb->CreateAnd(blk, kb->CreateNot(kb->bitblock_mask_from(kb->CreateURem(itemsToKeep, blockSize))));
    179179    Value * outputPtr = kb->CreateGEP(uptoN_bitstream, {finalBlock, kb->getInt32(0)});
    180180    kb->CreateBlockAlignedStore(blk, outputPtr);
Note: See TracChangeset for help on using the changeset viewer.