blob: 7c6b4d5701281a8f860c5fa9434c89716bc29cfb [file] [log] [blame]
Zane Shelley871adec2019-07-30 11:01:39 -05001#pragma once
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05002
Zane Shelley52cb1a92019-08-21 14:38:31 -05003#include <register/hei_register.hpp>
4
Zane Shelley871adec2019-07-30 11:01:39 -05005namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05006{
7
Zane Shelley23244cb2019-08-30 21:12:12 -05008class NotRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05009{
10 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -060011 NotRegister(Register& i_arg) :
12 Register(), iv_child(&i_arg), iv_iBS(i_arg.GetBitLength())
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050013 {
14 iv_bs = &iv_iBS;
15 }
16
Zane Shelleycaee69f2019-12-05 13:42:58 -060017 NotRegister& operator=(const NotRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050018 {
19 iv_child = r.iv_child;
Zane Shelleycaee69f2019-12-05 13:42:58 -060020 iv_iBS = r.iv_iBS;
21 // iv_bs = r.iv_bs; <-- don't do this!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050022 return *this;
23 }
24
Zane Shelleycaee69f2019-12-05 13:42:58 -060025 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050026 {
Zane Shelley53efc352019-10-03 21:46:39 -050027 (*iv_bs) = ~(*iv_child->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050028 return iv_bs;
29 }
30
Zane Shelleycaee69f2019-12-05 13:42:58 -060031 bool operator==(const NotRegister& r) const
32 {
33 return r.iv_child == iv_child;
34 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050035
Zane Shelleycaee69f2019-12-05 13:42:58 -060036 bool operator<(const NotRegister& r) const
37 {
38 return iv_child < r.iv_child;
39 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050040
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050041 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -060042 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050043
Zane Shelleycaee69f2019-12-05 13:42:58 -060044 BitStringBuffer* iv_bs;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050045 BitStringBuffer iv_iBS;
46};
47
Zane Shelley23244cb2019-08-30 21:12:12 -050048class LeftShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050049{
50 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -060051 LeftShiftRegister(Register& i_arg, uint16_t i_amount) :
52 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050053 iv_iBS(i_arg.GetBitLength())
54 {
55 iv_bs = &iv_iBS;
56 }
57
Zane Shelleycaee69f2019-12-05 13:42:58 -060058 LeftShiftRegister& operator=(const LeftShiftRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050059 {
Zane Shelleycaee69f2019-12-05 13:42:58 -060060 iv_child = r.iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050061 iv_amount = r.iv_amount;
Zane Shelleycaee69f2019-12-05 13:42:58 -060062 iv_iBS = r.iv_iBS;
63 // iv_bs = r.iv_bs; <-- don't do this!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050064 return *this;
65 }
66
Zane Shelleycaee69f2019-12-05 13:42:58 -060067 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050068 {
Zane Shelley53efc352019-10-03 21:46:39 -050069 (*iv_bs) = (*iv_child->getBitString(i_chip)) << iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050070 return iv_bs;
71 }
72
Zane Shelleycaee69f2019-12-05 13:42:58 -060073 bool operator==(const LeftShiftRegister& r) const
74 {
75 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
76 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050077
Zane Shelleycaee69f2019-12-05 13:42:58 -060078 bool operator<(const LeftShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050079 {
80 if (iv_child == r.iv_child)
81 return iv_amount < r.iv_amount;
82 return iv_child < r.iv_child;
83 }
84
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050085 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -060086 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050087 uint16_t iv_amount;
88
Zane Shelleycaee69f2019-12-05 13:42:58 -060089 BitStringBuffer* iv_bs;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050090 BitStringBuffer iv_iBS;
91};
92
Zane Shelley23244cb2019-08-30 21:12:12 -050093class RightShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050094{
95 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -060096 RightShiftRegister(Register& i_arg, uint16_t i_amount) :
97 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050098 iv_iBS(i_arg.GetBitLength())
99 {
100 iv_bs = &iv_iBS;
101 }
102
Zane Shelleycaee69f2019-12-05 13:42:58 -0600103 RightShiftRegister& operator=(const RightShiftRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500104 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600105 iv_child = r.iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500106 iv_amount = r.iv_amount;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600107 iv_iBS = r.iv_iBS;
108 // iv_bs = r.iv_bs; <-- don't do this!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500109 return *this;
110 }
111
Zane Shelleycaee69f2019-12-05 13:42:58 -0600112 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500113 {
Zane Shelley53efc352019-10-03 21:46:39 -0500114 (*iv_bs) = (*iv_child->getBitString(i_chip)) >> iv_amount;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500115 return iv_bs;
116 }
117
Zane Shelleycaee69f2019-12-05 13:42:58 -0600118 bool operator==(const RightShiftRegister& r) const
119 {
120 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
121 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500122
Zane Shelleycaee69f2019-12-05 13:42:58 -0600123 bool operator<(const RightShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500124 {
125 if (iv_child == r.iv_child)
126 return iv_amount < r.iv_amount;
127 return iv_child < r.iv_child;
128 }
129
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500130 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600131 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500132 uint16_t iv_amount;
133
Zane Shelleycaee69f2019-12-05 13:42:58 -0600134 BitStringBuffer* iv_bs;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500135 BitStringBuffer iv_iBS;
136};
137
Zane Shelley23244cb2019-08-30 21:12:12 -0500138class AndRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500139{
140 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600141 AndRegister(Register& i_left, Register& i_right) :
142 Register(), iv_left(&i_left), iv_right(&i_right),
143 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500144 {
145 iv_bs = &iv_iBS;
146 }
147
Zane Shelleycaee69f2019-12-05 13:42:58 -0600148 AndRegister& operator=(const AndRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500149 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600150 iv_left = r.iv_left;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500151 iv_right = r.iv_right;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600152 iv_iBS = r.iv_iBS;
153 // iv_bs = r.iv_bs; <-- don't do this!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500154 return *this;
155 }
156
Zane Shelleycaee69f2019-12-05 13:42:58 -0600157 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500158 {
Zane Shelley53efc352019-10-03 21:46:39 -0500159 (*iv_bs) = *iv_left->getBitString(i_chip);
160 (*iv_bs) = (*iv_bs) & (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500161 return iv_bs;
162 }
163
Zane Shelleycaee69f2019-12-05 13:42:58 -0600164 bool operator==(const AndRegister& r) const
165 {
166 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
167 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500168
Zane Shelleycaee69f2019-12-05 13:42:58 -0600169 bool operator<(const AndRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500170 {
171 if (iv_left == r.iv_left)
172 return iv_right < r.iv_right;
173 return iv_left < r.iv_left;
174 }
175
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500176 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600177 Register* iv_left;
178 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500179
Zane Shelleycaee69f2019-12-05 13:42:58 -0600180 BitStringBuffer* iv_bs;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500181 BitStringBuffer iv_iBS;
182};
183
Zane Shelley23244cb2019-08-30 21:12:12 -0500184class OrRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500185{
186 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600187 OrRegister(Register& i_left, Register& i_right) :
188 Register(), iv_left(&i_left), iv_right(&i_right),
189 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500190 {
191 iv_bs = &iv_iBS;
192 }
193
Zane Shelleycaee69f2019-12-05 13:42:58 -0600194 OrRegister& operator=(const OrRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500195 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600196 iv_left = r.iv_left;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500197 iv_right = r.iv_right;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600198 iv_iBS = r.iv_iBS;
199 // iv_bs = r.iv_bs; <-- don't do this!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500200 return *this;
201 }
202
Zane Shelleycaee69f2019-12-05 13:42:58 -0600203 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500204 {
Zane Shelley53efc352019-10-03 21:46:39 -0500205 (*iv_bs) = *iv_left->getBitString(i_chip);
206 (*iv_bs) = (*iv_bs) | (*iv_right->getBitString(i_chip));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500207 return iv_bs;
208 }
209
Zane Shelleycaee69f2019-12-05 13:42:58 -0600210 bool operator==(const OrRegister& r) const
211 {
212 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
213 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500214
Zane Shelleycaee69f2019-12-05 13:42:58 -0600215 bool operator<(const OrRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500216 {
217 if (iv_left == r.iv_left)
218 return iv_right < r.iv_right;
219 return iv_left < r.iv_left;
220 }
221
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500222 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600223 Register* iv_left;
224 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500225
Zane Shelleycaee69f2019-12-05 13:42:58 -0600226 BitStringBuffer* iv_bs;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500227 BitStringBuffer iv_iBS;
228};
229
Zane Shelley23244cb2019-08-30 21:12:12 -0500230class ConstantRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500231{
232 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600233 ConstantRegister(const BitStringBuffer& i_arg) : Register(), iv_iBS(i_arg)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500234 {}
235
Zane Shelleycaee69f2019-12-05 13:42:58 -0600236 ConstantRegister& operator=(const ConstantRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500237 {
238 iv_iBS = r.iv_iBS;
239 return *this;
240 }
241
Zane Shelleycaee69f2019-12-05 13:42:58 -0600242 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500243 {
244 return &iv_iBS;
245 }
246
Zane Shelleycaee69f2019-12-05 13:42:58 -0600247 bool operator==(const ConstantRegister& r) const
248 {
249 return r.iv_iBS == iv_iBS;
250 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500251
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500252 private:
253 BitStringBuffer iv_iBS;
254};
255
Zane Shelley871adec2019-07-30 11:01:39 -0500256} // end namespace libhei