Ignore:
Timestamp:
Jul 14, 2015, 6:29:35 PM (4 years ago)
Author:
cameron
Message:

Carry Manager progress

File:
1 edited

Legend:

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

    r4595 r4670  
    1414namespace pablo {
    1515 
     16   
     17const unsigned bitsPerPack = 64;
     18
     19
     20void AlignUpwards(unsigned & toAlign, unsigned alignment) {
     21    if ((toAlign & (alignment - 1)) != 0) {
     22        toAlign = (toAlign + alignment) & (alignment - 1);
     23    }
     24}
     25
     26void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
     27    unsigned bitsInCurrentPack = packedTotalBits % bitsPerPack;
     28    if (bitsInCurrentPack + addedBits > bitsPerPack) {
     29        AlignUpwards(packedTotalBits, bitsPerPack);
     30    }
     31}
     32   
     33   
    1634unsigned PabloBlockCarryData::enumerate(PabloBlock & blk) {
    1735    for (Statement * stmt : blk) {
     
    1937            unsigned shift_amount = adv->getAdvanceAmount();
    2038            if (shift_amount == 1) {
    21                 adv->setLocalAdvanceIndex(unitAdvances);
    22                 unitAdvances++;               
     39                adv->setLocalAdvanceIndex(advance1.entries);
     40                advance1.entries++;               
    2341            }
    2442            else if (shift_amount < LongAdvanceBase) {
    25                 //EnsurePackHasSpace(shortAdvanceTotal, shift_amount);
    26                 //adv->setLocalAdvanceIndex(shortAdvanceTotal);
    27                 adv->setLocalAdvanceIndex(shortAdvances);
    28                 shortAdvances++;
    29                 shortAdvanceTotal += shift_amount;
     43#ifdef PACKING
     44                EnsurePackHasSpace(shortAdvance.allocatedBits, shift_amount);
     45                adv->setLocalAdvanceIndex(shortAdvance.allocatedBits);
     46#else
     47                adv->setLocalAdvanceIndex(shortAdvance.entries);
     48#endif
     49                shortAdvance.entries++;
     50                shortAdvance.allocatedBits += shift_amount;
    3051            }
    3152            else {
    32                 adv->setLocalAdvanceIndex(longAdvanceTotalBlocks);
    33                 longAdvances++;
    34                 longAdvanceTotalBlocks += longAdvanceBufferSize(shift_amount);
     53                adv->setLocalAdvanceIndex(longAdvance.allocatedBitBlocks);
     54                longAdvance.entries++;
     55                longAdvance.allocatedBitBlocks += longAdvanceBufferSize(shift_amount);
    3556            }
    3657        }
    3758        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
    38             m->setLocalCarryIndex(localCarries);
    39             ++localCarries;
     59            m->setLocalCarryIndex(addWithCarry.entries);
     60            ++addWithCarry.entries;
    4061        }
    4162        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
    42             s->setLocalCarryIndex(localCarries);
    43             ++localCarries;
     63            s->setLocalCarryIndex(addWithCarry.entries);
     64            ++addWithCarry.entries;
    4465        }
    4566    }
    46     unsigned localCarryDataIndex = localCarries + unitAdvances + shortAdvances + longAdvanceTotalBlocks;
    47     localCarryDataSize = localCarryDataIndex;
    48     /*
    49     totalCarryDataSize = longAdvanceTotalBlocks * BLOCK_SIZE;
    50     totalCarryDataSize += shortAdvanceTotal;
    51     EnsurePackHasSpace(totalCarryDataSize, localCarries);
    52     totalCarryDataSize += localCarries;
    53     EnsurePackHasSpace(totalCarryDataSize, unitAdvances);
    54     totalCarryDataSize += unitAdvances;
    55      */
     67    longAdvance.frameOffsetinBits = 0;
     68#ifdef PACKING
     69    shortAdvance.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
     70    addWithCarry.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.allocatedBits;
     71    EnsurePackHasSpace(addWithCarry.frameOffsetinBits, addWithCarry.entries);
     72    advance1.frameOffsetinBits = addWithCarry.frameOffsetinBits + addWithCarry.entries;
     73    EnsurePackHasSpace(advance1.frameOffsetinBits, advance1.entries);
     74    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries;
     75#else
     76    addWithCarry.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
     77    advance1.frameOffsetinBits = addWithCarry.frameOffsetinBits + addWithCarry.entries * BLOCK_SIZE;
     78    shortAdvance.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries * BLOCK_SIZE;
     79    nested.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.entries * BLOCK_SIZE;
     80#endif
     81    unsigned nestedframePosition = nested.frameOffsetinBits;
    5682   
    5783    for (Statement * stmt : blk) {
    5884        if (If * ifStatement = dyn_cast<If>(stmt)) {
    5985            PabloBlockCarryData & nestedBlockData = ifStatement->getBody().carryData;
    60             nestedBlockData.setIfDepth(ifDepth + 1);
    61             nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
    62             const unsigned ifCarryDataSize = nestedBlockData.enumerate(ifStatement->getBody());
    63             nestedBlockCount++;
    64             //EnsurePackHasSpace(totalCarryDataSize, ifCarryDataSize);
    65             nestedCarryDataSize += ifCarryDataSize;
    66             localCarryDataIndex += ifCarryDataSize;           
     86            nestedBlockData.ifDepth = ifDepth + 1;
     87            const unsigned ifCarryDataBits = nestedBlockData.enumerate(ifStatement->getBody());
     88#ifdef PACKING
     89            EnsurePackHasSpace(nestedframePosition, ifCarryDataBits);
     90#endif
     91            nestedBlockData.framePosition = nestedframePosition;
     92            nestedframePosition += ifCarryDataBits;
     93            if (maxNestingDepth <= nestedBlockData.maxNestingDepth) maxNestingDepth = nestedBlockData.maxNestingDepth + 1;
     94            nested.entries++;
    6795        }
    6896        else if (While * whileStatement = dyn_cast<While>(stmt)) {
    6997            PabloBlockCarryData & nestedBlockData = whileStatement->getBody().carryData;
    70             nestedBlockData.setWhileDepth(whileDepth + 1);
    71             nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
    72             unsigned whileCarryDataSize = nestedBlockData.enumerate(whileStatement->getBody());
    73             //if (whileStatement->isMultiCarry()) whileCarryDataSize *= whileStatement->getMaxIterations();
    74             nestedBlockCount++;
    75             //EnsurePackHasSpace(totalCarryDataSize, whileCarryDataSize);
    76             nestedCarryDataSize += whileCarryDataSize;
    77             localCarryDataIndex += whileCarryDataSize;
     98            nestedBlockData.whileDepth = whileDepth + 1;
     99            unsigned whileCarryDataBits = nestedBlockData.enumerate(whileStatement->getBody());
     100            //if (whileStatement->isMultiCarry()) whileCarryDataBits *= whileStatement->getMaxIterations();
     101#ifdef PACKING
     102            EnsurePackHasSpace(nestedframePosition, whileCarryDataBits);
     103#endif
     104            nestedBlockData.framePosition = nestedframePosition;
     105            nestedframePosition += whileCarryDataBits;
     106            if (maxNestingDepth <= nestedBlockData.maxNestingDepth) maxNestingDepth = nestedBlockData.maxNestingDepth + 1;
     107            nested.entries++;
    78108        }
    79109    }
    80     totalCarryDataSize = localCarryDataIndex;
    81     if ((ifDepth > 0) && (totalCarryDataSize > 1)) {
     110   
     111   
     112    totalCarryDataBits = nestedframePosition;
     113   
     114    if ((ifDepth > 0) && (totalCarryDataBits > BLOCK_SIZE)) {
    82115        // Need extra space for the summary variable, always the last
    83116        // entry within an if block.
    84         totalCarryDataSize += 1;
     117        AlignUpwards(totalCarryDataBits, BLOCK_SIZE);
     118        summary.frameOffsetinBits = totalCarryDataBits;
     119        summary.allocatedBits = BLOCK_SIZE;
     120        totalCarryDataBits += BLOCK_SIZE;
    85121    }
    86     longAdvanceOffset = 0;
    87     /*
    88     if (totalCarryDataSize > CarryPackSize) {
    89         // Need extra space for the summary variable, always the first
    90         // entry within an if block.
    91         totalCarryDataSize += BLOCK_SIZE;
    92         longAdvanceOffset = BLOCK_SIZE;
     122    else {
     123        summary.frameOffsetinBits = 0;
     124        summary.allocatedBits = totalCarryDataBits;
    93125    }
    94      */
    95     carryOffset = longAdvanceOffset + longAdvanceTotalBlocks;
    96     unitAdvanceOffset = carryOffset + localCarries;
    97     shortAdvanceOffset = unitAdvanceOffset + unitAdvances;
    98 
    99 //     std::cerr << "blockCarryDataIndex = " << blockCarryDataIndex << " nestedBlockCount = " << nestedBlockCount << std::endl;
    100 //     std::cerr << "longAdvanceOffset = " << longAdvanceOffset << " carryOffset = " << carryOffset << std::endl;
    101 //     std::cerr << "unitAdvanceOffset = " << unitAdvanceOffset << " shortAdvanceOffset = " << shortAdvanceOffset << std::endl;
    102 //     std::cerr << "ifDepth = " << ifDepth << " whileDepth = " << whileDepth << std::endl;
    103 //     std::cerr << "totalCarryDataSize = " << totalCarryDataSize << std::endl;
    104     return totalCarryDataSize;
     126    return totalCarryDataBits;
    105127}
    106128
Note: See TracChangeset for help on using the changeset viewer.