Ignore:
Timestamp:
Aug 10, 2018, 3:07:59 AM (10 months ago)
Author:
xwa163
Message:

lz4_grep: some bug fixing and refactor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/lz4/decompression/lz4_twist_decompression.cpp

    r6136 r6143  
    2828    {
    2929        mStreamSetInputs.push_back(Binding{b->getStreamSetTy(1, twistWidth), "inputTwistStream", RateEqualTo("byteStream")});
     30//        mStreamSetInputs.push_back(Binding{b->getStreamSetTy(1, twistWidth), "refTwistStream"});
    3031        mStreamSetOutputs.push_back(Binding{b->getStreamSetTy(1, twistWidth), "outputTwistStream", BoundedRate(0, 1)});
    3132
    3233        this->addScalar(b->getInt8PtrTy(), "temporaryInputPtr");
     34        this->addScalar(b->getInt8PtrTy(), "temporaryOutputPtr");
    3335    }
    3436
     
    4143        Constant* SIZE_ITEMS_PER_BYTE = b->getSize(mItemsPerByte);
    4244        Constant* INT_FW_TWIST_WIDTH = b->getIntN(COPY_FW, mTwistWidth);
    43         Type* INT8_PTR_TY = b->getInt8PtrTy();
    4445        Type* INT_FW_TY = b->getIntNTy(COPY_FW);
    4546        Type* INT_FW_PTR_TY = INT_FW_TY->getPointerTo();
     
    5556        Value* initInputPtr = b->CreateGEP(temporayInputPtr, initInputOffset);
    5657
    57         Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", SIZE_0), INT8_PTR_TY);
     58
     59        Value* outputByteBasePtr = b->getScalarField("temporaryOutputPtr");
    5860        Value* outputPos = b->getScalarField("outputPos");
    59         Value* outputCapacity = b->getCapacity("outputTwistStream");
    60 
    61         Value* outputPosRem = b->CreateURem(outputPos, outputCapacity);
     61
     62        Value* outputPosRem = b->CreateSub(outputPos, b->getProducedItemCount("outputTwistStream"));
    6263        Value* outputPosByteRem = b->CreateUDiv(outputPosRem, SIZE_ITEMS_PER_BYTE);
    6364
     
    6970        Value* outputPosRemByteItem = b->CreateURem(outputPos, SIZE_ITEMS_PER_BYTE);
    7071        Value* outputMask = this->getOutputMask(b, outputPos);
    71 
    7272
    7373        // ---- EntryBlock
     
    9595        BasicBlock* literalCopyExit = b->CreateBasicBlock("literalCopyExit");
    9696
     97
    9798        b->CreateCondBr(b->CreateICmpULT(phiCopiedLength, literalLength), literalCopyBody, literalCopyExit);
    9899
     
    103104        Value* outputFwPtr = b->CreatePointerCast(phiOutputPtr, INT_FW_PTR_TY);
    104105
     106
    105107        Value* inputTargetValue = b->CreateLoad(inputFwPtr);
     108
     109
    106110        inputTargetValue = b->CreateLShr(inputTargetValue, b->CreateMul(literalStartRemByteItem, INT_FW_TWIST_WIDTH));
    107111        inputTargetValue = b->CreateShl(inputTargetValue, b->CreateMul(outputPosRemByteItem, INT_FW_TWIST_WIDTH));
     
    111115
    112116        Value* outputValue = b->CreateAnd(phiOutputLastByte, outputMask);
     117
    113118        outputValue = b->CreateOr(outputValue, inputTargetValue);
     119
    114120        b->CreateStore(outputValue, outputFwPtr);
    115 
    116121
    117122        phiOutputLastByte->addIncoming(b->CreateLShr(outputValue, b->getSize(this->getNormalCopyLength() * mTwistWidth)), b->GetInsertBlock());
     
    124129        // ---- literalCopyExit
    125130        b->SetInsertPoint(literalCopyExit);
     131
     132
    126133        b->setScalarField("outputPos", b->CreateAdd(outputPos, literalLength));
    127134    }
     
    141148
    142149
    143         Value* outputCapacity = b->getCapacity("outputTwistStream");
    144 
    145         Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", SIZE_0), INT8_PTR_TY);
     150//        Value* outputCapacity = b->getCapacity("outputTwistStream");
     151
     152//        Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", SIZE_0), INT8_PTR_TY);
     153        Value* outputByteBasePtr = b->getScalarField("temporaryOutputPtr");
    146154
    147155        Value* outputPos = b->getScalarField("outputPos");
    148         Value* outputPosRem = b->CreateURem(outputPos, outputCapacity);
     156//        Value* outputPosRem = b->CreateURem(outputPos, outputCapacity);
     157        Value* outputPosRem = b->CreateSub(outputPos, b->getProducedItemCount("outputTwistStream"));
    149158
    150159        // ---- EntryBlock
     
    214223
    215224
    216 
    217         Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", b->getSize(0)), INT8_PTR_TY);
    218         Value* outputCapacity = b->getCapacity("outputTwistStream");
     225//        Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", b->getSize(0)), INT8_PTR_TY);
     226//        Value* outputCapacity = b->getCapacity("outputTwistStream");
     227        Value* outputByteBasePtr = b->getScalarField("temporaryOutputPtr");
    219228        Value* outputPos = b->getScalarField("outputPos");
    220         Value* outputPosRem = b->CreateURem(outputPos, outputCapacity);
     229
     230
     231//        Value* outputPosRem = b->CreateURem(outputPos, outputCapacity);
     232        Value* outputPosRem = b->CreateSub(outputPos, b->getProducedItemCount("outputTwistStream"));
    221233
    222234        Value* outputPosRemByteItem = b->CreateURem(outputPosRem, SIZE_ITEMS_PER_BYTE);
     
    225237
    226238        Value* outputBytePos = b->CreateUDiv(outputPosRem, SIZE_ITEMS_PER_BYTE);
     239
     240
    227241        Value* initCopyToPtr = b->CreateGEP(outputByteBasePtr, outputBytePos);
    228 
    229242        Value* initOutputLastByte = b->CreateZExt(b->CreateLoad(initCopyToPtr), INT_FW_TY);
    230243
     
    319332
    320333    void LZ4TwistDecompressionKernel::setProducedOutputItemCount(const std::unique_ptr<KernelBuilder> &b, llvm::Value* produced) {
     334        Constant* SIZE_ITEMS_PER_BYTE = b->getSize(mItemsPerByte);
     335        Constant* SIZE_0 = b->getSize(0);
     336        Type* INT8_PTR_TY = b->getInt8PtrTy();
     337
     338        Value* oldProduced = b->getProducedItemCount("outputTwistStream");
     339
     340        Value* outputByteBasePtr = b->CreatePointerCast(b->getRawOutputPointer("outputTwistStream", SIZE_0), INT8_PTR_TY);
     341        Value* outputCapacity = b->getCapacity("outputTwistStream");
     342        Value* outputPosRem = b->CreateURem(oldProduced, outputCapacity);
     343
     344        Value* outputPosByteRem = b->CreateUDiv(outputPosRem, SIZE_ITEMS_PER_BYTE);
     345        Value* actualOutputPtr = b->CreateGEP(outputByteBasePtr, outputPosByteRem);
     346        b->CreateMemCpy(actualOutputPtr, b->getScalarField("temporaryOutputPtr"), b->getSize(mBlockSize / mItemsPerByte), 1);
     347
     348        Value* ptr = b->CreateGEP(b->CreatePointerCast(b->getScalarField("temporaryOutputPtr"), b->getBitBlockType()->getPointerTo()), b->getSize(0x16f));
     349
    321350        b->setProducedItemCount("outputTwistStream", produced);
    322351    }
     
    325354    void LZ4TwistDecompressionKernel::initializationMethod(const std::unique_ptr<KernelBuilder> &b) {
    326355        b->setScalarField("temporaryInputPtr", b->CreateMalloc(b->getSize(mBlockSize / mItemsPerByte)));
     356        b->setScalarField("temporaryOutputPtr", b->CreateMalloc(b->getSize(mBlockSize / mItemsPerByte + COPY_FW / BYTE_WIDTH)));
     357
    327358    }
    328359
     
    356387    void LZ4TwistDecompressionKernel::beforeTermination(const std::unique_ptr<KernelBuilder> &b) {
    357388        b->CreateFree(b->getScalarField("temporaryInputPtr"));
     389        b->CreateFree(b->getScalarField("temporaryOutputPtr"));
    358390    }
    359391
Note: See TracChangeset for help on using the changeset viewer.