Ignore:
Timestamp:
Jun 9, 2016, 3:34:07 PM (3 years ago)
Author:
xuedongx
Message:

Support over UTF-16 representation of Unicode

File:
1 edited

Legend:

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

    r5042 r5045  
    3636}
    3737
    38 void PipelineBuilder::CreateKernels(PabloFunction * function, bool isNameExpression){
     38void PipelineBuilder::CreateKernels(PabloFunction * function, bool UTF_16, bool isNameExpression){
    3939    mS2PKernel = new KernelBuilder(iBuilder, "s2p", codegen::SegmentSize);
    4040    mICgrepKernel = new KernelBuilder(iBuilder, "icgrep", codegen::SegmentSize);
    4141    mScanMatchKernel = new KernelBuilder(iBuilder, "scanMatch", codegen::SegmentSize);
    42     generateS2PKernel(mMod, iBuilder, mS2PKernel);
     42        if (UTF_16) {
     43                generateS2P_16Kernel(mMod, iBuilder, mS2PKernel);
     44        }
     45        else {
     46                generateS2PKernel(mMod, iBuilder, mS2PKernel);
     47        }
    4348    generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel, isNameExpression);
    4449    pablo_function_passes(function);
     
    6873}
    6974
    70 Function * PipelineBuilder::ExecuteKernels(bool CountOnly) {
     75Function * PipelineBuilder::ExecuteKernels(bool CountOnly, bool UTF_16) {
    7176    Type * const int64ty = iBuilder->getInt64Ty();
    7277    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    73     Type * const inputType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), std::vector<Type *>({ArrayType::get(mBitBlockType, 8)})), 1), 0);
     78    Type * const inputType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), std::vector<Type *>({ArrayType::get(mBitBlockType, (UTF_16 ? 16 : 8))})), 1), 0);
    7479    Type * const resultTy = CountOnly ? int64ty : iBuilder->getVoidTy();
    7580    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", resultTy, inputType, int64ty, int64ty, iBuilder->getInt1Ty(), nullptr));
     
    128133        PHINode * remainingBytes = iBuilder->CreatePHI(int64ty, 2, "remainingBytes");
    129134        remainingBytes->addIncoming(bufferSize, entryBlock);
    130         Constant * const step = ConstantInt::get(int64ty, mBlockSize * segmentSize);
     135        Constant * const step = ConstantInt::get(int64ty, mBlockSize * segmentSize * (UTF_16 ? 2 : 1));
    131136        Value * segmentCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
    132137        iBuilder->CreateCondBr(segmentCondTest, fullCondBlock, segmentBodyBlock);
     
    145150                Value * prev_count = iBuilder->CreateBitCast(temp_count, iBuilder->getIntNTy(mBlockSize));
    146151                Value * add_for = iBuilder->CreateAdd(prev_count, popcount_for);
    147                 iBuilder->CreateStore(add_for, count);
     152                Value * add = iBuilder->CreateBitCast(add_for, mBitBlockType);
     153                iBuilder->CreateStore(add, count);
    148154            }
    149155        }
     
    167173    remainingBytes->addIncoming(initialBufferSize, initialBlock);
    168174
    169     Constant * const step = ConstantInt::get(int64ty, mBlockSize);
     175    Constant * const step = ConstantInt::get(int64ty, mBlockSize * (UTF_16 ? 2 : 1));
    170176    Value * fullCondTest = iBuilder->CreateICmpULT(remainingBytes, step);
    171177    iBuilder->CreateCondBr(fullCondTest, finalBlock, fullBodyBlock);
     
    201207    iBuilder->SetInsertPoint(exitBlock);
    202208
    203     Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(mBlockSize));
    204     Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), remaining);
     209    Value * remainingByte = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(mBlockSize));
     210        Value * remainingUnit = iBuilder->CreateLShr(remainingByte, ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1));
     211    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), UTF_16 ? remainingUnit : remainingByte);
    205212        icGrepInstance->setInternalState("EOFmark", iBuilder->CreateBitCast(EOFmark, mBitBlockType));
    206213
Note: See TracChangeset for help on using the changeset viewer.