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

Support over UTF-16 representation of Unicode

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
4 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
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r5025 r5045  
    3030        ~PipelineBuilder();
    3131
    32         void CreateKernels(pablo::PabloFunction * function, bool isNameExpression);
    33     llvm::Function * ExecuteKernels(bool CountOnly);
     32        void CreateKernels(pablo::PabloFunction * function, bool UTF_16, bool isNameExpression);
     33    llvm::Function * ExecuteKernels(bool CountOnly, bool UTF_16);
    3434
    3535private:
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.cpp

    r4986 r5045  
    2828}
    2929
    30 inline void s2p(IDISA::IDISA_Builder * iBuilder, Value * input, Value * output[]) {
     30void s2p(IDISA::IDISA_Builder * iBuilder, Value * input[], Value * output[]) {
    3131    Value * bit00224466[4];
    3232    Value * bit11335577[4];
    3333
    3434    for (unsigned i = 0; i < 4; i++) {
    35         Value * s0 = iBuilder->CreateBlockAlignedLoad(input, {iBuilder->getInt32(0), iBuilder->getInt32(2 * i)});
    36         Value * s1 = iBuilder->CreateBlockAlignedLoad(input, {iBuilder->getInt32(0), iBuilder->getInt32(2 * i + 1)});
     35        Value * s0 = input[2 * i];
     36        Value * s1 = input[2 * i + 1];
    3737        s2p_step(iBuilder, s0, s1, iBuilder->simd_himask(2), 1, bit00224466[i], bit11335577[i]);
    3838    }
     
    5151    s2p_step(iBuilder, bit22226666[0], bit22226666[1], iBuilder->simd_himask(8), 4, output[2], output[6]);
    5252    s2p_step(iBuilder, bit33337777[0], bit33337777[1], iBuilder->simd_himask(8), 4, output[3], output[7]);
     53}
     54
     55void s2p(IDISA::IDISA_Builder * iBuilder, Value * input, Value * output[]) {
     56    Value * bit[8];
     57    for (unsigned i = 0; i < 8; i++) {
     58        bit[i] = iBuilder->CreateBlockAlignedLoad(input, {iBuilder->getInt32(0), iBuilder->getInt32(i)});
     59    }
     60    s2p(iBuilder, bit, output);
    5361}
    5462
     
    7179}
    7280
     81void generateS2P_16Kernel(Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder) {
     82        kBuilder->addInputStream(16, "unit_pack");
     83        for(unsigned i = 0; i < 16; i++) {
     84                kBuilder->addOutputStream(1);
     85        }
     86        kBuilder->prepareFunction();
     87
     88    Value * ptr = kBuilder->getInputStream(0);
     89
     90    Value * lo[8];
     91    Value * hi[8];
     92    for (unsigned i = 0; i < 8; i++) {
     93        Value * s0 = iBuilder->CreateBlockAlignedLoad(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2 * i)});
     94        Value * s1 = iBuilder->CreateBlockAlignedLoad(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(2 * i + 1)});
     95        lo[i] = iBuilder->hsimd_packl(16, s0, s1);
     96        hi[i] = iBuilder->hsimd_packh(16, s0, s1);
     97    }
     98
     99    Value * output[16];
     100    s2p(iBuilder, lo, output);
     101    s2p(iBuilder, hi, output + 8);
     102    for (unsigned j = 0; j < 16; j++) {
     103        iBuilder->CreateBlockAlignedStore(output[j], kBuilder->getOutputStream(j));
     104    }
     105    kBuilder->finalize();
     106}
     107       
    73108void generateS2P_idealKernel(Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder) {
    74109    kBuilder->addInputStream(8, "byte_pack");
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r4976 r5045  
    1515
    1616    void generateS2PKernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
     17        void generateS2P_16Kernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    1718    void generateS2P_idealKernel(llvm::Module *, IDISA::IDISA_Builder * iBuilder, KernelBuilder * kBuilder);
    1819
Note: See TracChangeset for help on using the changeset viewer.