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 | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 11 | NotRegister(Register& i_arg) : |
| 12 | Register(), iv_child(&i_arg), iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 13 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 14 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 15 | NotRegister& operator=(const NotRegister& r) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 16 | { |
| 17 | iv_child = r.iv_child; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 18 | iv_iBS = r.iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 19 | return *this; |
| 20 | } |
| 21 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 22 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 23 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 24 | const auto* bs = iv_child->getBitString(i_chip); |
| 25 | |
| 26 | (const_cast<NotRegister*>(this))->iv_iBS = ~(*bs); |
| 27 | |
| 28 | return &iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 29 | } |
| 30 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 31 | bool operator==(const NotRegister& r) const |
| 32 | { |
| 33 | return r.iv_child == iv_child; |
| 34 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 35 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 36 | bool operator<(const NotRegister& r) const |
| 37 | { |
| 38 | return iv_child < r.iv_child; |
| 39 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 40 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 41 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 42 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 43 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 44 | BitStringBuffer iv_iBS; |
| 45 | }; |
| 46 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 47 | class LeftShiftRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 48 | { |
| 49 | public: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 50 | LeftShiftRegister(Register& i_arg, uint16_t i_amount) : |
| 51 | Register(), iv_child(&i_arg), iv_amount(i_amount), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 52 | iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 53 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 54 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 55 | LeftShiftRegister& operator=(const LeftShiftRegister& r) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 56 | { |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 57 | iv_child = r.iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 58 | iv_amount = r.iv_amount; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 59 | iv_iBS = r.iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 60 | return *this; |
| 61 | } |
| 62 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 63 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 64 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 65 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 70 | } |
| 71 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 72 | bool operator==(const LeftShiftRegister& r) const |
| 73 | { |
| 74 | return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); |
| 75 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 76 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 77 | bool operator<(const LeftShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 78 | { |
| 79 | if (iv_child == r.iv_child) |
| 80 | return iv_amount < r.iv_amount; |
| 81 | return iv_child < r.iv_child; |
| 82 | } |
| 83 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 84 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 85 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 86 | uint16_t iv_amount; |
| 87 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 88 | BitStringBuffer iv_iBS; |
| 89 | }; |
| 90 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 91 | class RightShiftRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 92 | { |
| 93 | public: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 94 | RightShiftRegister(Register& i_arg, uint16_t i_amount) : |
| 95 | Register(), iv_child(&i_arg), iv_amount(i_amount), |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 96 | iv_iBS(i_arg.GetBitLength()) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 97 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 98 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 99 | RightShiftRegister& operator=(const RightShiftRegister& r) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 100 | { |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 101 | iv_child = r.iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 102 | iv_amount = r.iv_amount; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 103 | iv_iBS = r.iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 104 | return *this; |
| 105 | } |
| 106 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 107 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 108 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 109 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 116 | bool operator==(const RightShiftRegister& r) const |
| 117 | { |
| 118 | return (r.iv_child == iv_child) && (r.iv_amount == iv_amount); |
| 119 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 120 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 121 | bool operator<(const RightShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 122 | { |
| 123 | if (iv_child == r.iv_child) |
| 124 | return iv_amount < r.iv_amount; |
| 125 | return iv_child < r.iv_child; |
| 126 | } |
| 127 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 128 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 129 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 130 | uint16_t iv_amount; |
| 131 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 132 | BitStringBuffer iv_iBS; |
| 133 | }; |
| 134 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 135 | class AndRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 136 | { |
| 137 | public: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 138 | 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 Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 141 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 142 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 143 | AndRegister& operator=(const AndRegister& r) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 144 | { |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 145 | iv_left = r.iv_left; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 146 | iv_right = r.iv_right; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 147 | iv_iBS = r.iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 148 | return *this; |
| 149 | } |
| 150 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 151 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 152 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 153 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 159 | } |
| 160 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 161 | bool operator==(const AndRegister& r) const |
| 162 | { |
| 163 | return (r.iv_left == iv_left) && (r.iv_right == iv_right); |
| 164 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 165 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 166 | bool operator<(const AndRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 167 | { |
| 168 | if (iv_left == r.iv_left) |
| 169 | return iv_right < r.iv_right; |
| 170 | return iv_left < r.iv_left; |
| 171 | } |
| 172 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 173 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 174 | Register* iv_left; |
| 175 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 176 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 177 | BitStringBuffer iv_iBS; |
| 178 | }; |
| 179 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 180 | class OrRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 181 | { |
| 182 | public: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 183 | 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 Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 186 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 187 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 188 | OrRegister& operator=(const OrRegister& r) |
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 | iv_left = r.iv_left; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 191 | iv_right = r.iv_right; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 192 | iv_iBS = r.iv_iBS; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 193 | return *this; |
| 194 | } |
| 195 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 196 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 197 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame^] | 198 | 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 Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 206 | bool operator==(const OrRegister& r) const |
| 207 | { |
| 208 | return (r.iv_left == iv_left) && (r.iv_right == iv_right); |
| 209 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 210 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 211 | bool operator<(const OrRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 212 | { |
| 213 | if (iv_left == r.iv_left) |
| 214 | return iv_right < r.iv_right; |
| 215 | return iv_left < r.iv_left; |
| 216 | } |
| 217 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 218 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 219 | Register* iv_left; |
| 220 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 221 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 222 | BitStringBuffer iv_iBS; |
| 223 | }; |
| 224 | |
Zane Shelley | 23244cb | 2019-08-30 21:12:12 -0500 | [diff] [blame] | 225 | class ConstantRegister : public Register |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 226 | { |
| 227 | public: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 228 | ConstantRegister(const BitStringBuffer& i_arg) : Register(), iv_iBS(i_arg) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 229 | {} |
| 230 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 231 | ConstantRegister& operator=(const ConstantRegister& r) |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 232 | { |
| 233 | iv_iBS = r.iv_iBS; |
| 234 | return *this; |
| 235 | } |
| 236 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 237 | const BitString* getBitString(const Chip& i_chip) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 238 | { |
| 239 | return &iv_iBS; |
| 240 | } |
| 241 | |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 242 | bool operator==(const ConstantRegister& r) const |
| 243 | { |
| 244 | return r.iv_iBS == iv_iBS; |
| 245 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 246 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 247 | private: |
| 248 | BitStringBuffer iv_iBS; |
| 249 | }; |
| 250 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 251 | } // end namespace libhei |