Changeset 4697 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jul 24, 2015, 11:47:14 AM (4 years ago)
Author:
cameron
Message:

Further progress on Carry Manager with bit packing

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r4665 r4697  
    151151}
    152152
     153Value * IDISA_Builder::mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex) {
     154    Value * aVec = fwCast(fw, a);
     155    return mLLVMBuilder->CreateExtractElement(aVec, mLLVMBuilder->getInt32(fieldIndex));
     156}
     157
    153158Value * IDISA_Builder::mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift) {
    154159    unsigned field_count = mBitBlockSize/fw;
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r4665 r4697  
    5858    Value * hsimd_signmask(unsigned fw, Value * a);
    5959
     60   
     61    Value * mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex);
    6062    Value * mvmd_dslli(unsigned fw, Value * a, Value * b, unsigned shift);
    6163   
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.h

    r4696 r4697  
    9292    }
    9393   
    94     unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    95         return fullOrPartialBlocks(longAdvance.frameOffsetinBits, BLOCK_SIZE) + advanceIndex;
    96     }
    97    
    9894    unsigned longAdvanceEntries(unsigned shift_amount) const {
    9995        return fullOrPartialBlocks(shift_amount, BLOCK_SIZE);
     
    105101   
    106102    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
    107    
    108     unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    109         return fullOrPartialBlocks(shortAdvance.frameOffsetinBits, PACK_SIZE) + advanceIndex;
    110     }
    111    
    112     unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    113         return fullOrPartialBlocks(advance1.frameOffsetinBits, PACK_SIZE) + advanceIndex;
    114     }
    115    
    116     unsigned carryOpCarryDataOffset(unsigned idx)  const {
    117         return fullOrPartialBlocks(addWithCarry.frameOffsetinBits, PACK_SIZE) + idx;
    118     }
    119    
    120     unsigned summaryCarryDataIndex()  const {
    121         return fullOrPartialBlocks(summary.frameOffsetinBits, PACK_SIZE);
    122     }
    123103   
    124104    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4696 r4697  
    146146/* Helper routines */
    147147
     148unsigned CarryManager::absPosition(unsigned frameOffsetinBits, unsigned relPos) {
     149#ifdef PACKING
     150    return mCurrentFrameIndex + frameOffsetinBits + relPos;
     151#else
     152    return mCurrentFrameIndex + frameOffsetinBits/BLOCK_SIZE + relPos;
     153#endif
     154}
     155
     156
     157unsigned CarryManager::carryOpPosition(unsigned localIndex) {
     158    return absPosition(mCarryInfo->addWithCarry.frameOffsetinBits, localIndex);
     159}
     160
     161unsigned CarryManager::advance1Position(unsigned localIndex) {
     162    return absPosition(mCarryInfo->advance1.frameOffsetinBits, localIndex);
     163}
     164
     165unsigned CarryManager::shortAdvancePosition(unsigned localIndex) {
     166    return absPosition(mCarryInfo->shortAdvance.frameOffsetinBits, localIndex);
     167}
     168
     169unsigned CarryManager::longAdvancePosition(unsigned localIndex) {
     170    return absPosition(mCarryInfo->longAdvance.frameOffsetinBits, localIndex);
     171}
     172
     173unsigned CarryManager::summaryPosition() {
     174    return absPosition(mCarryInfo->summary.frameOffsetinBits, 0);
     175}
     176
     177unsigned CarryManager::summaryBits() {
     178    return mCarryInfo->summary.allocatedBits;
     179}
     180
     181
    148182
    149183Value * CarryManager::getCarryPack(unsigned packIndex) {
     
    199233   
    200234Value * CarryManager::getCarryOpCarryIn(int localIndex) {
    201     unsigned cd_index = mCurrentFrameIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
    202 #ifdef PACKING
    203     return getCarryBit(cd_index);
    204 #else
    205     return getCarryPack(cd_index);
     235    unsigned posn = carryOpPosition(localIndex);
     236#ifdef PACKING
     237    return getCarryBit(posn);
     238#else
     239    return getCarryPack(posn);
    206240#endif
    207241}
     
    209243   
    210244void CarryManager::setCarryOpCarryOut(unsigned localIndex, Value * carry_out) {
    211 #ifdef PACKING
    212 #else
    213     unsigned cd_index = mCurrentFrameIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
    214     mCarryOutPack[cd_index] = carry_out;
     245    unsigned posn = carryOpPosition(localIndex);
     246#ifdef PACKING
     247    setCarryBits(posn, carry_out);
     248#else
     249    mCarryOutPack[posn] = carry_out;
    215250    if (mCarryInfo->getWhileDepth() == 0) {
    216         storeCarryPack(cd_index);
     251        storeCarryPack(posn);
    217252    }
    218253#endif
     
    233268
    234269Value * CarryManager::unitAdvanceCarryInCarryOut(int localIndex, Value * strm) {
    235 #ifdef PACKING
    236 #else
    237    
    238     unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->unitAdvanceCarryDataOffset(localIndex);
    239     mCarryOutPack[carryDataIndex] = strm;
    240     Value * carry_in = getCarryPack(carryDataIndex);
     270    unsigned posn = advance1Position(localIndex);
     271#ifdef PACKING
     272    unsigned offset = posn % PACK_SIZE;
     273    unsigned rshift = PACK_SIZE - offset - 1;
     274    Value * field = iBuilder->mvmd_extract(PACK_SIZE, strm, BLOCK_SIZE/PACK_SIZE - 1);
     275    if (rshift != 0) {
     276        field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
     277    }
     278    if (offset != 0) {
     279        field = mBuilder->CreateAnd(field, mBuilder->getInt64(1<<offset));
     280    }
     281    setCarryBits(posn - offset, field);
     282    Value* carry_longint = mBuilder->CreateZExt(getCarryBit(posn), mBuilder->getIntNTy(BLOCK_SIZE));
     283    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     284    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), carry_longint);
     285    result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     286    return result_value;
     287#else
     288    mCarryOutPack[posn] = strm;
     289    Value * carry_in = getCarryPack(posn);
    241290    if (mCarryInfo->getWhileDepth() == 0) {
    242         storeCarryPack(carryDataIndex);
     291        storeCarryPack(posn);
    243292    }
    244293    Value* result_value;
     
    259308
    260309Value * CarryManager::shortAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * strm) {
    261 #ifdef PACKING
    262 #else
    263     unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->shortAdvanceCarryDataOffset(localIndex);
    264     mCarryOutPack[carryDataIndex] = strm;
    265     Value * carry_in = getCarryPack(carryDataIndex);
     310    unsigned posn = shortAdvancePosition(localIndex);
     311#ifdef PACKING
     312    unsigned offset = posn % PACK_SIZE;
     313    unsigned rshift = PACK_SIZE - offset - shift_amount;
     314    Value * field = iBuilder->mvmd_extract(PACK_SIZE, strm, BLOCK_SIZE/PACK_SIZE - 1);
     315    if (rshift != 0) {
     316        field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
     317    }
     318    if (offset != 0) {
     319        field = mBuilder->CreateAnd(field, mBuilder->getInt64(((1<<shift_amount) - 1) << offset));
     320    }   
     321    setCarryBits(posn - offset, field);
     322    Value* carry_longint = mBuilder->CreateZExt(getCarryRange(posn, shift_amount), mBuilder->getIntNTy(BLOCK_SIZE));
     323    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     324    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), carry_longint);
     325    result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     326    return result_value;
     327#else
     328    mCarryOutPack[posn] = strm;
     329    Value * carry_in = getCarryPack(posn);
    266330    if (mCarryInfo->getWhileDepth() == 0) {
    267         storeCarryPack(carryDataIndex);
     331        storeCarryPack(posn);
    268332    }
    269333    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     
    294358   
    295359Value * CarryManager::longAdvanceCarryInCarryOut(int localIndex, int shift_amount, Value * carry_out) {
    296     unsigned carryDataIndex = mCurrentFrameIndex + mCarryInfo->longAdvanceCarryDataOffset(localIndex);
     360    unsigned carryDataIndex = longAdvancePosition(localIndex);
    297361    Value * advBaseIndex = mBuilder->getInt64(carryDataIndex);
    298362    if (shift_amount <= BLOCK_SIZE) {
     
    339403
    340404Value * CarryManager::getCarrySummaryExpr() {
    341 #ifdef PACKING
    342 #else
    343     unsigned summary_idx = mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex();
    344     return getCarryPack(summary_idx);
     405    unsigned summary_posn = summaryPosition();
     406#ifdef PACKING
     407    return getCarryRange(summary_posn, getSummaryBits());
     408#else
     409    return getCarryPack(summary_posn);
    345410#endif
    346411}
     
    352417        return;
    353418    }
    354     const unsigned carrySummaryIndex = mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex();
     419    const unsigned carrySummaryIndex = summaryPosition();
    355420    PHINode * summary_phi = mBuilder->CreatePHI(mBitBlockType, 2, "summary");
    356421    summary_phi->addIncoming(mZeroInitializer, ifEntryBlock);
     
    368433    }
    369434   
    370     const unsigned carrySummaryIndex = mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex();
     435    const unsigned carrySummaryIndex = summaryPosition();
    371436   
    372437    Value * carry_summary = mZeroInitializer;
     
    390455                enterScope(inner_blk);
    391456                if (blockHasCarries()) {
    392                   carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
     457                  carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPosition()]);
    393458                }
    394459                leaveScope();
     
    398463                enterScope(inner_blk);
    399464                if (blockHasCarries()) {
    400                     carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[mCurrentFrameIndex + mCarryInfo->summaryCarryDataIndex()]);
     465                    carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPosition()]);
    401466                }
    402467                leaveScope();
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4696 r4697  
    136136    void setCarryBits(unsigned carryBit_lo, Value * bits);
    137137
    138    
    139    
     138    unsigned absPosition(unsigned frameOffsetinBits, unsigned relPos);
     139    unsigned carryOpPosition(unsigned localIndex) ;
     140    unsigned advance1Position(unsigned localIndex);
     141    unsigned shortAdvancePosition(unsigned localIndex);
     142    unsigned longAdvancePosition(unsigned localIndex);
     143    unsigned summaryPosition();
     144    unsigned summaryBits();
     145
    140146};
    141147
Note: See TracChangeset for help on using the changeset viewer.