blob: 7cfd627540adee2ab03c04deebb2794b0a049896 [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 Shelley48aa8602019-12-05 21:41:21 -060011 /**
12 * @brief Constructor from components.
13 * @param i_arg Target register for operation.
14 */
15 explicit NotRegister(Register& i_arg) :
Zane Shelleycaee69f2019-12-05 13:42:58 -060016 Register(), iv_child(&i_arg), iv_iBS(i_arg.GetBitLength())
Zane Shelleyd4c0e982019-12-05 21:27:41 -060017 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050018
Zane Shelley48aa8602019-12-05 21:41:21 -060019 /** @brief Default destructor. */
20 ~NotRegister() = default;
21
22 /** @brief Default copy constructor. */
23 NotRegister(const NotRegister&) = default;
24
25 /** @brief Default assignment operator. */
26 NotRegister& operator=(const NotRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050027
Zane Shelleycaee69f2019-12-05 13:42:58 -060028 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050029 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -060030 const auto* bs = iv_child->getBitString(i_chip);
31
32 (const_cast<NotRegister*>(this))->iv_iBS = ~(*bs);
33
34 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050035 }
36
Zane Shelleycaee69f2019-12-05 13:42:58 -060037 bool operator==(const NotRegister& r) const
38 {
39 return r.iv_child == iv_child;
40 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050041
Zane Shelleycaee69f2019-12-05 13:42:58 -060042 bool operator<(const NotRegister& r) const
43 {
44 return iv_child < r.iv_child;
45 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050046
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050047 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -060048 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050049
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050050 BitStringBuffer iv_iBS;
51};
52
Zane Shelley23244cb2019-08-30 21:12:12 -050053class LeftShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050054{
55 public:
Zane Shelley48aa8602019-12-05 21:41:21 -060056 /**
57 * @brief Constructor from components.
58 * @param i_arg Target register for operation.
59 * @param i_amount The shift value.
60 */
Zane Shelleycaee69f2019-12-05 13:42:58 -060061 LeftShiftRegister(Register& i_arg, uint16_t i_amount) :
62 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050063 iv_iBS(i_arg.GetBitLength())
Zane Shelleyd4c0e982019-12-05 21:27:41 -060064 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050065
Zane Shelley48aa8602019-12-05 21:41:21 -060066 /** @brief Default destructor. */
67 ~LeftShiftRegister() = default;
68
69 /** @brief Default copy constructor. */
70 LeftShiftRegister(const LeftShiftRegister&) = default;
71
72 /** @brief Default assignment operator. */
73 LeftShiftRegister& operator=(const LeftShiftRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050074
Zane Shelleycaee69f2019-12-05 13:42:58 -060075 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050076 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -060077 const auto* bs = iv_child->getBitString(i_chip);
78
79 (const_cast<LeftShiftRegister*>(this))->iv_iBS = (*bs) << iv_amount;
80
81 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050082 }
83
Zane Shelleycaee69f2019-12-05 13:42:58 -060084 bool operator==(const LeftShiftRegister& r) const
85 {
86 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
87 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050088
Zane Shelleycaee69f2019-12-05 13:42:58 -060089 bool operator<(const LeftShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050090 {
91 if (iv_child == r.iv_child)
92 return iv_amount < r.iv_amount;
93 return iv_child < r.iv_child;
94 }
95
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050096 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -060097 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050098 uint16_t iv_amount;
99
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500100 BitStringBuffer iv_iBS;
101};
102
Zane Shelley23244cb2019-08-30 21:12:12 -0500103class RightShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500104{
105 public:
Zane Shelley48aa8602019-12-05 21:41:21 -0600106 /**
107 * @brief Constructor from components.
108 * @param i_arg Target register for operation.
109 * @param i_amount The shift value.
110 */
Zane Shelleycaee69f2019-12-05 13:42:58 -0600111 RightShiftRegister(Register& i_arg, uint16_t i_amount) :
112 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500113 iv_iBS(i_arg.GetBitLength())
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600114 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500115
Zane Shelley48aa8602019-12-05 21:41:21 -0600116 /** @brief Default destructor. */
117 ~RightShiftRegister() = default;
118
119 /** @brief Default copy constructor. */
120 RightShiftRegister(const RightShiftRegister&) = default;
121
122 /** @brief Default assignment operator. */
123 RightShiftRegister& operator=(const RightShiftRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500124
Zane Shelleycaee69f2019-12-05 13:42:58 -0600125 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500126 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600127 const auto* bs = iv_child->getBitString(i_chip);
128
129 (const_cast<RightShiftRegister*>(this))->iv_iBS = (*bs) >> iv_amount;
130
131 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500132 }
133
Zane Shelleycaee69f2019-12-05 13:42:58 -0600134 bool operator==(const RightShiftRegister& r) const
135 {
136 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
137 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500138
Zane Shelleycaee69f2019-12-05 13:42:58 -0600139 bool operator<(const RightShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500140 {
141 if (iv_child == r.iv_child)
142 return iv_amount < r.iv_amount;
143 return iv_child < r.iv_child;
144 }
145
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500146 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600147 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500148 uint16_t iv_amount;
149
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500150 BitStringBuffer iv_iBS;
151};
152
Zane Shelley23244cb2019-08-30 21:12:12 -0500153class AndRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500154{
155 public:
Zane Shelley48aa8602019-12-05 21:41:21 -0600156 /**
157 * @brief Constructor from components.
158 * @param i_left Target register for operation.
159 * @param i_right Target register for operation.
160 */
Zane Shelleycaee69f2019-12-05 13:42:58 -0600161 AndRegister(Register& i_left, Register& i_right) :
162 Register(), iv_left(&i_left), iv_right(&i_right),
163 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600164 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500165
Zane Shelley48aa8602019-12-05 21:41:21 -0600166 /** @brief Default destructor. */
167 ~AndRegister() = default;
168
169 /** @brief Default copy constructor. */
170 AndRegister(const AndRegister&) = default;
171
172 /** @brief Default assignment operator. */
173 AndRegister& operator=(const AndRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500174
Zane Shelleycaee69f2019-12-05 13:42:58 -0600175 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500176 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600177 const auto* l_bs = iv_left->getBitString(i_chip);
178 const auto* r_bs = iv_right->getBitString(i_chip);
179
180 (const_cast<AndRegister*>(this))->iv_iBS = (*l_bs) & (*r_bs);
181
182 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500183 }
184
Zane Shelleycaee69f2019-12-05 13:42:58 -0600185 bool operator==(const AndRegister& r) const
186 {
187 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
188 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500189
Zane Shelleycaee69f2019-12-05 13:42:58 -0600190 bool operator<(const AndRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500191 {
192 if (iv_left == r.iv_left)
193 return iv_right < r.iv_right;
194 return iv_left < r.iv_left;
195 }
196
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500197 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600198 Register* iv_left;
199 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500200
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500201 BitStringBuffer iv_iBS;
202};
203
Zane Shelley23244cb2019-08-30 21:12:12 -0500204class OrRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500205{
206 public:
Zane Shelley48aa8602019-12-05 21:41:21 -0600207 /**
208 * @brief Constructor from components.
209 * @param i_left Target register for operation.
210 * @param i_right Target register for operation.
211 */
Zane Shelleycaee69f2019-12-05 13:42:58 -0600212 OrRegister(Register& i_left, Register& i_right) :
213 Register(), iv_left(&i_left), iv_right(&i_right),
214 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600215 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500216
Zane Shelley48aa8602019-12-05 21:41:21 -0600217 /** @brief Default destructor. */
218 ~OrRegister() = default;
219
220 /** @brief Default copy constructor. */
221 OrRegister(const OrRegister&) = default;
222
223 /** @brief Default assignment operator. */
224 OrRegister& operator=(const OrRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500225
Zane Shelleycaee69f2019-12-05 13:42:58 -0600226 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500227 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600228 const auto* l_bs = iv_left->getBitString(i_chip);
229 const auto* r_bs = iv_right->getBitString(i_chip);
230
231 (const_cast<OrRegister*>(this))->iv_iBS = (*l_bs) | (*r_bs);
232
233 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500234 }
235
Zane Shelleycaee69f2019-12-05 13:42:58 -0600236 bool operator==(const OrRegister& r) const
237 {
238 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
239 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500240
Zane Shelleycaee69f2019-12-05 13:42:58 -0600241 bool operator<(const OrRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500242 {
243 if (iv_left == r.iv_left)
244 return iv_right < r.iv_right;
245 return iv_left < r.iv_left;
246 }
247
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500248 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600249 Register* iv_left;
250 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500251
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500252 BitStringBuffer iv_iBS;
253};
254
Zane Shelley23244cb2019-08-30 21:12:12 -0500255class ConstantRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500256{
257 public:
Zane Shelley48aa8602019-12-05 21:41:21 -0600258 /**
259 * @brief Constructor from components.
260 * @param i_arg A BitStringBuffer containing the constant value.
261 */
262 explicit ConstantRegister(const BitStringBuffer& i_arg) :
263 Register(), iv_iBS(i_arg)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500264 {}
265
Zane Shelley48aa8602019-12-05 21:41:21 -0600266 /** @brief Default destructor. */
267 ~ConstantRegister() = default;
268
269 /** @brief Default copy constructor. */
270 ConstantRegister(const ConstantRegister&) = default;
271
272 /** @brief Default assignment operator. */
273 ConstantRegister& operator=(const ConstantRegister& r) = default;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500274
Zane Shelleycaee69f2019-12-05 13:42:58 -0600275 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500276 {
277 return &iv_iBS;
278 }
279
Zane Shelleycaee69f2019-12-05 13:42:58 -0600280 bool operator==(const ConstantRegister& r) const
281 {
282 return r.iv_iBS == iv_iBS;
283 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500284
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500285 private:
286 BitStringBuffer iv_iBS;
287};
288
Zane Shelley871adec2019-07-30 11:01:39 -0500289} // end namespace libhei