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

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

Restructure to create separate carry data module

File size: 3.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#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    unsigned summaryCarryDataIndex()  const {
93        return blockCarryDataIndex + totalCarryDataSize - 1;
94    }
95   
96    unsigned getTotalCarryDataSize()  const {
97        return totalCarryDataSize;
98    }
99   
100private:
101    unsigned blockCarryDataIndex;
102    unsigned ifDepth;
103    unsigned whileDepth;
104    unsigned localCarries;
105    unsigned unitAdvances;
106    unsigned shortAdvances;
107    unsigned shortAdvanceTotal;
108    unsigned longAdvances;
109    unsigned longAdvanceTotalBlocks;
110    unsigned nestedBlockCount;
111    unsigned nestedCarryDataSize;
112    unsigned totalCarryDataSize;
113    unsigned carryOffset;
114    unsigned unitAdvanceOffset;
115    unsigned shortAdvanceOffset;
116    unsigned longAdvanceOffset;
117   
118};
119
120
121}
122
123
124#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.