Extend tuning framework
[satune.git] / src / Encoders / elementencoding.h
1 #ifndef ELEMENTENCODING_H
2 #define ELEMENTENCODING_H
3 #include "classlist.h"
4 #include "naiveencoder.h"
5 #include "constraint.h"
6
7 class ElementEncoding {
8 public:
9         ElementEncoding(Element *element);
10         ElementEncodingType getElementEncodingType() {return type;}
11         ~ElementEncoding();
12         void setElementEncodingType(ElementEncodingType type);
13         void deleteElementEncoding();
14         void allocEncodingArrayElement(uint size);
15         void allocInUseArrayElement(uint size);
16         uint numEncodingVars() {return numVars;}
17         bool isinUseElement(uint offset) { return (inUseArray[(offset >> 6)] >> (offset & 63)) & 0x1;}
18         void setInUseElement(uint offset) {inUseArray[(offset >> 6)] |= 1 << (offset & 63);}
19         void encodingArrayInitialization();
20         uint getSizeEncodingArray(uint setSize) {
21                 switch (type) {
22                 case BINARYINDEX:
23                         return NEXTPOW2(setSize);
24                 case ONEHOT:
25                 case UNARY:
26                         return setSize;
27                 default:
28                         ASSERT(0);
29                 }
30                 return -1;
31         }
32
33
34         ElementEncodingType type;
35         Element *element;
36         Edge *variables;/* List Variables Used To Encode Element */
37         union {
38                 struct {
39                         uint64_t *encodingArray;        /* List the Variables in the appropriate order */
40                         uint64_t *inUseArray;   /* Bitmap to track variables in use */
41                         uint encArraySize;
42                 };
43                 struct {
44                         uint64_t offset;/* Value = offset + encoded number (interpretted according to isBinaryValSigned) */
45                         uint64_t low;/* Lowest value to encode */
46                         uint64_t high;/* High value to encode.   If low > high, we assume wrap around to include 0. */
47                         uint numBits;
48                         bool isBinaryValSigned;
49                 };
50         };
51         uint numVars;   /* Number of variables */
52         CMEMALLOC;
53 };
54
55
56
57 #endif