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

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

Clean-ups

File size: 3.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>
11/*
12 * Carry Data system.
13 *
14 * Each PabloBlock (Main, If, While) has a contiguous data area for carry information.
15 * The data area may be at a fixed or variable base offset from the base of the
16 * main function carry data area.
17 * The data area for each block consists of contiguous space for the local carries and
18 * advances of the block plus the areas of any ifs/whiles nested within the block.
19
20*/
21unsigned const LongAdvanceBase = 64;
22
23static unsigned power2ceil (unsigned v) {
24    unsigned ceil = 1;
25    while (ceil < v) ceil *= 2;
26    return ceil;
27}
28
29namespace pablo {
30
31class PabloBlock;
32
33class PabloBlockCarryData {
34public:
[4670]35    PabloBlockCarryData(): framePosition(0), 
36                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
37                           longAdvance({0, 0, 0}),
38                           shortAdvance({0, 0, 0}),
39                           advance1({0, 0}),
40                           addWithCarry({0, 0}),
41                           nested({0, 0, 0}),
42                           summary({0, 0}),
[4672]43                           scopeCarryDataBits(0)
[4566]44                           {}
[4670]45       
[4566]46    unsigned enumerate(PabloBlock & p);
47   
48    unsigned getBlockCarryDataIndex()  const {
[4670]49        return framePosition/BLOCK_SIZE;
[4566]50    }
51   
52    unsigned getIfDepth()  const {
53        return ifDepth;
54    }
55   
56    unsigned getWhileDepth()  const {
57        return whileDepth;
58    }
[4670]59       
[4566]60    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4670]61        return longAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
[4566]62    }
63   
64    unsigned longAdvanceEntries(unsigned shift_amount) const {
65        return (shift_amount + BLOCK_SIZE - 1)/BLOCK_SIZE;
66    }
67   
68    unsigned longAdvanceBufferSize(unsigned shift_amount)  const {
69        return power2ceil(longAdvanceEntries(shift_amount));
70    }
71   
[4670]72    bool blockHasLongAdvances() const { return longAdvance.entries > 0;}
[4644]73   
[4566]74    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4670]75        return shortAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
[4566]76    }
77   
78    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
[4670]79        return advance1.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
[4566]80    }
81   
82    unsigned carryOpCarryDataOffset(unsigned idx)  const {
[4670]83        return addWithCarry.frameOffsetinBits / BLOCK_SIZE + idx;
[4566]84    }
85   
[4670]86    unsigned summaryCarryDataIndex()  const {
87        return summary.frameOffsetinBits / BLOCK_SIZE;
88    }
[4568]89   
[4670]90    unsigned getLocalCarryDataSize () { return nested.frameOffsetinBits / BLOCK_SIZE; }
91
[4672]92    unsigned getScopeCarryDataSize () { return scopeCarryDataBits / BLOCK_SIZE; }
[4670]93   
[4672]94    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
[4568]95   
[4672]96    bool explicitSummaryRequired() const { return scopeCarryDataBits > BLOCK_SIZE;}
[4670]97   
[4568]98    bool summaryNeededInParentBlock() const {return (ifDepth > 0) && blockHasCarries();}
99   
[4670]100private:
[4566]101   
[4670]102    unsigned framePosition;
[4595]103   
[4566]104    unsigned ifDepth;
105    unsigned whileDepth;
[4670]106    unsigned maxNestingDepth;   
[4566]107   
[4670]108    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBitBlocks;} longAdvance;
109    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} shortAdvance;
110    struct {unsigned frameOffsetinBits; unsigned entries;} advance1;
111    struct {unsigned frameOffsetinBits; unsigned entries;} addWithCarry;
112    struct {unsigned frameOffsetinBits; unsigned entries; unsigned allocatedBits;} nested;
113    struct {unsigned frameOffsetinBits; unsigned allocatedBits;} summary;
114
[4672]115    unsigned scopeCarryDataBits;
[4670]116   
[4566]117};
118
119
120}
121
122
123#endif // CARRY_DATA_H
Note: See TracBrowser for help on using the repository browser.