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

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

Carry manager progress

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