Changeset 6197 for icGREP


Ignore:
Timestamp:
Nov 10, 2018, 2:05:05 PM (6 months ago)
Author:
nmedfort
Message:

UntilN bug fix.

File:
1 edited

Legend:

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

    r6184 r6197  
    3535   input stream.
    3636*/
    37 
    3837    IntegerType * const sizeTy = b->getSizeTy();
    3938    const unsigned packSize = sizeTy->getBitWidth();
     
    7372    localIndex->addIncoming(ZERO, strideLoop);
    7473    Value * const blockIndex = b->CreateAdd(baseBlockIndex, localIndex);
    75     Value * inputPtr = b->getInputStreamBlockPtr("bits", ZERO, blockIndex);
    76     Value * inputValue = b->CreateBlockAlignedLoad(inputPtr);
    77     Value * outputPtr = b->getOutputStreamBlockPtr("uptoN", ZERO, blockIndex);
    78     b->CreateBlockAlignedStore(inputValue, outputPtr);
     74    Value * inputValue = b->loadInputStreamBlock("bits", ZERO, blockIndex);
     75    b->storeOutputStreamBlock("uptoN", ZERO, blockIndex, inputValue);
    7976    Value * const inputPackValue = b->CreateNot(b->simd_eq(packSize, inputValue, ZEROES));
    8077    Value * iteratorMask = b->CreateZExtOrTrunc(b->hsimd_signmask(packSize, inputPackValue), sizeTy);
     
    154151    Value * const maskedInputValue = b->CreateAnd(inputValue2, mask);
    155152    b->storeOutputStreamBlock("uptoN", ZERO, blockIndex2, maskedInputValue);
    156     Value * const positionOfNthItem = b->CreateAdd(b->CreateMul(blockIndex2, b->getSize(b->getBitBlockWidth())), b->CreateAdd(blockOffset, ONE));
     153    Value * const priorProducedItemCount = b->getProducedItemCount("uptoN");
     154    const auto log2BlockWidth = std::log2<unsigned>(b->getBitBlockWidth());
     155    Value * positionOfNthItem = b->CreateShl(blockIndex2, log2BlockWidth);
     156    positionOfNthItem = b->CreateAdd(positionOfNthItem, b->CreateAdd(blockOffset, ONE));
     157    positionOfNthItem = b->CreateAdd(positionOfNthItem, priorProducedItemCount);
     158    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::EnableAsserts))) {
     159        Value * const availableBits = b->getAvailableItemCount("bits");
     160        Value * const positionLessThanAvail = b->CreateICmpULT(positionOfNthItem, availableBits);
     161        b->CreateAssert(positionLessThanAvail, "position of n-th item exceeds available items!");
     162    }
    157163    b->setTerminationSignal();
    158164    BasicBlock * const segmentDone = b->CreateBasicBlock("segmentDone");
     
    169175    produced->addIncoming(positionOfNthItem, foundNthBit);
    170176    produced->addIncoming(availableBits, nextStride);
    171     Value * producedCount = b->getProducedItemCount("uptoN");
    172     producedCount = b->CreateAdd(producedCount, produced);
    173     b->setProducedItemCount("uptoN", producedCount);
     177    b->setProducedItemCount("uptoN", produced);
    174178
    175179}
     
    180184{Binding{"bits", AllMatches}},
    181185// outputs
    182 {Binding{"uptoN", Matches, FixedRate(), Deferred()}},
     186{Binding{"uptoN", Matches, BoundedRate(0, 1)}},
    183187// input scalar
    184188{Binding{"N", maxCount}}, {},
Note: See TracChangeset for help on using the changeset viewer.