Ignore:
Timestamp:
Jul 10, 2015, 9:10:06 AM (4 years ago)
Author:
cameron
Message:

Move logic for advance operations entirely within carry manager.

File:
1 edited

Legend:

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

    r4647 r4654  
    2121    mPabloRoot = pb;
    2222    mCarryDataPtr = carryPtr;
     23    iBuilder = new IDISA::IDISA_Builder(mMod, mBuilder, mBitBlockType);
    2324   
    2425    PabloBlockCarryData & cd = pb->carryData;
     
    5455}
    5556
    56 Value * CarryManager::getUnitAdvanceCarryIn(PabloBlock * blk, int localIndex) {
    57     PabloBlockCarryData & cd = blk->carryData;
    58     if (cd.getWhileDepth() == 0) {
    59        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.unitAdvanceCarryDataOffset(localIndex)));
    60        mCarryInVector[cd.unitAdvanceCarryDataOffset(localIndex)] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    61     }
    62     return mCarryInVector[cd.unitAdvanceCarryDataOffset(localIndex)];
    63 }
    64 
    65 Value * CarryManager::getShortAdvanceCarryIn(PabloBlock * blk, int localIndex, int shift_amount) {
    66     PabloBlockCarryData & cd = blk->carryData;
    67     if (cd.getWhileDepth() == 0) {
    68        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.shortAdvanceCarryDataOffset(localIndex)));
    69        mCarryInVector[cd.shortAdvanceCarryDataOffset(localIndex)] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    70     }
    71     return mCarryInVector[cd.shortAdvanceCarryDataOffset(localIndex)];
    72 }
    73 
    7457void CarryManager::setCarryOpCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out) {
    7558    PabloBlockCarryData & cd = blk->carryData;
     
    8164}
    8265
    83 void CarryManager::setUnitAdvanceCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out) {
    84     PabloBlockCarryData & cd = blk->carryData;
    85     mCarryOutVector[cd.unitAdvanceCarryDataOffset(idx)] = carry_out;
     66   
     67Value * CarryManager::advanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm) {
     68    if (shift_amount == 1) {
     69        return unitAdvanceCarryInCarryOut(blk, localIndex, strm);
     70    }
     71    else if (shift_amount < LongAdvanceBase) {
     72        return shortAdvanceCarryInCarryOut(blk, localIndex, shift_amount, strm);
     73    }
     74    else {
     75        return longAdvanceCarryInCarryOut(blk, localIndex, shift_amount, strm);
     76    }
     77}
     78
     79Value * CarryManager::unitAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, Value * strm) {
     80    PabloBlockCarryData & cd = blk->carryData;
     81    unsigned carryDataIndex = cd.unitAdvanceCarryDataOffset(localIndex);
     82    mCarryOutVector[carryDataIndex] = strm;
    8683    if (cd.getWhileDepth() == 0) {
    87        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.unitAdvanceCarryDataOffset(idx)));
    88        mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
    89     }
    90 }
    91 
    92 void CarryManager::setShortAdvanceCarryOut(PabloBlock * blk, unsigned idx, int shift_amount, Value * carry_out) {
    93     PabloBlockCarryData & cd = blk->carryData;
    94     mCarryOutVector[cd.shortAdvanceCarryDataOffset(idx)] = carry_out;
     84        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     85        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
     86        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
     87       
     88    }
     89    Value * carry_in = mCarryInVector[carryDataIndex];
     90    Value* result_value;
     91   
     92#if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
     93    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     94    Value* advanceq_value = mBuilder->CreateBitCast(mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), mBitBlockType);
     95    Value* srli_1_value = mBuilder->CreateLShr(strm, 63);
     96    Value* packed_shuffle;
     97    Constant* const_packed_1_elems [] = {mBuilder->getInt32(0), mBuilder->getInt32(2)};
     98    Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
     99    packed_shuffle = mBuilder->CreateShuffleVector(advanceq_value, srli_1_value, const_packed_1);
     100   
     101    Constant* const_packed_2_elems[] = {mBuilder->getInt64(1), mBuilder->getInt64(1)};
     102    Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
     103   
     104    Value* shl_value = mBuilder->CreateShl(strm, const_packed_2);
     105    result_value = mBuilder->CreateOr(shl_value, packed_shuffle, "advance");
     106#else
     107    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     108    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     109    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), "advance");
     110    result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     111   
     112#endif
     113    return result_value;
     114}
     115
     116Value * CarryManager::shortAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm) {
     117    PabloBlockCarryData & cd = blk->carryData;
     118    unsigned carryDataIndex = cd.shortAdvanceCarryDataOffset(localIndex);
     119    mCarryOutVector[carryDataIndex] = strm;
    95120    if (cd.getWhileDepth() == 0) {
    96        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.shortAdvanceCarryDataOffset(idx)));
    97        mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
    98     }
    99 }
    100    
    101 /*
     121        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     122        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
     123        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
     124       
     125    }
     126    Value * carry_in = mCarryInVector[carryDataIndex];
     127    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     128    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     129    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
     130    return mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     131}
     132   
     133
     134/*  currently defined in carry_data.h
     135 
    102136 static unsigned power2ceil (unsigned v) {
    103137 unsigned ceil = 1;
     
    115149 */
    116150
     151   
    117152Value * CarryManager::longAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * carry_out) {
    118153    PabloBlockCarryData & cd = blk->carryData;
Note: See TracChangeset for help on using the changeset viewer.