blob: 50223ac6dce6816d35a0ccb59d472549e6f2e109 [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 Shelleyd4c0e982019-12-05 21:27:41 -060013 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050014
Zane Shelleycaee69f2019-12-05 13:42:58 -060015 NotRegister& operator=(const NotRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050016 {
17 iv_child = r.iv_child;
Zane Shelleycaee69f2019-12-05 13:42:58 -060018 iv_iBS = r.iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050019 return *this;
20 }
21
Zane Shelleycaee69f2019-12-05 13:42:58 -060022 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050023 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -060024 const auto* bs = iv_child->getBitString(i_chip);
25
26 (const_cast<NotRegister*>(this))->iv_iBS = ~(*bs);
27
28 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050029 }
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 Shelleyfd3f9cc2019-07-29 15:02:24 -050044 BitStringBuffer iv_iBS;
45};
46
Zane Shelley23244cb2019-08-30 21:12:12 -050047class LeftShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050048{
49 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -060050 LeftShiftRegister(Register& i_arg, uint16_t i_amount) :
51 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050052 iv_iBS(i_arg.GetBitLength())
Zane Shelleyd4c0e982019-12-05 21:27:41 -060053 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050054
Zane Shelleycaee69f2019-12-05 13:42:58 -060055 LeftShiftRegister& operator=(const LeftShiftRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050056 {
Zane Shelleycaee69f2019-12-05 13:42:58 -060057 iv_child = r.iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050058 iv_amount = r.iv_amount;
Zane Shelleycaee69f2019-12-05 13:42:58 -060059 iv_iBS = r.iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050060 return *this;
61 }
62
Zane Shelleycaee69f2019-12-05 13:42:58 -060063 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050064 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -060065 const auto* bs = iv_child->getBitString(i_chip);
66
67 (const_cast<LeftShiftRegister*>(this))->iv_iBS = (*bs) << iv_amount;
68
69 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050070 }
71
Zane Shelleycaee69f2019-12-05 13:42:58 -060072 bool operator==(const LeftShiftRegister& r) const
73 {
74 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
75 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050076
Zane Shelleycaee69f2019-12-05 13:42:58 -060077 bool operator<(const LeftShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050078 {
79 if (iv_child == r.iv_child)
80 return iv_amount < r.iv_amount;
81 return iv_child < r.iv_child;
82 }
83
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050084 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -060085 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050086 uint16_t iv_amount;
87
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050088 BitStringBuffer iv_iBS;
89};
90
Zane Shelley23244cb2019-08-30 21:12:12 -050091class RightShiftRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050092{
93 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -060094 RightShiftRegister(Register& i_arg, uint16_t i_amount) :
95 Register(), iv_child(&i_arg), iv_amount(i_amount),
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050096 iv_iBS(i_arg.GetBitLength())
Zane Shelleyd4c0e982019-12-05 21:27:41 -060097 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050098
Zane Shelleycaee69f2019-12-05 13:42:58 -060099 RightShiftRegister& operator=(const RightShiftRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500100 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600101 iv_child = r.iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500102 iv_amount = r.iv_amount;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600103 iv_iBS = r.iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500104 return *this;
105 }
106
Zane Shelleycaee69f2019-12-05 13:42:58 -0600107 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500108 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600109 const auto* bs = iv_child->getBitString(i_chip);
110
111 (const_cast<RightShiftRegister*>(this))->iv_iBS = (*bs) >> iv_amount;
112
113 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500114 }
115
Zane Shelleycaee69f2019-12-05 13:42:58 -0600116 bool operator==(const RightShiftRegister& r) const
117 {
118 return (r.iv_child == iv_child) && (r.iv_amount == iv_amount);
119 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500120
Zane Shelleycaee69f2019-12-05 13:42:58 -0600121 bool operator<(const RightShiftRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500122 {
123 if (iv_child == r.iv_child)
124 return iv_amount < r.iv_amount;
125 return iv_child < r.iv_child;
126 }
127
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500128 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600129 Register* iv_child;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500130 uint16_t iv_amount;
131
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500132 BitStringBuffer iv_iBS;
133};
134
Zane Shelley23244cb2019-08-30 21:12:12 -0500135class AndRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500136{
137 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600138 AndRegister(Register& i_left, Register& i_right) :
139 Register(), iv_left(&i_left), iv_right(&i_right),
140 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600141 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500142
Zane Shelleycaee69f2019-12-05 13:42:58 -0600143 AndRegister& operator=(const AndRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500144 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600145 iv_left = r.iv_left;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500146 iv_right = r.iv_right;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600147 iv_iBS = r.iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500148 return *this;
149 }
150
Zane Shelleycaee69f2019-12-05 13:42:58 -0600151 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500152 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600153 const auto* l_bs = iv_left->getBitString(i_chip);
154 const auto* r_bs = iv_right->getBitString(i_chip);
155
156 (const_cast<AndRegister*>(this))->iv_iBS = (*l_bs) & (*r_bs);
157
158 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500159 }
160
Zane Shelleycaee69f2019-12-05 13:42:58 -0600161 bool operator==(const AndRegister& r) const
162 {
163 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
164 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500165
Zane Shelleycaee69f2019-12-05 13:42:58 -0600166 bool operator<(const AndRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500167 {
168 if (iv_left == r.iv_left)
169 return iv_right < r.iv_right;
170 return iv_left < r.iv_left;
171 }
172
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500173 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600174 Register* iv_left;
175 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500176
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500177 BitStringBuffer iv_iBS;
178};
179
Zane Shelley23244cb2019-08-30 21:12:12 -0500180class OrRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500181{
182 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600183 OrRegister(Register& i_left, Register& i_right) :
184 Register(), iv_left(&i_left), iv_right(&i_right),
185 iv_iBS(std::min(i_left.GetBitLength(), i_right.GetBitLength()))
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600186 {}
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500187
Zane Shelleycaee69f2019-12-05 13:42:58 -0600188 OrRegister& operator=(const OrRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500189 {
Zane Shelleycaee69f2019-12-05 13:42:58 -0600190 iv_left = r.iv_left;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500191 iv_right = r.iv_right;
Zane Shelleycaee69f2019-12-05 13:42:58 -0600192 iv_iBS = r.iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500193 return *this;
194 }
195
Zane Shelleycaee69f2019-12-05 13:42:58 -0600196 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500197 {
Zane Shelleyd4c0e982019-12-05 21:27:41 -0600198 const auto* l_bs = iv_left->getBitString(i_chip);
199 const auto* r_bs = iv_right->getBitString(i_chip);
200
201 (const_cast<OrRegister*>(this))->iv_iBS = (*l_bs) | (*r_bs);
202
203 return &iv_iBS;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500204 }
205
Zane Shelleycaee69f2019-12-05 13:42:58 -0600206 bool operator==(const OrRegister& r) const
207 {
208 return (r.iv_left == iv_left) && (r.iv_right == iv_right);
209 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500210
Zane Shelleycaee69f2019-12-05 13:42:58 -0600211 bool operator<(const OrRegister& r) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500212 {
213 if (iv_left == r.iv_left)
214 return iv_right < r.iv_right;
215 return iv_left < r.iv_left;
216 }
217
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500218 private:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600219 Register* iv_left;
220 Register* iv_right;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500221
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500222 BitStringBuffer iv_iBS;
223};
224
Zane Shelley23244cb2019-08-30 21:12:12 -0500225class ConstantRegister : public Register
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500226{
227 public:
Zane Shelleycaee69f2019-12-05 13:42:58 -0600228 ConstantRegister(const BitStringBuffer& i_arg) : Register(), iv_iBS(i_arg)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500229 {}
230
Zane Shelleycaee69f2019-12-05 13:42:58 -0600231 ConstantRegister& operator=(const ConstantRegister& r)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500232 {
233 iv_iBS = r.iv_iBS;
234 return *this;
235 }
236
Zane Shelleycaee69f2019-12-05 13:42:58 -0600237 const BitString* getBitString(const Chip& i_chip) const
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500238 {
239 return &iv_iBS;
240 }
241
Zane Shelleycaee69f2019-12-05 13:42:58 -0600242 bool operator==(const ConstantRegister& r) const
243 {
244 return r.iv_iBS == iv_iBS;
245 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500246
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500247 private:
248 BitStringBuffer iv_iBS;
249};
250
Zane Shelley871adec2019-07-30 11:01:39 -0500251} // end namespace libhei