Ignore:
Timestamp:
Jul 30, 2015, 11:43:04 AM (4 years ago)
Author:
cameron
Message:

Bit packing progress

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4706 r4707  
    256256}
    257257
    258 Value * CarryManager::getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize) {
    259 
    260     unsigned packIndex = carryBit_lo / PACK_SIZE;
    261     unsigned carryOffset = carryBit_lo % PACK_SIZE;
    262    
    263     Value * carryItem = getCarryPack(packIndex);
    264     if (carryRangeSize == PACK_SIZE) {
    265         assert(carryOffset == 0);
    266         return carryItem;
    267     }
    268     unsigned mask = (1 << carryRangeSize) - 1;
    269     return mBuilder->CreateAnd(carryItem, mBuilder->getInt64(mask << carryOffset));
    270 }
    271    
    272 Value * CarryManager::getCarryBits(unsigned carryBitPos, unsigned carryBitCount) {
    273    
    274     unsigned carryOffset = carryBitPos % PACK_SIZE;
    275 
    276     Value * carryRange = getCarryRange(carryBitPos, carryBitCount);
    277     if (carryOffset == 0) return carryRange;
    278     return mBuilder->CreateLShr(carryRange, carryOffset);
    279 }
    280 
    281 Value * CarryManager::getCarryBit(unsigned carryBitPos) {
    282     return getCarryBits(carryBitPos, 1);
    283 }
    284 
    285 /*  NOTE: In the following the mCarryOutPack is an accumulator.
     258/* maskSelectBitRange selects the bits of a pack from lo_bit through
     259 lo_bit + bitCount - 1, setting all other bits to zero.  */
     260
     261Value * CarryManager::maskSelectBitRange(Value * pack, unsigned lo_bit, unsigned bitCount) {
     262    if (bitCount == PACK_SIZE) {
     263        assert(lo_bit == 0);
     264        return pack;
     265    }
     266    unsigned mask = (1 << bitCount) - 1;
     267    return mBuilder->CreateAnd(pack, mBuilder->getInt64(mask << lo_bit));
     268}
     269
     270Value * CarryManager::getCarryInBits(unsigned carryBitPos, unsigned carryBitCount) {
     271    unsigned packIndex = carryBitPos / PACK_SIZE;
     272    unsigned packOffset = carryBitPos % PACK_SIZE;
     273    Value * selected = maskSelectBitRange(getCarryPack(packIndex), packOffset, carryBitCount);
     274    if (packOffset == 0) return selected;
     275    return mBuilder->CreateLShr(selected, packOffset);
     276}
     277
     278void CarryManager::extractAndSaveCarryOutBits(Value * bitblock, unsigned carryBit_pos, unsigned carryBitCount) {
     279   
     280    unsigned packIndex = carryBit_pos / PACK_SIZE;
     281    unsigned packOffset = carryBit_pos % PACK_SIZE;
     282    unsigned rshift = PACK_SIZE - packOffset - carryBitCount;
     283    Value * field = iBuilder->mvmd_extract(PACK_SIZE, bitblock, BLOCK_SIZE/PACK_SIZE - 1);
     284    //Value * field = maskSelectBitRange(field, PACK_SIZE - carryBitCount, carryBitCount);
     285    if (rshift != 0) {
     286        field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
     287    }
     288    if (packOffset != 0) {
     289        field = mBuilder->CreateAnd(field, mBuilder->getInt64(((1<<carryBitCount) - 1) << packOffset));
     290    }
     291    if (mCarryOutPack[packIndex] == nullptr) {
     292        mCarryOutPack[packIndex] = field;
     293    }
     294    else {
     295        mCarryOutPack[packIndex] = mBuilder->CreateOr(mCarryOutPack[packIndex], field);
     296    }
     297}
     298
     299Value * CarryManager::pack2bitblock(Value * pack) {
     300    return mBuilder->CreateBitCast(mBuilder->CreateZExt(pack, mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
     301}
     302   
     303    /*  NOTE: In the following the mCarryOutPack is an accumulator.
    286304    It must be created at the appropriate outer level.  */
    287305void CarryManager::setCarryBits(unsigned carryBit_lo, unsigned carryRangeSize, Value * bits) {
     
    308326    unsigned posn = carryOpPosition(localIndex);
    309327#ifdef PACKING
    310     return  mBuilder->CreateBitCast(mBuilder->CreateZExt(getCarryBit(posn), mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
     328    return pack2bitblock(getCarryInBits(posn, 1));
    311329#else
    312330    return getCarryPack(posn);
     
    345363    unsigned posn = advance1Position(localIndex);
    346364#ifdef PACKING
    347     unsigned offset = posn % PACK_SIZE;
    348     unsigned rshift = PACK_SIZE - offset - 1;
    349     Value * field = iBuilder->mvmd_extract(PACK_SIZE, strm, BLOCK_SIZE/PACK_SIZE - 1);
    350     if (rshift != 0) {
    351         field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
    352     }
    353     if (offset != 0) {
    354         field = mBuilder->CreateAnd(field, mBuilder->getInt64(1<<offset));
    355     }
    356     setCarryBits(posn - offset, 1, field);
    357     Value* carry_longint = mBuilder->CreateZExt(getCarryBit(posn), mBuilder->getIntNTy(BLOCK_SIZE));
     365    extractAndSaveCarryOutBits(strm, posn, 1);
     366    Value* carry_longint = mBuilder->CreateZExt(getCarryInBits(posn, 1), mBuilder->getIntNTy(BLOCK_SIZE));
    358367    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
    359368    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), carry_longint);
     
    385394    unsigned posn = shortAdvancePosition(localIndex);
    386395#ifdef PACKING
    387     unsigned offset = posn % PACK_SIZE;
    388     unsigned rshift = PACK_SIZE - offset - shift_amount;
    389     Value * field = iBuilder->mvmd_extract(PACK_SIZE, strm, BLOCK_SIZE/PACK_SIZE - 1);
    390     if (rshift != 0) {
    391         field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
    392     }
    393     if (offset != 0) {
    394         field = mBuilder->CreateAnd(field, mBuilder->getInt64(((1<<shift_amount) - 1) << offset));
    395     }   
    396     setCarryBits(posn - offset, shift_amount, field);
    397     Value* carry_longint = mBuilder->CreateZExt(getCarryBits(posn, shift_amount), mBuilder->getIntNTy(BLOCK_SIZE));
     396    extractAndSaveCarryOutBits(strm, posn, shift_amount);
     397    Value* carry_longint = mBuilder->CreateZExt(getCarryInBits(posn, shift_amount), mBuilder->getIntNTy(BLOCK_SIZE));
    398398    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
    399399    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), carry_longint);
     
    480480    unsigned summary_posn = summaryPosition();
    481481#ifdef PACKING
    482     return mBuilder->CreateBitCast(mBuilder->CreateZExt(getCarryRange(summary_posn, summaryBits()), mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
     482    Value * pack = getCarryPack(summary_posn/PACK_SIZE);
     483    Value * summary_bits = maskSelectBitRange(pack, summary_posn % PACK_SIZE, summaryBits());
     484    return mBuilder->CreateBitCast(mBuilder->CreateZExt(summary_bits, mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
    483485#else
    484486    return getCarryPack(summary_posn);
     
    502504    }
    503505#ifdef PACKING
    504     if (ifScopeCarrySize < PACK_SIZE) {
     506    if (ifScopeCarrySize <= PACK_SIZE) {
    505507        unsigned const ifPackIndex = scopeBasePack();
    506508        PHINode * ifPack_phi = mBuilder->CreatePHI(mCarryPackType, 2, "ifPack");
     
    508510        ifPack_phi->addIncoming(mCarryOutPack[ifPackIndex], ifBodyFinalBlock);
    509511        mCarryOutPack[ifPackIndex] = ifPack_phi;
     512        return;
    510513    }
    511514#endif
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4704 r4707  
    7272    Value * getCarryOpCarryIn(int localIndex);
    7373    void setCarryOpCarryOut(unsigned idx, Value * carry_out);
     74    Value * addCarryInCarryOut(int localIndex, Value* e1, Value* e2);
     75
    7476
    7577    Value * advanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm);
     
    137139    void storeCarryPack(unsigned packIndex);
    138140   
    139     Value * getCarryRange(unsigned carryBit_lo, unsigned carryRangeSize);     
    140     Value * getCarryBits(unsigned carryBitPos, unsigned bits);
    141     Value * getCarryBit(unsigned carryBitPos);
     141    Value * maskSelectBitRange(Value * pack, unsigned lo_bit, unsigned bitCount);     
     142    Value * getCarryInBits(unsigned carryBitPos, unsigned bits);
    142143    void setCarryBits(unsigned carryBit_lo, unsigned carryRangeSize, Value * bits);
     144    void extractAndSaveCarryOutBits(Value * strm, unsigned carryBit_lo, unsigned carryBitCount);
     145    Value * pack2bitblock(Value * pack);
    143146
    144147    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
Note: See TracChangeset for help on using the changeset viewer.