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

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

Removing compile-time BLOCK_SIZE from pablo compiler/carry manager

File size: 4.2 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
10#include <stdexcept>
11#include <iostream>
12#include <ostream>
13#include <llvm/Support/raw_os_ostream.h>
14#include <llvm/IR/Module.h>
15
16/*
17 * Carry Data system.
18 *
19 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
20 * The data area may be at a fixed or variable base offset from the base of the
21 * main function carry data area.
22 * The data area for each block consists of contiguous space for the local carries and
23 * advances of the block plus the areas of any ifs/whiles nested within the block.
24
25*/
26unsigned const LongAdvanceBase = 64;
27
28
29static unsigned power2ceil (unsigned v) {
30    unsigned ceil = 1;
31    while (ceil < v) ceil *= 2;
32    return ceil;
33}
34
35static unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
36    return ((toAlign - 1) | (alignment - 1)) + 1;
37}
38
39static unsigned fullOrPartialBlocks(unsigned bits, unsigned block_size) {
40    return alignCeiling(bits, block_size) / block_size;
41}
42
43namespace pablo {
44
45class PabloBlock;
46
47class CarryData {
48public:
49
50    CarryData(PabloBlock * b, unsigned packSize, unsigned itemsPerPack, unsigned blockSize):
51       mPackSize(packSize),
52       mItemsPerPack(itemsPerPack),
53       mBlockSize(blockSize),
54       mPositionsPerBlock(mItemsPerPack * (blockSize/mPackSize)),
55       theScope(b),
56       framePosition(0),
57       ifDepth(0),
58       whileDepth (0),
59       maxNestingDepth(0),
60       longAdvance({0, 0, 0}),
61       shortAdvance({0, 0, 0}),
62       unitAdvance({0, 0}),
63       addWithCarry({0, 0}),
64       nested({0, 0, 0}),
65       summary({0, 0}),
66       scopeCarryDataSize(0)
67    {
68        enumerateLocal();
69    }
70
71    friend class CarryManager;
72   
73    inline unsigned roomInFinalPack(unsigned allocatedBits) const {
74        return mItemsPerPack - (allocatedBits % mItemsPerPack);
75    }
76   
77    void enumerateLocal();
78
79    void dumpCarryData(llvm::raw_ostream & strm);
80   
81    unsigned getFrameIndex()  const {
82        return framePosition;
83    }
84   
85    void setFramePosition(unsigned p) {
86        framePosition = p;
87    }
88   
89    unsigned getIfDepth()  const {
90        return ifDepth;
91    }
92   
93    void setIfDepth(unsigned d) {
94        ifDepth = d;
95    }
96   
97    unsigned getWhileDepth()  const {
98        return whileDepth;
99    }
100       
101    void setWhileDepth(unsigned d) {
102        whileDepth = d;
103    }
104   
105    unsigned longAdvanceEntries(unsigned shift_amount) const {
106        return fullOrPartialBlocks(shift_amount, mBlockSize);
107    }
108   
109    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
110        return power2ceil(longAdvanceEntries(shift_amount));
111    }
112   
113    bool hasLongAdvances() const { return longAdvance.entries > 0;}
114   
115    unsigned getLocalCarryPackIndex () { 
116        return shortAdvance.frameOffset / mItemsPerPack;
117    }
118
119    unsigned getLocalCarryPackCount () {
120        return fullOrPartialBlocks(nested.frameOffset, mItemsPerPack) - shortAdvance.frameOffset / mItemsPerPack;
121    }
122   
123    unsigned getScopeCarryPackCount () { 
124        return fullOrPartialBlocks(scopeCarryDataSize, mItemsPerPack);
125    }
126   
127    bool hasCarries() const { return scopeCarryDataSize > 0;}
128   
129    bool explicitSummaryRequired() const { 
130        return (ifDepth > 0) && (scopeCarryDataSize > mItemsPerPack);
131    }
132   
133protected:
134
135    unsigned mPackSize, mItemsPerPack, mBlockSize, mPositionsPerBlock;
136   
137    PabloBlock * theScope;
138   
139    unsigned framePosition;
140   
141    unsigned ifDepth;
142    unsigned whileDepth;
143    unsigned maxNestingDepth;   
144   
145    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
146    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} shortAdvance;
147    struct {unsigned frameOffset; unsigned entries;} unitAdvance;
148    struct {unsigned frameOffset; unsigned entries;} addWithCarry;
149    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} nested;
150    struct {unsigned frameOffset; unsigned allocatedBits;} summary;
151
152    unsigned scopeCarryDataSize;
153   
154};
155
156
157}
158
159
160#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.