forked from JeffersonLab/qphix-codegen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
address_types.h
254 lines (227 loc) · 6.26 KB
/
address_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifndef _ADDRESS_TYPES_H_
#define _ADDRESS_TYPES_H_
using namespace std;
enum AddressType { GAUGE, SPINOR, CLOVER_DIAG, CLOVER_OFFDIAG, ADDRESS_OF_SCALAR, GENERIC_ADDRESS};
class Address
{
public:
Address(int isHalfType_) : halfType(isHalfType_) { }
virtual string serialize(void) const=0;
virtual AddressType getType(void) const = 0;
int isHalfType(void)
{
return halfType;
}
int isHalfType(void) const
{
return halfType;
}
private:
int halfType;
};
class GenericAddress : public Address
{
public:
GenericAddress(string base_, int isHalfType) : Address(isHalfType), base(base_) {}
AddressType getType(void) const
{
return GENERIC_ADDRESS;
}
string serialize() const
{
ostringstream outbuf;
outbuf << "(" << base << ")";
return outbuf.str();
}
private:
const string base;
};
class AddressOfScalar : public Address
{
public:
AddressOfScalar(string scalar_name_, int isHalfType) : Address(isHalfType), scalar_name(scalar_name_) {}
AddressType getType(void) const
{
return ADDRESS_OF_SCALAR;
}
string serialize() const
{
ostringstream outbuf;
outbuf << "(&" << scalar_name << ")";
return outbuf.str();
}
private:
const string scalar_name;
};
class GaugeAddress : public Address
{
public:
GaugeAddress(const string& base_, int dir_, int c1_, int c2_, int reim_, int isHalfType) : Address(isHalfType), base(base_), dir(dir_), c1(c1_), c2(c2_), reim(reim_) {};
string serialize(void) const
{
ostringstream outbuf;
outbuf<< "(*" << base << ")[" << dir <<"]["<< c1 << "][" << c2 << "][" << reim << "]";
return outbuf.str();
}
AddressType getType(void) const
{
return GAUGE;
}
protected:
const string base;
const int dir;
const int c1;
const int c2;
const int reim;
};
class ClovDiagAddress : public Address
{
public:
ClovDiagAddress(const string& base_, int block_, int component_, int isHalfType) : Address(isHalfType), base(base_), block(block_), component(component_) {};
string serialize(void) const
{
ostringstream outbuf;
outbuf<< "(*" << base << ").diag"<<block+1<<"[ " << component <<" ] ";
return outbuf.str();
}
AddressType getType(void) const
{
return CLOVER_DIAG;
}
protected:
const string base;
const int block;
const int component;
};
class ClovOffDiagAddress : public Address
{
public:
ClovOffDiagAddress(const string& base_, int block_, int component_, int reim_, int isHalfType) : Address(isHalfType), base(base_), block(block_), component(component_), reim(reim_) {};
string serialize(void) const
{
ostringstream outbuf;
outbuf<< "(*" << base << ").off_diag"<<block+1<<"[ " << component <<" ][ " << reim << "]";
return outbuf.str();
}
AddressType getType(void) const
{
return CLOVER_OFFDIAG;
}
protected:
const string base;
const int block;
const int component;
const int reim;
};
class SpinorAddress : public Address
{
public:
SpinorAddress(const string& base_, int spin_, int color_, int reim_, int isHalfType) : Address(isHalfType), base(base_), spin(spin_), color(color_), reim(reim_) {};
string serialize(void) const
{
ostringstream outbuf;
outbuf<< "(*" << base << ")["<< color<< "][" << spin << "][" << reim << "]";
return outbuf.str();
}
AddressType getType(void) const
{
return SPINOR;
}
//int getOffset(void) const {return (((spin*3+color)*2+reim)*SOALEN);}
protected:
const string base;
const int spin;
const int color;
const int reim;
};
class AddressOffset : public Address
{
public:
AddressOffset(const Address* a_, string offset_var_) : Address(a_->isHalfType()), a(a_), offset_var(offset_var_) {}
AddressType getType(void) const
{
return a->getType();
}
string serialize() const
{
ostringstream outbuf;
outbuf << "(" << a->serialize() << " + " << offset_var <<")";
return outbuf.str();
}
private:
const Address* a;
const string offset_var;
};
class AddressImm : public Address
{
public:
AddressImm(const Address* base_, const int imm_) : Address(base_->isHalfType()), base(base_), imm(imm_) {}
string serialize() const
{
ostringstream outbuf;
outbuf << "(" << base->serialize() << "+" << imm << ")";
return outbuf.str();
}
AddressType getType(void) const
{
return base->getType();
}
protected:
const Address* base;
const int imm;
};
class IndirectAddress : public Address
{
public:
IndirectAddress(const Address* a_, string offset_var_, int imm_) : Address(a_->isHalfType()), a(a_), offset_var(offset_var_), imm(imm_) {}
AddressType getType(void) const
{
return a->getType();
}
string serialize() const
{
ostringstream outbuf;
outbuf << "(" << a->serialize() << " + " << offset_var <<"[" << imm << "])";
return outbuf.str();
}
private:
const Address* a;
const string offset_var;
const int imm;
};
class GatherAddress : public Address
{
public:
GatherAddress(const Address *base_, string& offsets_) : Address(base_->isHalfType()), base(base_), offsets(offsets_) {};
string serialize(void) const
{
ostringstream outbuf;
outbuf<< "(" << base->serialize() << ")["<< offsets<< "[0:VECLEN]]";
return outbuf.str();
}
AddressType getType(void) const
{
return base->getType();
}
string getBase(void) const
{
return base->serialize();
}
string getOffsets(bool prefixed = true) const
{
if(prefixed == true) {
return "vec_" + offsets;
}
else {
return offsets;
}
}
const Address* getAddr(int ind) const
{
return new IndirectAddress(base, offsets, ind);
}
protected:
const Address* base;
const string offsets;
};
#endif //_ADDRESS_TYPES_H_