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/IR_Gen
Files:
2 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   
Note: See TracChangeset for help on using the changeset viewer.