source: icGREP/icgrep-devel/icgrep/pablo/carry_data.cpp @ 4578

Last change on this file since 4578 was 4566, checked in by cameron, 4 years ago

Restructure to create separate carry data module

File size: 4.6 KB
Line 
1/*
2 *  Copyright (c) 2015 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7
8#include <include/simd-lib/bitblock.hpp>
9#include <pablo/pablo_compiler.h>
10#include <pablo/codegenstate.h>
11#include <pablo/carry_data.h>
12#include <iostream>
13
14namespace pablo {
15 
16unsigned PabloBlockCarryData::enumerate(PabloBlock & blk) {
17    for (Statement * stmt : blk) {
18        if (Advance * adv = dyn_cast<Advance>(stmt)) {
19            unsigned shift_amount = adv->getAdvanceAmount();
20            if (shift_amount == 1) {
21                adv->setLocalAdvanceIndex(unitAdvances);
22                unitAdvances++;               
23            }
24            else if (shift_amount < LongAdvanceBase) {
25                //EnsurePackHasSpace(shortAdvanceTotal, shift_amount);
26                //adv->setLocalAdvanceIndex(shortAdvanceTotal);
27                adv->setLocalAdvanceIndex(shortAdvances);
28                shortAdvances++;
29                shortAdvanceTotal += shift_amount;
30            }
31            else {
32                adv->setLocalAdvanceIndex(longAdvanceTotalBlocks);
33                longAdvances++;
34                longAdvanceTotalBlocks += longAdvanceBufferSize(shift_amount);
35            }
36        }
37        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
38            m->setLocalCarryIndex(localCarries);
39            ++localCarries;
40        }
41        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
42            s->setLocalCarryIndex(localCarries);
43            ++localCarries;
44        }
45    }
46    unsigned localCarryDataIndex = localCarries + unitAdvances + shortAdvances + longAdvanceTotalBlocks;
47    /*
48    totalCarryDataSize = longAdvanceTotalBlocks * BLOCK_SIZE;
49    totalCarryDataSize += shortAdvanceTotal;
50    EnsurePackHasSpace(totalCarryDataSize, localCarries);
51    totalCarryDataSize += localCarries;
52    EnsurePackHasSpace(totalCarryDataSize, unitAdvances);
53    totalCarryDataSize += unitAdvances;
54     */
55   
56    for (Statement * stmt : blk) {
57        if (If * ifStatement = dyn_cast<If>(stmt)) {
58            PabloBlockCarryData & nestedBlockData = ifStatement->getBody().carryData;
59            nestedBlockData.setIfDepth(ifDepth + 1);
60            nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
61            const unsigned ifCarryDataSize = nestedBlockData.enumerate(ifStatement->getBody());
62            nestedBlockCount++;
63            //EnsurePackHasSpace(totalCarryDataSize, ifCarryDataSize);
64            nestedCarryDataSize += ifCarryDataSize;
65            localCarryDataIndex += ifCarryDataSize;           
66        }
67        else if (While * whileStatement = dyn_cast<While>(stmt)) {
68            PabloBlockCarryData & nestedBlockData = whileStatement->getBody().carryData;
69            nestedBlockData.setWhileDepth(whileDepth + 1);
70            nestedBlockData.setBlockCarryDataIndex(blockCarryDataIndex + localCarryDataIndex);
71            unsigned whileCarryDataSize = nestedBlockData.enumerate(whileStatement->getBody());
72            //if (whileStatement->isMultiCarry()) whileCarryDataSize *= whileStatement->getMaxIterations();
73            nestedBlockCount++;
74            //EnsurePackHasSpace(totalCarryDataSize, whileCarryDataSize);
75            nestedCarryDataSize += whileCarryDataSize;
76            localCarryDataIndex += whileCarryDataSize;
77        }
78    }
79    totalCarryDataSize = localCarryDataIndex;
80    if ((ifDepth > 0) && (totalCarryDataSize > 1)) {
81        // Need extra space for the summary variable, always the last
82        // entry within an if block.
83        totalCarryDataSize += 1;
84    }
85    longAdvanceOffset = 0;
86    /*
87    if (totalCarryDataSize > CarryPackSize) {
88        // Need extra space for the summary variable, always the first
89        // entry within an if block.
90        totalCarryDataSize += BLOCK_SIZE;
91        longAdvanceOffset = BLOCK_SIZE;
92    }
93     */
94    carryOffset = longAdvanceOffset + longAdvanceTotalBlocks;
95    unitAdvanceOffset = carryOffset + localCarries;
96    shortAdvanceOffset = unitAdvanceOffset + unitAdvances;
97
98//     std::cerr << "blockCarryDataIndex = " << blockCarryDataIndex << " nestedBlockCount = " << nestedBlockCount << std::endl;
99//     std::cerr << "longAdvanceOffset = " << longAdvanceOffset << " carryOffset = " << carryOffset << std::endl;
100//     std::cerr << "unitAdvanceOffset = " << unitAdvanceOffset << " shortAdvanceOffset = " << shortAdvanceOffset << std::endl;
101//     std::cerr << "ifDepth = " << ifDepth << " whileDepth = " << whileDepth << std::endl;
102//     std::cerr << "totalCarryDataSize = " << totalCarryDataSize << std::endl;
103    return totalCarryDataSize;
104}
105
106}
Note: See TracBrowser for help on using the repository browser.