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