Changeset 5427


Ignore:
Timestamp:
Apr 26, 2017, 10:12:11 AM (2 years ago)
Author:
cameron
Message:

Add bit manipulation instructions to CBuilder

Location:
icGREP/icgrep-devel/icgrep
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5425 r5427  
    697697}
    698698
     699Value * CBuilder::CreateResetLowestBit(Value * bits) {
     700    return CreateAnd(bits, CreateSub(bits, ConstantInt::get(bits->getType(), 1)));
     701}
     702
     703Value * CBuilder::CreateIsolateLowestBit(Value * bits) {
     704    return CreateAnd(bits, CreateNeg(bits));
     705}
     706
     707Value * CBuilder::CreateMaskToLowestBitInclusive(Value * bits) {
     708    return CreateXor(bits, CreateSub(bits, ConstantInt::get(bits->getType(), 1)));
     709}
     710
     711Value * CBuilder::CreateMaskToLowestBitExclusive(Value * bits) {
     712    return CreateAnd(CreateSub(bits, ConstantInt::get(bits->getType(), 1)), CreateNot(bits));
     713}
     714
     715Value * CBuilder::CreateExtractBitField(llvm::Value * bits, Value * start, Value * length) {
     716    Constant * One = ConstantInt::get(bits->getType(), 1);
     717    return CreateAnd(CreateLShr(bits, start), CreateSub(CreateShl(One, length), One));
     718}
     719
    699720Value * CBuilder::CreateCeilLog2(Value * value) {
    700721    IntegerType * ty = cast<IntegerType>(value->getType());
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5425 r5427  
    183183
    184184    llvm::Value * CreateCountReverseZeroes(llvm::Value * value);
    185 
     185   
     186    // Useful bit manipulation operations 
     187    llvm::Value * CreateResetLowestBit(llvm::Value * bits);   
     188   
     189    llvm::Value * CreateIsolateLowestBit(llvm::Value * bits);
     190   
     191    llvm::Value * CreateMaskToLowestBitInclusive(llvm::Value * bits);
     192   
     193    llvm::Value * CreateMaskToLowestBitExclusive(llvm::Value * bits);
     194   
     195    llvm::Value * CreateExtractBitField(llvm::Value * bits, llvm::Value * start, llvm::Value * length);
     196   
    186197    llvm::Value * CreateCeilLog2(llvm::Value * value);
    187198   
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5419 r5427  
    9898            // The loop body is entered if we have more matches to process.
    9999            iBuilder->SetInsertPoint(processMatchesEntry);
    100             Value * prior_breaks = iBuilder->CreateAnd(makeForwardZeroesMask(phiMatchWord), phiRecordBreaks);
     100            Value * prior_breaks = iBuilder->CreateAnd(iBuilder->CreateMaskToLowestBitExclusive(phiMatchWord), phiRecordBreaks);
    101101            // Within the loop we have a conditional block that is executed if there are any prior record breaks.
    102102            Value * prior_breaks_cond = iBuilder->CreateICmpNE(prior_breaks, ConstantInt::getNullValue(sizeTy));
     
    142142            }
    143143
    144             Value * remaining_matches = resetLowestBit(phiMatchWord);
     144            Value * remaining_matches = iBuilder->CreateResetLowestBit(phiMatchWord);
    145145            phiMatchWord->addIncoming(remaining_matches, loop_final_block);
    146146
     
    187187    setScalarField("LineNum", phiFinalRecordNum);
    188188    setProcessedItemCount("InputStream", phiFinalRecordStart);
    189 }
    190 
    191 inline Value * ScanMatchKernel::makeForwardZeroesMask(Value * const value) const {
    192     return iBuilder->CreateAnd(iBuilder->CreateSub(value, ConstantInt::get(value->getType(), 1)), iBuilder->CreateNot(value));
    193 }
    194 
    195 inline Value * ScanMatchKernel::resetLowestBit(Value * const value) const {
    196     return iBuilder->CreateAnd(iBuilder->CreateSub(value, ConstantInt::get(value->getType(), 1)), value);
    197189}
    198190
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5411 r5427  
    2121    void generateDoBlockMethod() override;
    2222private:
    23     llvm::Value * makeForwardZeroesMask(llvm::Value * const value) const;
    24     llvm::Value * resetLowestBit(llvm::Value * const value) const;
    25 private:
    2623    const GrepType      mGrepType;
    2724};
Note: See TracChangeset for help on using the changeset viewer.