Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 1 | #pragma once |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 2 | |
Zane Shelley | 52cb1a9 | 2019-08-21 14:38:31 -0500 | [diff] [blame] | 3 | #include <register/hei_register.hpp> |
| 4 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 5 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 6 | { |
| 7 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 8 | class NotRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 9 | { |
| 10 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 11 | /** |
| 12 | * @brief Constructor from components. |
| 13 | * @param i_arg Target register for operation. |
| 14 | */ |
| 15 | explicit NotRegister(Register& i_arg) : |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 16 | Register(), iv_child(&i_arg), iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 17 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 18 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 19 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 27 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 28 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 29 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 30 | const auto* bs = iv_child->getBitString(i_chip); |
| 31 | |
| 32 | (const_cast<NotRegister*>(this))->iv_iBS = ~(*bs); |
| 33 | |
| 34 | return &iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 37 | bool operator==(const NotRegister& r) const |
| 38 | { |
| 39 | return r.iv_child == iv_child; |
| 40 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 41 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 42 | bool operator<(const NotRegister& r) const |
| 43 | { |
| 44 | return iv_child < r.iv_child; |
| 45 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 46 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 47 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 48 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 49 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 50 | BitStringBuffer iv_iBS; |
| 51 | }; |
| 52 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 53 | class LeftShiftRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 54 | { |
| 55 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 56 | /** |
| 57 | * @brief Constructor from components. |
| 58 | * @param i_arg Target register for operation. |
| 59 | * @param i_amount The shift value. |
| 60 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 61 | LeftShiftRegister(Register& i_arg, uint16_t i_amount) : |
| 62 | Register(), iv_child(&i_arg), iv_amount(i_amount), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 63 | iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 64 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 65 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 66 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 74 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 75 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 76 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 77 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 84 | bool operator==(const LeftShiftRegister& r) const |
| 85 | { |
| 86 | return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); |
| 87 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 88 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 89 | bool operator<(const LeftShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 90 | { |
| 91 | if (iv_child == r.iv_child) |
| 92 | return iv_amount < r.iv_amount; |
| 93 | return iv_child < r.iv_child; |
| 94 | } |
| 95 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 96 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 97 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 98 | uint16_t iv_amount; |
| 99 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 100 | BitStringBuffer iv_iBS; |
| 101 | }; |
| 102 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 103 | class RightShiftRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 104 | { |
| 105 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 106 | /** |
| 107 | * @brief Constructor from components. |
| 108 | * @param i_arg Target register for operation. |
| 109 | * @param i_amount The shift value. |
| 110 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 111 | RightShiftRegister(Register& i_arg, uint16_t i_amount) : |
| 112 | Register(), iv_child(&i_arg), iv_amount(i_amount), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 113 | iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 114 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 115 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 116 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 124 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 125 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 126 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 127 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 134 | bool operator==(const RightShiftRegister& r) const |
| 135 | { |
| 136 | return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); |
| 137 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 138 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 139 | bool operator<(const RightShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 140 | { |
| 141 | if (iv_child == r.iv_child) |
| 142 | return iv_amount < r.iv_amount; |
| 143 | return iv_child < r.iv_child; |
| 144 | } |
| 145 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 146 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 147 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 148 | uint16_t iv_amount; |
| 149 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 150 | BitStringBuffer iv_iBS; |
| 151 | }; |
| 152 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 153 | class AndRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 154 | { |
| 155 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 156 | /** |
| 157 | * @brief Constructor from components. |
| 158 | * @param i_left Target register for operation. |
| 159 | * @param i_right Target register for operation. |
| 160 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 161 | 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 Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 164 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 165 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 166 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 174 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 175 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 176 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 177 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 185 | bool operator==(const AndRegister& r) const |
| 186 | { |
| 187 | return (r.iv_left == iv_left) && (r.iv_right == iv_right); |
| 188 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 189 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 190 | bool operator<(const AndRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 191 | { |
| 192 | if (iv_left == r.iv_left) |
| 193 | return iv_right < r.iv_right; |
| 194 | return iv_left < r.iv_left; |
| 195 | } |
| 196 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 197 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 198 | Register* iv_left; |
| 199 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 200 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 201 | BitStringBuffer iv_iBS; |
| 202 | }; |
| 203 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 204 | class OrRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 205 | { |
| 206 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 207 | /** |
| 208 | * @brief Constructor from components. |
| 209 | * @param i_left Target register for operation. |
| 210 | * @param i_right Target register for operation. |
| 211 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 212 | 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 Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 215 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 216 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 217 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 225 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 226 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 227 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 228 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 234 | } |
| 235 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 236 | bool operator==(const OrRegister& r) const |
| 237 | { |
| 238 | return (r.iv_left == iv_left) && (r.iv_right == iv_right); |
| 239 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 240 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 241 | bool operator<(const OrRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 242 | { |
| 243 | if (iv_left == r.iv_left) |
| 244 | return iv_right < r.iv_right; |
| 245 | return iv_left < r.iv_left; |
| 246 | } |
| 247 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 248 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 249 | Register* iv_left; |
| 250 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 251 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 252 | BitStringBuffer iv_iBS; |
| 253 | }; |
| 254 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 255 | class ConstantRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 256 | { |
| 257 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 258 | /** |
| 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 264 | {} |
| 265 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame^] | 266 | /** @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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 274 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 275 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 276 | { |
| 277 | return &iv_iBS; |
| 278 | } |
| 279 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 280 | bool operator==(const ConstantRegister& r) const |
| 281 | { |
| 282 | return r.iv_iBS == iv_iBS; |
| 283 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 284 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 285 | private: |
| 286 | BitStringBuffer iv_iBS; |
| 287 | }; |
| 288 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 289 | } // end namespace libhei |