blob: 6161ed11e02ab73c0ea38c1659aa2ce43a588a4a [file] [log] [blame]
Zane Shelleydd156ad2019-10-25 20:59:55 -05001// clang-format off
Zane Shelley871adec2019-07-30 11:01:39 -05002#pragma once
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05003
4#include <algorithm>
5
Zane Shelley52cb1a92019-08-21 14:38:31 -05006#include <register/hei_register.hpp>
7
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05008#include <prdrCommon.H>
9
Zane Shelley871adec2019-07-30 11:01:39 -050010namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050011{
12
Zane Shelley23244cb2019-08-30 21:12:12 -050013class NotRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050014{
15 public:
16 NotRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -050017 Register( ), iv_child(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050018 {
19 iv_bs = &iv_iBS;
20 }
21
Zane Shelley23244cb2019-08-30 21:12:12 -050022 NotRegister(Register & i_arg) :
23 Register( ), iv_child(&i_arg),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050024 iv_iBS(i_arg.GetBitLength())
25 {
26 iv_bs = &iv_iBS;
27 }
28
29 NotRegister & operator=(const NotRegister & r)
30 {
31 iv_child = r.iv_child;
32 iv_iBS = r.iv_iBS;
33 //iv_bs = r.iv_bs; <-- don't do this!
34 return *this;
35 }
36
37 virtual uint32_t Read() const { return iv_child->Read(); }
38 virtual uint32_t Write() { return iv_child->Write(); }
39
Zane Shelley53efc352019-10-03 21:46:39 -050040 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050041 {
Zane Shelley53efc352019-10-03 21:46:39 -050042 (*iv_bs) = ~(*iv_child->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050043 return iv_bs;
44 }
45
46 virtual uint16_t GetId() const { return iv_child->GetId(); }
47 virtual void SetId(uint16_t i_id) {}
48
49 bool operator==(const NotRegister & r) const
50 { return r.iv_child == iv_child; }
51
52 bool operator<(const NotRegister & r) const
53 { return iv_child < r.iv_child; }
54
55 bool operator>=(const NotRegister & r) const
56 { return iv_child >= r.iv_child; }
57
58 protected:
59 BitString & AccessBitString(void) { return iv_iBS; }
60 void SetBitString(const BitString *) {}
61
62 private:
Zane Shelley23244cb2019-08-30 21:12:12 -050063 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050064
65 BitStringBuffer * iv_bs;
66 BitStringBuffer iv_iBS;
67};
68
Zane Shelley23244cb2019-08-30 21:12:12 -050069class LeftShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050070{
71 public:
72 LeftShiftRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -050073 Register( ), iv_child(nullptr), iv_amount(0), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050074 {
75 iv_bs = &iv_iBS;
76 }
77
Zane Shelley23244cb2019-08-30 21:12:12 -050078 LeftShiftRegister(Register & i_arg, uint16_t i_amount) :
79 Register( ), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050080 iv_iBS(i_arg.GetBitLength())
81 {
82 iv_bs = &iv_iBS;
83 }
84
85 LeftShiftRegister & operator=(const LeftShiftRegister & r)
86 {
87 iv_child = r.iv_child;
88 iv_amount = r.iv_amount;
89 iv_iBS = r.iv_iBS;
90 //iv_bs = r.iv_bs; <-- don't do this!
91 return *this;
92 }
93
94 virtual uint32_t Read() const { return iv_child->Read(); }
95 virtual uint32_t Write() { return iv_child->Write(); }
96
Zane Shelley53efc352019-10-03 21:46:39 -050097 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050098 {
Zane Shelley53efc352019-10-03 21:46:39 -050099 (*iv_bs) = (*iv_child->getBitString(i_chip)) << iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500100 return iv_bs;
101 }
102
103 virtual uint16_t GetId() const { return iv_child->GetId(); }
104 virtual void SetId(uint16_t i_id) {}
105
106 bool operator==(const LeftShiftRegister & r) const
107 { return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); }
108
109 bool operator<(const LeftShiftRegister & r) const
110 {
111 if (iv_child == r.iv_child)
112 return iv_amount < r.iv_amount;
113 return iv_child < r.iv_child;
114 }
115
116 bool operator>=(const LeftShiftRegister & r) const
117 {
118 if (iv_child == r.iv_child)
119 return iv_amount >= r.iv_amount;
120 return iv_child >= r.iv_child;
121 }
122
123 protected:
124 BitString & AccessBitString(void) { return iv_iBS; }
125 void SetBitString(const BitString *) {}
126
127 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500128 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500129 uint16_t iv_amount;
130
131 BitStringBuffer * iv_bs;
132 BitStringBuffer iv_iBS;
133};
134
Zane Shelley23244cb2019-08-30 21:12:12 -0500135class RightShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500136{
137 public:
138 RightShiftRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500139 Register( ), iv_child(nullptr), iv_amount(0), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500140 {
141 iv_bs = &iv_iBS;
142 }
143
Zane Shelley23244cb2019-08-30 21:12:12 -0500144 RightShiftRegister(Register & i_arg, uint16_t i_amount) :
145 Register( ), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500146 iv_iBS(i_arg.GetBitLength())
147 {
148 iv_bs = &iv_iBS;
149 }
150
151 RightShiftRegister & operator=(const RightShiftRegister & r)
152 {
153 iv_child = r.iv_child;
154 iv_amount = r.iv_amount;
155 iv_iBS = r.iv_iBS;
156 //iv_bs = r.iv_bs; <-- don't do this!
157 return *this;
158 }
159
160 virtual uint32_t Read() const { return iv_child->Read(); }
161 virtual uint32_t Write() { return iv_child->Write(); }
162
Zane Shelley53efc352019-10-03 21:46:39 -0500163 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500164 {
Zane Shelley53efc352019-10-03 21:46:39 -0500165 (*iv_bs) = (*iv_child->getBitString(i_chip)) >> iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500166 return iv_bs;
167 }
168
169 virtual uint16_t GetId() const { return iv_child->GetId(); }
170 virtual void SetId(uint16_t i_id) {}
171
172 bool operator==(const RightShiftRegister & r) const
173 { return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); }
174
175 bool operator<(const RightShiftRegister & r) const
176 {
177 if (iv_child == r.iv_child)
178 return iv_amount < r.iv_amount;
179 return iv_child < r.iv_child;
180 }
181
182 bool operator>=(const RightShiftRegister & r) const
183 {
184 if (iv_child == r.iv_child)
185 return iv_amount >= r.iv_amount;
186 return iv_child >= r.iv_child;
187 }
188
189 protected:
190 BitString & AccessBitString(void) { return iv_iBS; }
191 void SetBitString(const BitString *) {}
192
193 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500194 Register * iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500195 uint16_t iv_amount;
196
197 BitStringBuffer * iv_bs;
198 BitStringBuffer iv_iBS;
199};
200
201
Zane Shelley23244cb2019-08-30 21:12:12 -0500202class AndRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500203{
204 public:
205 AndRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500206 Register( ), iv_left(nullptr), iv_right(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500207 {
208 iv_bs = &iv_iBS;
209 }
210
Zane Shelley23244cb2019-08-30 21:12:12 -0500211 AndRegister( Register & i_left,
212 Register & i_right ) :
213 Register( ), iv_left(&i_left), iv_right(&i_right),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500214 iv_iBS(std::min(i_left.GetBitLength(),
215 i_right.GetBitLength()))
216 {
217 iv_bs = &iv_iBS;
218 }
219
220 AndRegister & operator=(const AndRegister & r)
221 {
222 iv_left = r.iv_left;
223 iv_right = r.iv_right;
224 iv_iBS = r.iv_iBS;
225 //iv_bs = r.iv_bs; <-- don't do this!
226 return *this;
227 }
228
229 virtual uint32_t Read() const
230 {
231 return iv_left->Read() | iv_right->Read();
232 }
233 virtual uint32_t Write()
234 {
235 return iv_left->Write() | iv_right->Write();
236 }
237
Zane Shelley53efc352019-10-03 21:46:39 -0500238 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500239 {
Zane Shelley53efc352019-10-03 21:46:39 -0500240 (*iv_bs) = *iv_left->getBitString(i_chip);
241 (*iv_bs) = (*iv_bs) & (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500242 return iv_bs;
243 }
244
245 virtual uint16_t GetId() const
246 {
247 return Prdr::SignatureOp::combineSig(iv_left->GetId(),
248 iv_right->GetId());
249 }
250
251 virtual void SetId(uint16_t i_id) {}
252
253 bool operator==(const AndRegister & r) const
254 { return (r.iv_left == iv_left) && (r.iv_right == iv_right); }
255
256 bool operator<(const AndRegister & r) const
257 {
258 if (iv_left == r.iv_left)
259 return iv_right < r.iv_right;
260 return iv_left < r.iv_left;
261 }
262
263 bool operator>=(const AndRegister & r) const
264 {
265 if (iv_left == r.iv_left)
266 return iv_right >= r.iv_right;
267 return iv_left >= r.iv_left;
268 }
269
270 protected:
271 BitString & AccessBitString(void) { return iv_iBS; }
272 void SetBitString(const BitString *) {}
273
274 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500275 Register * iv_left;
276 Register * iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500277
278 BitStringBuffer * iv_bs;
279 BitStringBuffer iv_iBS;
280};
281
Zane Shelley23244cb2019-08-30 21:12:12 -0500282class OrRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500283{
284 public:
285
286 OrRegister() :
Zane Shelley05bac982019-09-02 20:57:42 -0500287 Register( ), iv_left(nullptr), iv_right(nullptr), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500288 {
289 iv_bs = &iv_iBS;
290 }
291
Zane Shelley23244cb2019-08-30 21:12:12 -0500292 OrRegister( Register & i_left,
293 Register & i_right ) :
294 Register( ), iv_left(&i_left), iv_right(&i_right),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500295 iv_iBS(std::min(i_left.GetBitLength(),
296 i_right.GetBitLength()))
297 {
298 iv_bs = &iv_iBS;
299 }
300
301 OrRegister & operator=(const OrRegister & r)
302 {
303 iv_left = r.iv_left;
304 iv_right = r.iv_right;
305 iv_iBS = r.iv_iBS;
306 //iv_bs = r.iv_bs; <-- don't do this!
307 return *this;
308 }
309
310 virtual uint32_t Read() const
311 {
312 return iv_left->Read() | iv_right->Read();
313 }
314
315 virtual uint32_t Write()
316 {
317 return iv_left->Write() | iv_right->Write();
318 }
319
Zane Shelley53efc352019-10-03 21:46:39 -0500320 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500321 {
Zane Shelley53efc352019-10-03 21:46:39 -0500322 (*iv_bs) = *iv_left->getBitString(i_chip);
323 (*iv_bs) = (*iv_bs) | (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500324 return iv_bs;
325 }
326
327 virtual uint16_t GetId() const
328 {
329 return Prdr::SignatureOp::combineSig( iv_left->GetId(),
330 iv_right->GetId() );
331 }
332
333 virtual void SetId(uint16_t i_id) {}
334
335 bool operator==(const OrRegister & r) const
336 { return (r.iv_left == iv_left) && (r.iv_right == iv_right); }
337
338 bool operator<(const OrRegister & r) const
339 {
340 if (iv_left == r.iv_left)
341 return iv_right < r.iv_right;
342 return iv_left < r.iv_left;
343 }
344
345 bool operator>=(const OrRegister & r) const
346 {
347 if (iv_left == r.iv_left)
348 return iv_right >= r.iv_right;
349 return iv_left >= r.iv_left;
350 }
351
352 protected:
353 BitString & AccessBitString(void) { return iv_iBS; }
354 void SetBitString(const BitString *) {}
355
356 private:
Zane Shelley23244cb2019-08-30 21:12:12 -0500357 Register * iv_left;
358 Register * iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500359
360 BitStringBuffer * iv_bs;
361 BitStringBuffer iv_iBS;
362};
363
Zane Shelley23244cb2019-08-30 21:12:12 -0500364class NullRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500365{
366 public:
367 NullRegister(int size) :
Zane Shelley23244cb2019-08-30 21:12:12 -0500368 Register( ), iv_iBS(size)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500369 {}
370
371 NullRegister & operator=(const NullRegister & r)
372 {
373 iv_iBS = r.iv_iBS;
374 return *this;
375 }
376
377 virtual uint32_t Read() const { return 0; }
378 virtual uint32_t Write() { return 0; }
379
Zane Shelley53efc352019-10-03 21:46:39 -0500380 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500381 {
382 return &iv_iBS;
383 }
384
385 protected:
386 BitString & AccessBitString(void) { return iv_iBS; }
387 void SetBitString(const BitString *) {}
388
389 private:
390 BitStringBuffer iv_iBS;
391
392 virtual uint16_t GetId() const
393 { return Prdr::SignatureOp::DEFAULT_SIGNATURE; }
394
395 virtual void SetId(uint16_t i_id) {}
396
397};
398
Zane Shelley23244cb2019-08-30 21:12:12 -0500399class ConstantRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500400{
401 public:
402 ConstantRegister() :
Zane Shelley23244cb2019-08-30 21:12:12 -0500403 Register( ), iv_iBS(0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500404 {}
405
406 ConstantRegister( const BitStringBuffer & i_arg ) :
Zane Shelley23244cb2019-08-30 21:12:12 -0500407 Register( ), iv_iBS(i_arg)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500408 {}
409
410 ConstantRegister & operator=(const ConstantRegister & r)
411 {
412 iv_iBS = r.iv_iBS;
413 return *this;
414 }
415
416 virtual uint32_t Read() const { return SUCCESS; }
417 virtual uint32_t Write() { return SUCCESS; }
418
Zane Shelley53efc352019-10-03 21:46:39 -0500419 const BitString * getBitString( const Chip & i_chip ) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500420 {
421 return &iv_iBS;
422 }
423
424 virtual uint16_t GetId() const
425 { return Prdr::SignatureOp::DEFAULT_SIGNATURE; }
426
427 virtual void SetId(uint16_t i_id) {}
428
429 bool operator==(const ConstantRegister & r) const
430 { return r.iv_iBS == iv_iBS; }
431
432 protected:
433 BitString & AccessBitString(void) { return iv_iBS; }
434 void SetBitString(const BitString *) {}
435
436 private:
437 BitStringBuffer iv_iBS;
438};
439
Zane Shelley871adec2019-07-30 11:01:39 -0500440} // end namespace libhei
Zane Shelleydd156ad2019-10-25 20:59:55 -0500441// clang-format on