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

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

Dynamic selection of carry strategy options

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