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

Last change on this file since 4925 was 4925, checked in by nmedfort, 4 years ago

Slight optimization for Simplifier; major change to CarryManager? to build summary variables whenever a carry operation is performed.

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#include <include/simd-lib/bitblock.hpp>
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 PACK_SIZE, unsigned ITEMS_PER_PACK):
51       mPackSize(PACK_SIZE),
52       mItemsPerPack(ITEMS_PER_PACK),
53       mPositionsPerBlock(mItemsPerPack * (BLOCK_SIZE/mPackSize)),
54       theScope(b),
55       framePosition(0),
56       ifDepth(0),
57       whileDepth (0),
58       maxNestingDepth(0),
59       longAdvance({0, 0, 0}),
60       shortAdvance({0, 0, 0}),
61       unitAdvance({0, 0}),
62       addWithCarry({0, 0}),
63       nested({0, 0, 0}),
64       summary({0, 0}),
65       scopeCarryDataSize(0)
66    {
67        enumerateLocal();
68    }
69
70    friend class CarryManager;
71   
72    inline unsigned roomInFinalPack(unsigned allocatedBits) const {
73        return mItemsPerPack - (allocatedBits % mItemsPerPack);
74    }
75   
76    void enumerateLocal();
77
78    void dumpCarryData(llvm::raw_ostream & strm);
79   
80    unsigned getFrameIndex()  const {
81        return framePosition;
82    }
83   
84    void setFramePosition(unsigned p) {
85        framePosition = p;
86    }
87   
88    unsigned getIfDepth()  const {
89        return ifDepth;
90    }
91   
92    void setIfDepth(unsigned d) {
93        ifDepth = d;
94    }
95   
96    unsigned getWhileDepth()  const {
97        return whileDepth;
98    }
99       
100    void setWhileDepth(unsigned d) {
101        whileDepth = d;
102    }
103   
104    unsigned longAdvanceEntries(unsigned shift_amount) const {
105        return fullOrPartialBlocks(shift_amount, BLOCK_SIZE);
106    }
107   
108    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
109        return power2ceil(longAdvanceEntries(shift_amount));
110    }
111   
112    bool hasLongAdvances() const { return longAdvance.entries > 0;}
113   
114    unsigned getLocalCarryPackIndex () { 
115        return shortAdvance.frameOffset / mItemsPerPack;
116    }
117
118    unsigned getLocalCarryPackCount () {
119        return fullOrPartialBlocks(nested.frameOffset, mItemsPerPack) - shortAdvance.frameOffset / mItemsPerPack;
120    }
121   
122    unsigned getScopeCarryPackCount () { 
123        return fullOrPartialBlocks(scopeCarryDataSize, mItemsPerPack);
124    }
125   
126    bool hasCarries() const { return scopeCarryDataSize > 0;}
127   
128    bool explicitSummaryRequired() const { 
129        return (ifDepth > 0) && (scopeCarryDataSize > mItemsPerPack);
130    }
131   
132protected:
133
134    unsigned mPackSize, mItemsPerPack, mPositionsPerBlock;
135   
136    PabloBlock * theScope;
137   
138    unsigned framePosition;
139   
140    unsigned ifDepth;
141    unsigned whileDepth;
142    unsigned maxNestingDepth;   
143   
144    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
145    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} shortAdvance;
146    struct {unsigned frameOffset; unsigned entries;} unitAdvance;
147    struct {unsigned frameOffset; unsigned entries;} addWithCarry;
148    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} nested;
149    struct {unsigned frameOffset; unsigned allocatedBits;} summary;
150
151    unsigned scopeCarryDataSize;
152   
153};
154
155
156}
157
158
159#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.