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

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

Abstract conditions for if-summary computation

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