Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/constraint_compiler
[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 enum ElementEncodingType {
8         ELEM_UNASSIGNED, ONEHOT, UNARY, BINARYINDEX, ONEHOTBINARY, BINARYVAL
9 };
10
11 typedef enum ElementEncodingType ElementEncodingType;
12
13 class ElementEncoding {
14 public:
15         ElementEncoding(Element *element);
16         ElementEncodingType getElementEncodingType() {return type;}
17         ~ElementEncoding();
18         void setElementEncodingType(ElementEncodingType type);
19         void deleteElementEncoding();
20         void allocEncodingArrayElement(uint size);
21         void allocInUseArrayElement(uint size);
22         uint numEncodingVars() {return numVars;}
23         bool isinUseElement(uint offset) { return (inUseArray[(offset >> 6)] >> (offset & 63)) & 0x1;}
24         void setInUseElement(uint offset) {inUseArray[(offset >> 6)] |= 1 << (offset & 63);}
25         void encodingArrayInitialization();
26         uint getSizeEncodingArray(uint setSize) {
27                 switch (type) {
28                 case BINARYINDEX:
29                         return NEXTPOW2(setSize);
30                 case ONEHOT:
31                 case UNARY:
32                         return setSize;
33                 default:
34                         ASSERT(0);
35                 }
36                 return -1;
37         }
38
39
40         ElementEncodingType type;
41         Element *element;
42         Edge *variables;/* List Variables Used To Encode Element */
43         union {
44                 struct {
45                         uint64_t *encodingArray;        /* List the Variables in the appropriate order */
46                         uint64_t *inUseArray;   /* Bitmap to track variables in use */
47                         uint encArraySize;
48                 };
49                 struct {
50                         uint64_t offset;/* Value = offset + encoded number (interpretted according to isBinaryValSigned) */
51                         uint64_t low;/* Lowest value to encode */
52                         uint64_t high;/* High value to encode.   If low > high, we assume wrap around to include 0. */
53                         uint numBits;
54                         bool isBinaryValSigned;
55                 };
56         };
57         uint numVars;   /* Number of variables */
58         CMEMALLOC;
59 };
60
61
62
63 #endif