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

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

Bit pack carry manager progress

File size: 4.3 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//#define PACKING
27
28#ifdef PACKING
29const unsigned PACK_SIZE = 64;
30#else
31const unsigned PACK_SIZE = BLOCK_SIZE;
32#endif
33
34
35static unsigned power2ceil (unsigned v) {
36    unsigned ceil = 1;
37    while (ceil < v) ceil *= 2;
38    return ceil;
39}
40
41static unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
42    return ((toAlign - 1) | (alignment - 1)) + 1;
43}
44
45static unsigned fullOrPartialBlocks(unsigned bits, unsigned block_size) {
46    return alignCeiling(bits, block_size) / block_size;
47}
48
49static void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
50    unsigned bitsInCurrentPack = packedTotalBits % PACK_SIZE;
51    if ((bitsInCurrentPack > 0) && (bitsInCurrentPack + addedBits > PACK_SIZE)) {
52        packedTotalBits = alignCeiling(packedTotalBits, PACK_SIZE);
53    }
54}
55
56
57namespace pablo {
58
59class PabloBlock;
60
61class PabloBlockCarryData {
62public:
63    PabloBlockCarryData(PabloBlock * b):
64                           theScope(b), framePosition(0),
65                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
66                           longAdvance({0, 0, 0}),
67                           shortAdvance({0, 0, 0}),
68                           advance1({0, 0}),
69                           addWithCarry({0, 0}),
70                           nested({0, 0, 0}),
71                           summary({0, 0}),
72                           scopeCarryDataBits(0)
73    {enumerateLocal();}
74       
75    friend class CarryManager;
76   
77    void enumerateLocal();
78    void dumpCarryData(llvm::raw_ostream & strm);
79   
80    unsigned getFrameIndex()  const {
81        return framePosition/BLOCK_SIZE;
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 blockHasLongAdvances() const { return longAdvance.entries > 0;}
113   
114    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
115
116    unsigned getLocalCarryPackCount () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
117
118    unsigned getScopeCarryPackCount () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
119   
120    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
121   
122    bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > PACK_SIZE);}
123   
124protected:
125   
126    PabloBlock * theScope;
127   
128    unsigned framePosition;
129   
130    unsigned ifDepth;
131    unsigned whileDepth;
132    unsigned maxNestingDepth;   
133   
134    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
135    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} shortAdvance;
136    struct {unsigned frameOffsetinBits; unsigned entries;} advance1;
137    struct {unsigned frameOffsetinBits; unsigned entries;} addWithCarry;
138    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} nested;
139    struct {unsigned frameOffsetinBits; unsigned allocatedBits;} summary;
140
141    unsigned scopeCarryDataBits;
142   
143};
144
145
146}
147
148
149#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.