source: icGREP/icgrep-devel/icgrep/pablo/carry_data.h @ 4667

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

Initial check of carry manager - not yet enabled

File size: 4.0 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#ifndef CARRY_DATA_H
8#define CARRY_DATA_H
9#include <include/simd-lib/bitblock.hpp>
10#include <stdexcept>
11/*
12 * Carry Data system.
13 *
14 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
15 * The data area may be at a fixed or variable base offset from the base of the
16 * main function carry data area.
17 * The data area for each block consists of contiguous space for the local carries and
18 * advances of the block plus the areas of any ifs/whiles nested within the block.
19
20*/
21unsigned const LongAdvanceBase = 64;
22
23static unsigned power2ceil (unsigned v) {
24    unsigned ceil = 1;
25    while (ceil < v) ceil *= 2;
26    return ceil;
27}
28
29namespace pablo {
30
31class PabloBlock;
32
33class PabloBlockCarryData {
34public:
35    PabloBlockCarryData(): blockCarryDataIndex(0),
36                           ifDepth(0), whileDepth (0),
37                           localCarries(0), unitAdvances(0),
38                           shortAdvances(0), shortAdvanceTotal(0),
39                           longAdvances(0), longAdvanceTotalBlocks(0),
40                           nestedBlockCount(0), nestedCarryDataSize(0),
41                           localCarryDataSize(0), totalCarryDataSize(0), 
42                           carryOffset(0), unitAdvanceOffset(0),
43                           shortAdvanceOffset(0), longAdvanceOffset(0)
44                           {}
45   
46   
47    void setBlockCarryDataIndex (unsigned idx) {blockCarryDataIndex = idx;}
48   
49    void setIfDepth (unsigned depth) {ifDepth = depth;}
50   
51    void setWhileDepth (unsigned depth) {whileDepth = depth;}
52   
53    unsigned enumerate(PabloBlock & p);
54   
55    unsigned getBlockCarryDataIndex()  const {
56        return blockCarryDataIndex;
57    }
58   
59    unsigned getIfDepth()  const {
60        return ifDepth;
61    }
62   
63    unsigned getWhileDepth()  const {
64        return whileDepth;
65    }
66   
67    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
68        return blockCarryDataIndex + longAdvanceOffset + advanceIndex;
69    }
70   
71    unsigned longAdvanceEntries(unsigned shift_amount) const {
72        return (shift_amount + BLOCK_SIZE - 1)/BLOCK_SIZE;
73    }
74   
75    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
76        return power2ceil(longAdvanceEntries(shift_amount));
77    }
78   
79    bool blockHasLongAdvances() const { return longAdvances > 0;}
80   
81    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
82        return blockCarryDataIndex + shortAdvanceOffset + advanceIndex;
83    }
84   
85    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
86        return blockCarryDataIndex + unitAdvanceOffset + advanceIndex;
87    }
88   
89    unsigned carryOpCarryDataOffset(unsigned idx)  const {
90        return blockCarryDataIndex + carryOffset + idx;
91    }
92   
93    bool blockHasCarries() const { return totalCarryDataSize > 0;}
94   
95    bool explicitSummaryRequired() const { return totalCarryDataSize > 1;}
96   
97    bool summaryNeededInParentBlock() const {return (ifDepth > 0) && blockHasCarries();}
98   
99    unsigned summaryCarryDataIndex()  const {
100        return blockCarryDataIndex + totalCarryDataSize - 1;
101    }
102   
103    unsigned getLocalCarryDataSize()  const {
104        return localCarryDataSize;
105    }
106   
107    unsigned getTotalCarryDataSize()  const {
108        return totalCarryDataSize;
109    }
110   
111private:
112    unsigned blockCarryDataIndex;
113    unsigned ifDepth;
114    unsigned whileDepth;
115    unsigned localCarries;
116    unsigned unitAdvances;
117    unsigned shortAdvances;
118    unsigned shortAdvanceTotal;
119    unsigned longAdvances;
120    unsigned longAdvanceTotalBlocks;
121    unsigned nestedBlockCount;
122    unsigned nestedCarryDataSize;
123    unsigned localCarryDataSize;
124    unsigned totalCarryDataSize;
125    unsigned carryOffset;
126    unsigned unitAdvanceOffset;
127    unsigned shortAdvanceOffset;
128    unsigned longAdvanceOffset;
129   
130};
131
132
133}
134
135
136#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.