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

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

Carry Manager restructuring and bug fixes

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
16   
17unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
18    return ((toAlign - 1) | (alignment - 1)) + 1;
19}
20
21void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
22    unsigned bitsInCurrentPack = packedTotalBits % PACK_SIZE;
23    if ((bitsInCurrentPack > 0) && (bitsInCurrentPack + addedBits > PACK_SIZE)) {
24      packedTotalBits = alignCeiling(packedTotalBits, PACK_SIZE);
25    }
26}
27
28void PabloBlockCarryData::enumerateLocal() {
29    for (Statement * stmt : *theScope) {
30        if (Advance * adv = dyn_cast<Advance>(stmt)) {
31            unsigned shift_amount = adv->getAdvanceAmount();
32            if (shift_amount == 1) {
33                adv->setLocalAdvanceIndex(advance1.entries);
34                advance1.entries++;               
35            }
36            else if (shift_amount < LongAdvanceBase) {
37#ifdef PACKING
38                EnsurePackHasSpace(shortAdvance.allocatedBits, shift_amount);
39                adv->setLocalAdvanceIndex(shortAdvance.allocatedBits);
40#else
41                adv->setLocalAdvanceIndex(shortAdvance.entries);
42#endif
43                shortAdvance.entries++;
44                shortAdvance.allocatedBits += shift_amount;
45            }
46            else {
47                adv->setLocalAdvanceIndex(longAdvance.allocatedBitBlocks);
48                longAdvance.entries++;
49                longAdvance.allocatedBitBlocks += longAdvanceBufferSize(shift_amount);
50            }
51        }
52        else if (MatchStar * m = dyn_cast<MatchStar>(stmt)) {
53            m->setLocalCarryIndex(addWithCarry.entries);
54            ++addWithCarry.entries;
55        }
56        else if (ScanThru * s = dyn_cast<ScanThru>(stmt)) {
57            s->setLocalCarryIndex(addWithCarry.entries);
58            ++addWithCarry.entries;
59        }
60    }
61    longAdvance.frameOffsetinBits = 0;
62#ifdef PACKING
63    shortAdvance.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
64    addWithCarry.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.allocatedBits;
65    EnsurePackHasSpace(addWithCarry.frameOffsetinBits, addWithCarry.entries);
66    advance1.frameOffsetinBits = addWithCarry.frameOffsetinBits + addWithCarry.entries;
67    EnsurePackHasSpace(advance1.frameOffsetinBits, advance1.entries);
68    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries;
69#else
70    shortAdvance.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
71    addWithCarry.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.entries * BLOCK_SIZE;
72    advance1.frameOffsetinBits = addWithCarry.frameOffsetinBits + addWithCarry.entries * BLOCK_SIZE;
73    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries * BLOCK_SIZE;
74#endif
75}
76       
77void PabloBlockCarryData::dumpCarryData(llvm::raw_ostream & strm) {
78    unsigned totalDepth = ifDepth + whileDepth;
79    for (int i = 0; i < totalDepth; i++) strm << "  ";
80    strm << "scope index = " << theScope->getScopeIndex();
81    strm << " framePosition: " << framePosition << ", ifDepth: " << ifDepth << ", whileDepth:" << whileDepth << ", maxNestingDepth: " << maxNestingDepth << "\n";
82    for (int i = 0; i < totalDepth; i++) strm << "  ";
83    strm << "longAdvance: offset = " << longAdvance.frameOffsetinBits << ", entries = " << longAdvance.entries << "\n";
84    for (int i = 0; i < totalDepth; i++) strm << "  ";
85    strm << "shortAdvance: offset = " << shortAdvance.frameOffsetinBits << ", entries = " << shortAdvance.entries << "\n";
86    for (int i = 0; i < totalDepth; i++) strm << "  ";
87    strm << "advance1: offset = " << advance1.frameOffsetinBits << ", entries = " << advance1.entries << "\n";
88    for (int i = 0; i < totalDepth; i++) strm << "  ";
89    strm << "addWithCarry: offset = " << addWithCarry.frameOffsetinBits << ", entries = " << addWithCarry.entries << "\n";
90    for (int i = 0; i < totalDepth; i++) strm << "  ";
91    strm << "nested: offset = " << nested.frameOffsetinBits << ", allocatedBits = " << nested.allocatedBits << "\n";
92    for (int i = 0; i < totalDepth; i++) strm << "  ";
93    strm << "summary: offset = " << summary.frameOffsetinBits << ", allocatedBits = " << summary.allocatedBits << "\n";
94    for (int i = 0; i < totalDepth; i++) strm << "  ";
95    strm << "scopeCarryDataBits = " << scopeCarryDataBits  << "\n";
96    strm.flush();
97   
98}
99
100}
Note: See TracBrowser for help on using the repository browser.