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

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

Carry data/manager paramaterization: progress towards dynamic strategy selection.

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#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//#define PACKING
29
30#ifdef PACKING
31const unsigned PACK_SIZE = 64;
32const unsigned ITEMS_PER_PACK = PACK_SIZE;
33#else
34const unsigned PACK_SIZE = BLOCK_SIZE;
35const unsigned ITEMS_PER_PACK = 1;
36#endif
37const unsigned POSITIONS_PER_BLOCK = ITEMS_PER_PACK * (BLOCK_SIZE/PACK_SIZE);
38
39
40static unsigned power2ceil (unsigned v) {
41    unsigned ceil = 1;
42    while (ceil < v) ceil *= 2;
43    return ceil;
44}
45
46static unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
47    return ((toAlign - 1) | (alignment - 1)) + 1;
48}
49
50static unsigned fullOrPartialBlocks(unsigned bits, unsigned block_size) {
51    return alignCeiling(bits, block_size) / block_size;
52}
53
54namespace pablo {
55
56class PabloBlock;
57
58class PabloBlockCarryData {
59public:
60    PabloBlockCarryData(PabloBlock * b):
61                           theScope(b), framePosition(0),
62                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
63                           longAdvance({0, 0, 0}),
64                           shortAdvance({0, 0, 0}),
65                           advance1({0, 0}),
66                           addWithCarry({0, 0}),
67                           nested({0, 0, 0}),
68                           summary({0, 0}),
69                           scopeCarryDataSize(0)
70    {enumerateLocal();}
71       
72    friend class CarryManager;
73   
74    inline unsigned roomInFinalPack(unsigned allocatedBits) {
75        return ITEMS_PER_PACK - (allocatedBits % ITEMS_PER_PACK);
76    }
77   
78    void enumerateLocal();
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, BLOCK_SIZE);
107    }
108   
109    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
110        return power2ceil(longAdvanceEntries(shift_amount));
111    }
112   
113    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
114   
115    unsigned getLocalCarryPackIndex () { 
116        return shortAdvance.frameOffset / ITEMS_PER_PACK;
117    }
118
119    unsigned getLocalCarryPackCount () { 
120        return fullOrPartialBlocks(nested.frameOffset, ITEMS_PER_PACK) - shortAdvance.frameOffset / ITEMS_PER_PACK;
121    }
122   
123    unsigned getScopeCarryPackCount () { 
124        return fullOrPartialBlocks(scopeCarryDataSize, ITEMS_PER_PACK);
125    }
126   
127    bool blockHasCarries() const { return scopeCarryDataSize > 0;}
128   
129    bool explicitSummaryRequired() const { 
130        return (ifDepth > 0) && (scopeCarryDataSize > ITEMS_PER_PACK);
131    }
132   
133protected:
134   
135    PabloBlock * theScope;
136   
137    unsigned framePosition;
138   
139    unsigned ifDepth;
140    unsigned whileDepth;
141    unsigned maxNestingDepth;   
142   
143    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
144    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} shortAdvance;
145    struct {unsigned frameOffset; unsigned entries;} advance1;
146    struct {unsigned frameOffset; unsigned entries;} addWithCarry;
147    struct {unsigned frameOffset; unsigned entries; unsigned allocatedBits;} nested;
148    struct {unsigned frameOffset; unsigned allocatedBits;} summary;
149
150    unsigned scopeCarryDataSize;
151   
152    llvm::Value * ifEntryPack;
153   
154};
155
156
157}
158
159
160#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.