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

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

Carry Manager restructuring and bug fixes

File size: 4.8 KB
RevLine 
[4566]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>
[4687]11#include <iostream>
12#include <ostream>
13#include <llvm/Support/raw_os_ostream.h>
[4566]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
[4682]26#ifdef PACKING
27const unsigned PACK_SIZE = 64;
28#else
29const unsigned PACK_SIZE = BLOCK_SIZE;
30#endif
31
32
[4566]33static unsigned power2ceil (unsigned v) {
34    unsigned ceil = 1;
35    while (ceil < v) ceil *= 2;
36    return ceil;
37}
38
[4682]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
[4566]47namespace pablo {
48
49class PabloBlock;
50
51class PabloBlockCarryData {
52public:
[4687]53    PabloBlockCarryData(PabloBlock * b):
54                           theScope(b), framePosition(0),
[4670]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}),
[4672]62                           scopeCarryDataBits(0)
[4687]63    {enumerateLocal();}
[4670]64       
[4687]65    friend class CarryManager;
[4566]66   
[4687]67    void enumerateLocal();
68    void dumpCarryData(llvm::raw_ostream & strm);
69   
[4566]70    unsigned getBlockCarryDataIndex()  const {
[4670]71        return framePosition/BLOCK_SIZE;
[4566]72    }
73   
[4687]74    void setFramePosition(unsigned p) {
75        framePosition = p;
76    }
77   
[4566]78    unsigned getIfDepth()  const {
79        return ifDepth;
80    }
81   
[4687]82    void setIfDepth(unsigned d) {
83        ifDepth = d;
84    }
85   
[4566]86    unsigned getWhileDepth()  const {
87        return whileDepth;
88    }
[4670]89       
[4687]90    void setWhileDepth(unsigned d) {
91        whileDepth = d;
92    }
93   
[4566]94    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4682]95        return fullOrPartialBlocks(longAdvance.frameOffsetinBits, BLOCK_SIZE) + advanceIndex;
[4566]96    }
97   
98    unsigned longAdvanceEntries(unsigned shift_amount) const {
[4682]99        return fullOrPartialBlocks(shift_amount, BLOCK_SIZE);
[4566]100    }
101   
102    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
103        return power2ceil(longAdvanceEntries(shift_amount));
104    }
105   
[4670]106    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
[4644]107   
[4566]108    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4682]109        return fullOrPartialBlocks(shortAdvance.frameOffsetinBits, PACK_SIZE) + advanceIndex;
[4566]110    }
111   
112    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4682]113        return fullOrPartialBlocks(advance1.frameOffsetinBits, PACK_SIZE) + advanceIndex;
[4566]114    }
115   
116    unsigned carryOpCarryDataOffset(unsigned idx)  const {
[4682]117        return fullOrPartialBlocks(addWithCarry.frameOffsetinBits, PACK_SIZE) + idx;
[4566]118    }
119   
[4670]120    unsigned summaryCarryDataIndex()  const {
[4682]121        return fullOrPartialBlocks(summary.frameOffsetinBits, PACK_SIZE);
[4670]122    }
[4568]123   
[4682]124    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
[4670]125
[4682]126    unsigned getLocalCarryDataSize () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
127
128    unsigned getScopeCarryDataSize () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
[4670]129   
[4672]130    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
[4568]131   
[4682]132    bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > PACK_SIZE);}
[4670]133   
[4687]134protected:
[4566]135   
[4687]136    PabloBlock * theScope;
137   
[4670]138    unsigned framePosition;
[4595]139   
[4566]140    unsigned ifDepth;
141    unsigned whileDepth;
[4670]142    unsigned maxNestingDepth;   
[4566]143   
[4670]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
[4672]151    unsigned scopeCarryDataBits;
[4670]152   
[4566]153};
154
155
156}
157
158
159#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.