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

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

Carry Manager progress and bug fix

File size: 4.4 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
23#ifdef PACKING
24const unsigned PACK_SIZE = 64;
25#else
26const unsigned PACK_SIZE = BLOCK_SIZE;
27#endif
28
29
30static unsigned power2ceil (unsigned v) {
31    unsigned ceil = 1;
32    while (ceil < v) ceil *= 2;
33    return ceil;
34}
35
36static unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
37    return ((toAlign - 1) | (alignment - 1)) + 1;
38}
39
40static unsigned fullOrPartialBlocks(unsigned bits, unsigned block_size) {
41    return alignCeiling(bits, block_size) / block_size;
42}
43
44namespace pablo {
45
46class PabloBlock;
47
48class PabloBlockCarryData {
49public:
50    PabloBlockCarryData(): framePosition(0), 
51                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
52                           longAdvance({0, 0, 0}),
53                           shortAdvance({0, 0, 0}),
54                           advance1({0, 0}),
55                           addWithCarry({0, 0}),
56                           nested({0, 0, 0}),
57                           summary({0, 0}),
58                           scopeCarryDataBits(0)
59                           {}
60       
61    unsigned enumerate(PabloBlock & p);
62   
63    unsigned getBlockCarryDataIndex()  const {
64        return framePosition/BLOCK_SIZE;
65    }
66   
67    unsigned getIfDepth()  const {
68        return ifDepth;
69    }
70   
71    unsigned getWhileDepth()  const {
72        return whileDepth;
73    }
74       
75    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
76        return fullOrPartialBlocks(longAdvance.frameOffsetinBits, BLOCK_SIZE) + advanceIndex;
77    }
78   
79    unsigned longAdvanceEntries(unsigned shift_amount) const {
80        return fullOrPartialBlocks(shift_amount, BLOCK_SIZE);
81    }
82   
83    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
84        return power2ceil(longAdvanceEntries(shift_amount));
85    }
86   
87    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
88   
89    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
90        return fullOrPartialBlocks(shortAdvance.frameOffsetinBits, PACK_SIZE) + advanceIndex;
91    }
92   
93    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
94        return fullOrPartialBlocks(advance1.frameOffsetinBits, PACK_SIZE) + advanceIndex;
95    }
96   
97    unsigned carryOpCarryDataOffset(unsigned idx)  const {
98        return fullOrPartialBlocks(addWithCarry.frameOffsetinBits, PACK_SIZE) + idx;
99    }
100   
101    unsigned summaryCarryDataIndex()  const {
102        return fullOrPartialBlocks(summary.frameOffsetinBits, PACK_SIZE);
103    }
104   
105    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
106
107    unsigned getLocalCarryDataSize () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
108
109    unsigned getScopeCarryDataSize () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
110   
111    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
112   
113    bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > PACK_SIZE);}
114   
115private:
116   
117    unsigned framePosition;
118   
119    unsigned ifDepth;
120    unsigned whileDepth;
121    unsigned maxNestingDepth;   
122   
123    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
124    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} shortAdvance;
125    struct {unsigned frameOffsetinBits; unsigned entries;} advance1;
126    struct {unsigned frameOffsetinBits; unsigned entries;} addWithCarry;
127    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} nested;
128    struct {unsigned frameOffsetinBits; unsigned allocatedBits;} summary;
129
130    unsigned scopeCarryDataBits;
131   
132};
133
134
135}
136
137
138#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.