blob: ee2519c501a41eb3836726566b5a071225a291b9 [file] [log] [blame]
Zane Shelley871adec2019-07-30 11:01:39 -05001#pragma once
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05002
3#include <algorithm>
4
Zane Shelley52cb1a92019-08-21 14:38:31 -05005#include <register/hei_register.hpp>
6
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05007#include <prdrCommon.H>
8
Zane Shelley871adec2019-07-30 11:01:39 -05009namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050010{
11
Zane Shelley23244cb2019-08-30 21:12:12 -050012class NotRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050013{
14 public:
15 NotRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -050016 Register( ), iv_child(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050017 {
18 iv_bs = &iv_iBS;
19 }
20
Zane Shelley23244cb2019-08-30 21:12:12 -050021 NotRegister(Register & i_arg) :
22 Register( ), iv_child(&i_arg),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050023 iv_iBS(i_arg.GetBitLength())
24 {
25 iv_bs = &iv_iBS;
26 }
27
28 NotRegister & operator=(const NotRegister & r)
29 {
30 iv_child = r.iv_child;
31 iv_iBS = r.iv_iBS;
32 //iv_bs = r.iv_bs; <-- don't do this!
33 return *this;
34 }
35
36 virtual uint32_t Read() const { return iv_child->Read(); }
37 virtual uint32_t Write() { return iv_child->Write(); }
38
Zane Shelley53efc352019-10-03 21:46:39 -050039 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050040 {
Zane Shelley53efc352019-10-03 21:46:39 -050041 (*iv_bs) = ~(*iv_child->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050042 return iv_bs;
43 }
44
45 virtual uint16_t GetId() const { return iv_child->GetId(); }
46 virtual void SetId(uint16_t i_id) {}
47
48 bool operator==(const NotRegister & r) const
49 { return r.iv_child == iv_child; }
50
51 bool operator<(const NotRegister & r) const
52 { return iv_child < r.iv_child; }
53
54 bool operator>=(const NotRegister & r) const
55 { return iv_child >= r.iv_child; }
56
57 protected:
58 BitString & AccessBitString(void) { return iv_iBS; }
59 void SetBitString(const BitString *) {}
60
61 private:
Zane Shelley23244cb2019-08-30 21:12:12 -050062 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050063
64 BitStringBuffer * iv_bs;
65 BitStringBuffer iv_iBS;
66};
67
Zane Shelley23244cb2019-08-30 21:12:12 -050068class LeftShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050069{
70 public:
71 LeftShiftRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -050072 Register( ), iv_child(nullptr), iv_amount(0), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050073 {
74 iv_bs = &iv_iBS;
75 }
76
Zane Shelley23244cb2019-08-30 21:12:12 -050077 LeftShiftRegister(Register & i_arg, uint16_t i_amount) :
78 Register( ), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050079 iv_iBS(i_arg.GetBitLength())
80 {
81 iv_bs = &iv_iBS;
82 }
83
84 LeftShiftRegister & operator=(const LeftShiftRegister & r)
85 {
86 iv_child = r.iv_child;
87 iv_amount = r.iv_amount;
88 iv_iBS = r.iv_iBS;
89 //iv_bs = r.iv_bs; <-- don't do this!
90 return *this;
91 }
92
93 virtual uint32_t Read() const { return iv_child->Read(); }
94 virtual uint32_t Write() { return iv_child->Write(); }
95
Zane Shelley53efc352019-10-03 21:46:39 -050096 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050097 {
Zane Shelley53efc352019-10-03 21:46:39 -050098 (*iv_bs) = (*iv_child->getBitString(i_chip)) << iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050099 return iv_bs;
100 }
101
102 virtual uint16_t GetId() const { return iv_child->GetId(); }
103 virtual void SetId(uint16_t i_id) {}
104
105 bool operator==(const LeftShiftRegister & r) const
106 { return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); }
107
108 bool operator<(const LeftShiftRegister & r) const
109 {
110 if (iv_child == r.iv_child)
111 return iv_amount < r.iv_amount;
112 return iv_child < r.iv_child;
113 }
114
115 bool operator>=(const LeftShiftRegister & r) const
116 {
117 if (iv_child == r.iv_child)
118 return iv_amount >= r.iv_amount;
119 return iv_child >= r.iv_child;
120 }
121
122 protected:
123 BitString & AccessBitString(void) { return iv_iBS; }
124 void SetBitString(const BitString *) {}
125
126 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500127 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500128 uint16_t iv_amount;
129
130 BitStringBuffer * iv_bs;
131 BitStringBuffer iv_iBS;
132};
133
Zane Shelley23244cb2019-08-30 21:12:12 -0500134class RightShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500135{
136 public:
137 RightShiftRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500138 Register( ), iv_child(nullptr), iv_amount(0), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500139 {
140 iv_bs = &iv_iBS;
141 }
142
Zane Shelley23244cb2019-08-30 21:12:12 -0500143 RightShiftRegister(Register & i_arg, uint16_t i_amount) :
144 Register( ), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500145 iv_iBS(i_arg.GetBitLength())
146 {
147 iv_bs = &iv_iBS;
148 }
149
150 RightShiftRegister & operator=(const RightShiftRegister & r)
151 {
152 iv_child = r.iv_child;
153 iv_amount = r.iv_amount;
154 iv_iBS = r.iv_iBS;
155 //iv_bs = r.iv_bs; <-- don't do this!
156 return *this;
157 }
158
159 virtual uint32_t Read() const { return iv_child->Read(); }
160 virtual uint32_t Write() { return iv_child->Write(); }
161
Zane Shelley53efc352019-10-03 21:46:39 -0500162 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500163 {
Zane Shelley53efc352019-10-03 21:46:39 -0500164 (*iv_bs) = (*iv_child->getBitString(i_chip)) >> iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500165 return iv_bs;
166 }
167
168 virtual uint16_t GetId() const { return iv_child->GetId(); }
169 virtual void SetId(uint16_t i_id) {}
170
171 bool operator==(const RightShiftRegister & r) const
172 { return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); }
173
174 bool operator<(const RightShiftRegister & r) const
175 {
176 if (iv_child == r.iv_child)
177 return iv_amount < r.iv_amount;
178 return iv_child < r.iv_child;
179 }
180
181 bool operator>=(const RightShiftRegister & r) const
182 {
183 if (iv_child == r.iv_child)
184 return iv_amount >= r.iv_amount;
185 return iv_child >= r.iv_child;
186 }
187
188 protected:
189 BitString & AccessBitString(void) { return iv_iBS; }
190 void SetBitString(const BitString *) {}
191
192 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500193 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500194 uint16_t iv_amount;
195
196 BitStringBuffer * iv_bs;
197 BitStringBuffer iv_iBS;
198};
199
200
Zane Shelley23244cb2019-08-30 21:12:12 -0500201class AndRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500202{
203 public:
204 AndRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500205 Register( ), iv_left(nullptr), iv_right(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500206 {
207 iv_bs = &iv_iBS;
208 }
209
Zane Shelley23244cb2019-08-30 21:12:12 -0500210 AndRegister( Register & i_left,
211 Register & i_right ) :
212 Register( ), iv_left(&i_left), iv_right(&i_right),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500213 iv_iBS(std::min(i_left.GetBitLength(),
214 i_right.GetBitLength()))
215 {
216 iv_bs = &iv_iBS;
217 }
218
219 AndRegister & operator=(const AndRegister & r)
220 {
221 iv_left = r.iv_left;
222 iv_right = r.iv_right;
223 iv_iBS = r.iv_iBS;
224 //iv_bs = r.iv_bs; <-- don't do this!
225 return *this;
226 }
227
228 virtual uint32_t Read() const
229 {
230 return iv_left->Read() | iv_right->Read();
231 }
232 virtual uint32_t Write()
233 {
234 return iv_left->Write() | iv_right->Write();
235 }
236
Zane Shelley53efc352019-10-03 21:46:39 -0500237 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500238 {
Zane Shelley53efc352019-10-03 21:46:39 -0500239 (*iv_bs) = *iv_left->getBitString(i_chip);
240 (*iv_bs) = (*iv_bs) & (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500241 return iv_bs;
242 }
243
244 virtual uint16_t GetId() const
245 {
246 return Prdr::SignatureOp::combineSig(iv_left->GetId(),
247 iv_right->GetId());
248 }
249
250 virtual void SetId(uint16_t i_id) {}
251
252 bool operator==(const AndRegister & r) const
253 { return (r.iv_left == iv_left) && (r.iv_right == iv_right); }
254
255 bool operator<(const AndRegister & r) const
256 {
257 if (iv_left == r.iv_left)
258 return iv_right < r.iv_right;
259 return iv_left < r.iv_left;
260 }
261
262 bool operator>=(const AndRegister & r) const
263 {
264 if (iv_left == r.iv_left)
265 return iv_right >= r.iv_right;
266 return iv_left >= r.iv_left;
267 }
268
269 protected:
270 BitString & AccessBitString(void) { return iv_iBS; }
271 void SetBitString(const BitString *) {}
272
273 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500274 Register * iv_left;
275 Register * iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500276
277 BitStringBuffer * iv_bs;
278 BitStringBuffer iv_iBS;
279};
280
Zane Shelley23244cb2019-08-30 21:12:12 -0500281class OrRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500282{
283 public:
284
285 OrRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500286 Register( ), iv_left(nullptr), iv_right(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500287 {
288 iv_bs = &iv_iBS;
289 }
290
Zane Shelley23244cb2019-08-30 21:12:12 -0500291 OrRegister( Register & i_left,
292 Register & i_right ) :
293 Register( ), iv_left(&i_left), iv_right(&i_right),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500294 iv_iBS(std::min(i_left.GetBitLength(),
295 i_right.GetBitLength()))
296 {
297 iv_bs = &iv_iBS;
298 }
299
300 OrRegister & operator=(const OrRegister & r)
301 {
302 iv_left = r.iv_left;
303 iv_right = r.iv_right;
304 iv_iBS = r.iv_iBS;
305 //iv_bs = r.iv_bs; <-- don't do this!
306 return *this;
307 }
308
309 virtual uint32_t Read() const
310 {
311 return iv_left->Read() | iv_right->Read();
312 }
313
314 virtual uint32_t Write()
315 {
316 return iv_left->Write() | iv_right->Write();
317 }
318
Zane Shelley53efc352019-10-03 21:46:39 -0500319 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500320 {
Zane Shelley53efc352019-10-03 21:46:39 -0500321 (*iv_bs) = *iv_left->getBitString(i_chip);
322 (*iv_bs) = (*iv_bs) | (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500323 return iv_bs;
324 }
325
326 virtual uint16_t GetId() const
327 {
328 return Prdr::SignatureOp::combineSig( iv_left->GetId(),
329 iv_right->GetId() );
330 }
331
332 virtual void SetId(uint16_t i_id) {}
333
334 bool operator==(const OrRegister & r) const
335 { return (r.iv_left == iv_left) && (r.iv_right == iv_right); }
336
337 bool operator<(const OrRegister & r) const
338 {
339 if (iv_left == r.iv_left)
340 return iv_right < r.iv_right;
341 return iv_left < r.iv_left;
342 }
343
344 bool operator>=(const OrRegister & r) const
345 {
346 if (iv_left == r.iv_left)
347 return iv_right >= r.iv_right;
348 return iv_left >= r.iv_left;
349 }
350
351 protected:
352 BitString & AccessBitString(void) { return iv_iBS; }
353 void SetBitString(const BitString *) {}
354
355 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500356 Register * iv_left;
357 Register * iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500358
359 BitStringBuffer * iv_bs;
360 BitStringBuffer iv_iBS;
361};
362
Zane Shelley23244cb2019-08-30 21:12:12 -0500363class NullRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500364{
365 public:
366 NullRegister(int size) :
Zane Shelley23244cb2019-08-30 21:12:12 -0500367 Register( ), iv_iBS(size)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500368 {}
369
370 NullRegister & operator=(const NullRegister & r)
371 {
372 iv_iBS = r.iv_iBS;
373 return *this;
374 }
375
376 virtual uint32_t Read() const { return 0; }
377 virtual uint32_t Write() { return 0; }
378
Zane Shelley53efc352019-10-03 21:46:39 -0500379 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500380 {
381 return &iv_iBS;
382 }
383
384 protected:
385 BitString & AccessBitString(void) { return iv_iBS; }
386 void SetBitString(const BitString *) {}
387
388 private:
389 BitStringBuffer iv_iBS;
390
391 virtual uint16_t GetId() const
392 { return Prdr::SignatureOp::DEFAULT_SIGNATURE; }
393
394 virtual void SetId(uint16_t i_id) {}
395
396};
397
Zane Shelley23244cb2019-08-30 21:12:12 -0500398class ConstantRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500399{
400 public:
401 ConstantRegister() :
Zane Shelley23244cb2019-08-30 21:12:12 -0500402 Register( ), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500403 {}
404
405 ConstantRegister( const BitStringBuffer & i_arg ) :
Zane Shelley23244cb2019-08-30 21:12:12 -0500406 Register( ), iv_iBS(i_arg)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500407 {}
408
409 ConstantRegister & operator=(const ConstantRegister & r)
410 {
411 iv_iBS = r.iv_iBS;
412 return *this;
413 }
414
415 virtual uint32_t Read() const { return SUCCESS; }
416 virtual uint32_t Write() { return SUCCESS; }
417
Zane Shelley53efc352019-10-03 21:46:39 -0500418 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500419 {
420 return &iv_iBS;
421 }
422
423 virtual uint16_t GetId() const
424 { return Prdr::SignatureOp::DEFAULT_SIGNATURE; }
425
426 virtual void SetId(uint16_t i_id) {}
427
428 bool operator==(const ConstantRegister & r) const
429 { return r.iv_iBS == iv_iBS; }
430
431 protected:
432 BitString & AccessBitString(void) { return iv_iBS; }
433 void SetBitString(const BitString *) {}
434
435 private:
436 BitStringBuffer iv_iBS;
437};
438
Zane Shelley871adec2019-07-30 11:01:39 -0500439} // end namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500440