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

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

Clean-ups

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 <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(): framePosition(0), 
36                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
37                           longAdvance({0, 0, 0}),
38                           shortAdvance({0, 0, 0}),
39                           advance1({0, 0}),
40                           addWithCarry({0, 0}),
41                           nested({0, 0, 0}),
42                           summary({0, 0}),
43                           scopeCarryDataBits(0)
44                           {}
45       
46    unsigned enumerate(PabloBlock & p);
47   
48    unsigned getBlockCarryDataIndex()  const {
49        return framePosition/BLOCK_SIZE;
50    }
51   
52    unsigned getIfDepth()  const {
53        return ifDepth;
54    }
55   
56    unsigned getWhileDepth()  const {
57        return whileDepth;
58    }
59       
60    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
61        return longAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
62    }
63   
64    unsigned longAdvanceEntries(unsigned shift_amount) const {
65        return (shift_amount + BLOCK_SIZE - 1)/BLOCK_SIZE;
66    }
67   
68    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
69        return power2ceil(longAdvanceEntries(shift_amount));
70    }
71   
72    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
73   
74    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
75        return shortAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
76    }
77   
78    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
79        return advance1.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
80    }
81   
82    unsigned carryOpCarryDataOffset(unsigned idx)  const {
83        return addWithCarry.frameOffsetinBits / BLOCK_SIZE + idx;
84    }
85   
86    unsigned summaryCarryDataIndex()  const {
87        return summary.frameOffsetinBits / BLOCK_SIZE;
88    }
89   
90    unsigned getLocalCarryDataSize () { return nested.frameOffsetinBits / BLOCK_SIZE; }
91
92    unsigned getScopeCarryDataSize () { return scopeCarryDataBits / BLOCK_SIZE; }
93   
94    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
95   
96    bool explicitSummaryRequired() const { return scopeCarryDataBits > BLOCK_SIZE;}
97   
98    bool summaryNeededInParentBlock() const {return (ifDepth > 0) && blockHasCarries();}
99   
100private:
101   
102    unsigned framePosition;
103   
104    unsigned ifDepth;
105    unsigned whileDepth;
106    unsigned maxNestingDepth;   
107   
108    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
109    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} shortAdvance;
110    struct {unsigned frameOffsetinBits; unsigned entries;} advance1;
111    struct {unsigned frameOffsetinBits; unsigned entries;} addWithCarry;
112    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} nested;
113    struct {unsigned frameOffsetinBits; unsigned allocatedBits;} summary;
114
115    unsigned scopeCarryDataBits;
116   
117};
118
119
120}
121
122
123#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.