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 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 5 | /** |
| 6 | * @file hei_operator_register.hpp |
| 7 | * |
| 8 | * A library of useful classes used to perform logical or bitwise math on or |
| 9 | * between other registers. The classes implemented here include NotRegister, |
| 10 | * LeftShiftRegister, RightShiftRegister, AndRegister, OrRegister, and |
| 11 | * ConstantRegister. |
| 12 | * |
| 13 | * Accompanied with other Register classes and the getBitString() function, it |
| 14 | * is possible to perform operations like: |
| 15 | * |
| 16 | * AndRegister reg{<register1>,<register2>}; |
| 17 | * result = reg.getBitString(<someChip>); |
| 18 | * |
| 19 | * This example will return a BitString containing the result of the bitwise |
| 20 | * AND operation applied to register1 and register2. |
| 21 | */ |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 22 | namespace libhei |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 23 | { |
| 24 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 25 | /** |
| 26 | * @brief An abstract class for all operator registers. |
| 27 | * |
| 28 | * Contains member functions and variables that are required for all child |
| 29 | * classes. |
| 30 | */ |
| 31 | class OperatorRegister : public Register |
| 32 | { |
| 33 | public: |
| 34 | /** @brief Pure virtual destructor. */ |
| 35 | virtual ~OperatorRegister() = 0; |
| 36 | |
| 37 | protected: |
| 38 | /** |
| 39 | * @brief Constructor from components. |
| 40 | * @param i_size Size (in bytes) of this register. |
| 41 | */ |
| 42 | explicit OperatorRegister(size_t i_size) : Register(), iv_result(i_size * 8) |
| 43 | {} |
| 44 | |
| 45 | protected: // Instance variables |
| 46 | /** When getBitString() is called on an operator, the resulting value of the |
| 47 | * operation will be stored in this instance variable. */ |
| 48 | BitStringBuffer iv_result; |
| 49 | |
| 50 | public: |
| 51 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 52 | size_t getSize() const override |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 53 | { |
| 54 | return (BitString::getMinBytes(iv_result.getBitLen())); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | // Pure virtual destructor must be defined. |
| 59 | inline OperatorRegister::~OperatorRegister() {} |
| 60 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 61 | /** |
| 62 | * @brief Using getBitString(), performs a bitwise NOT operation on a register. |
| 63 | * |
| 64 | * Example: |
| 65 | * NotRegister reg{someRegister}; |
| 66 | * result = reg.getBitString(someChip); |
| 67 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 68 | class NotRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 69 | { |
| 70 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 71 | /** |
| 72 | * @brief Constructor from components. |
| 73 | * @param i_arg Target register for operation. |
| 74 | */ |
| 75 | explicit NotRegister(Register& i_arg) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 76 | OperatorRegister(i_arg.getSize()), iv_child(&i_arg) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 77 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 78 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 79 | /** @brief Default destructor. */ |
| 80 | ~NotRegister() = default; |
| 81 | |
| 82 | /** @brief Default copy constructor. */ |
| 83 | NotRegister(const NotRegister&) = default; |
| 84 | |
| 85 | /** @brief Default assignment operator. */ |
| 86 | NotRegister& operator=(const NotRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 87 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 88 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 89 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 90 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 91 | const auto* bs = iv_child->getBitString(i_chip); |
| 92 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 93 | (const_cast<NotRegister*>(this))->iv_result = ~(*bs); |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 94 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 95 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 98 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 99 | bool operator==(const NotRegister& r) const |
| 100 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 101 | return iv_child == r.iv_child; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 102 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 103 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 104 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 105 | bool operator<(const NotRegister& r) const |
| 106 | { |
| 107 | return iv_child < r.iv_child; |
| 108 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 109 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 110 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 111 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 112 | }; |
| 113 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 114 | /** |
| 115 | * @brief Using getBitString(), performs a left shift operation on a register. |
| 116 | * |
| 117 | * Example: |
| 118 | * LeftShiftRegister reg{someRegister1, shiftValue}; |
| 119 | * result = reg.getBitString(someChip); |
| 120 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 121 | class LeftShiftRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 122 | { |
| 123 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 124 | /** |
| 125 | * @brief Constructor from components. |
| 126 | * @param i_arg Target register for operation. |
| 127 | * @param i_amount The shift value. |
| 128 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 129 | LeftShiftRegister(Register& i_arg, uint16_t i_amount) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 130 | OperatorRegister(i_arg.getSize()), iv_child(&i_arg), iv_amount(i_amount) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 131 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 132 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 133 | /** @brief Default destructor. */ |
| 134 | ~LeftShiftRegister() = default; |
| 135 | |
| 136 | /** @brief Default copy constructor. */ |
| 137 | LeftShiftRegister(const LeftShiftRegister&) = default; |
| 138 | |
| 139 | /** @brief Default assignment operator. */ |
| 140 | LeftShiftRegister& operator=(const LeftShiftRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 141 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 142 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 143 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 144 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 145 | const auto* bs = iv_child->getBitString(i_chip); |
| 146 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 147 | (const_cast<LeftShiftRegister*>(this))->iv_result = (*bs) << iv_amount; |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 148 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 149 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 150 | } |
| 151 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 152 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 153 | bool operator==(const LeftShiftRegister& r) const |
| 154 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 155 | return (iv_child == r.iv_child) && (iv_amount == r.iv_amount); |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 156 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 157 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 158 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 159 | bool operator<(const LeftShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 160 | { |
| 161 | if (iv_child == r.iv_child) |
| 162 | return iv_amount < r.iv_amount; |
| 163 | return iv_child < r.iv_child; |
| 164 | } |
| 165 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 166 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 167 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 168 | uint16_t iv_amount; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 169 | }; |
| 170 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 171 | /** |
| 172 | * @brief Using getBitString(), performs a right shift operation on a register. |
| 173 | * |
| 174 | * Example: |
| 175 | * RightShiftRegister reg{someRegister1, shiftValue}; |
| 176 | * result = reg.getBitString(someChip); |
| 177 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 178 | class RightShiftRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 179 | { |
| 180 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 181 | /** |
| 182 | * @brief Constructor from components. |
| 183 | * @param i_arg Target register for operation. |
| 184 | * @param i_amount The shift value. |
| 185 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 186 | RightShiftRegister(Register& i_arg, uint16_t i_amount) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 187 | OperatorRegister(i_arg.getSize()), iv_child(&i_arg), iv_amount(i_amount) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 188 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 189 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 190 | /** @brief Default destructor. */ |
| 191 | ~RightShiftRegister() = default; |
| 192 | |
| 193 | /** @brief Default copy constructor. */ |
| 194 | RightShiftRegister(const RightShiftRegister&) = default; |
| 195 | |
| 196 | /** @brief Default assignment operator. */ |
| 197 | RightShiftRegister& operator=(const RightShiftRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 198 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 199 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 200 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 201 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 202 | const auto* bs = iv_child->getBitString(i_chip); |
| 203 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 204 | (const_cast<RightShiftRegister*>(this))->iv_result = (*bs) >> iv_amount; |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 205 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 206 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 209 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 210 | bool operator==(const RightShiftRegister& r) const |
| 211 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 212 | return (iv_child == r.iv_child) && (iv_amount == r.iv_amount); |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 213 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 214 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 215 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 216 | bool operator<(const RightShiftRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 217 | { |
| 218 | if (iv_child == r.iv_child) |
| 219 | return iv_amount < r.iv_amount; |
| 220 | return iv_child < r.iv_child; |
| 221 | } |
| 222 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 223 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 224 | Register* iv_child; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 225 | uint16_t iv_amount; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 226 | }; |
| 227 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 228 | /** |
| 229 | * @brief Using getBitString(), performs a bitwise AND operation on a pair |
| 230 | * of registers. |
| 231 | * |
| 232 | * Example: |
| 233 | * AndRegister reg{someRegister1, someRegister2}; |
| 234 | * result = reg.getBitString(someChip); |
| 235 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 236 | class AndRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 237 | { |
| 238 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 239 | /** |
| 240 | * @brief Constructor from components. |
| 241 | * @param i_left Target register for operation. |
| 242 | * @param i_right Target register for operation. |
| 243 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 244 | AndRegister(Register& i_left, Register& i_right) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 245 | OperatorRegister(std::min(i_left.getSize(), i_right.getSize())), |
| 246 | iv_left(&i_left), iv_right(&i_right) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 247 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 248 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 249 | /** @brief Default destructor. */ |
| 250 | ~AndRegister() = default; |
| 251 | |
| 252 | /** @brief Default copy constructor. */ |
| 253 | AndRegister(const AndRegister&) = default; |
| 254 | |
| 255 | /** @brief Default assignment operator. */ |
| 256 | AndRegister& operator=(const AndRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 257 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 258 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 259 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 260 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 261 | const auto* l_bs = iv_left->getBitString(i_chip); |
| 262 | const auto* r_bs = iv_right->getBitString(i_chip); |
| 263 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 264 | (const_cast<AndRegister*>(this))->iv_result = (*l_bs) & (*r_bs); |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 265 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 266 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 267 | } |
| 268 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 269 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 270 | bool operator==(const AndRegister& r) const |
| 271 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 272 | return (iv_left == r.iv_left) && (iv_right == r.iv_right); |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 273 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 274 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 275 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 276 | bool operator<(const AndRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 277 | { |
| 278 | if (iv_left == r.iv_left) |
| 279 | return iv_right < r.iv_right; |
| 280 | return iv_left < r.iv_left; |
| 281 | } |
| 282 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 283 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 284 | Register* iv_left; |
| 285 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 286 | }; |
| 287 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 288 | /** |
| 289 | * @brief Using getBitString(), performs a bitwise OR operation on a pair |
| 290 | * of registers. |
| 291 | * |
| 292 | * Example: |
| 293 | * OrRegister reg{someRegister1, someRegister2}; |
| 294 | * result = reg.getBitString(someChip); |
| 295 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 296 | class OrRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 297 | { |
| 298 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 299 | /** |
| 300 | * @brief Constructor from components. |
| 301 | * @param i_left Target register for operation. |
| 302 | * @param i_right Target register for operation. |
| 303 | */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 304 | OrRegister(Register& i_left, Register& i_right) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 305 | OperatorRegister(std::min(i_left.getSize(), i_right.getSize())), |
| 306 | iv_left(&i_left), iv_right(&i_right) |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 307 | {} |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 308 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 309 | /** @brief Default destructor. */ |
| 310 | ~OrRegister() = default; |
| 311 | |
| 312 | /** @brief Default copy constructor. */ |
| 313 | OrRegister(const OrRegister&) = default; |
| 314 | |
| 315 | /** @brief Default assignment operator. */ |
| 316 | OrRegister& operator=(const OrRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 317 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 318 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 319 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 320 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 321 | const auto* l_bs = iv_left->getBitString(i_chip); |
| 322 | const auto* r_bs = iv_right->getBitString(i_chip); |
| 323 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 324 | (const_cast<OrRegister*>(this))->iv_result = (*l_bs) | (*r_bs); |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 325 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 326 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 329 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 330 | bool operator==(const OrRegister& r) const |
| 331 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 332 | return (iv_left == r.iv_left) && (iv_right == r.iv_right); |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 333 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 334 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 335 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 336 | bool operator<(const OrRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 337 | { |
| 338 | if (iv_left == r.iv_left) |
| 339 | return iv_right < r.iv_right; |
| 340 | return iv_left < r.iv_left; |
| 341 | } |
| 342 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 343 | private: |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 344 | Register* iv_left; |
| 345 | Register* iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 346 | }; |
| 347 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 348 | /** |
| 349 | * @brief Contains a constant value that can be used within any of the other |
| 350 | * register operators. The value can be retrieved using the |
| 351 | * getBitString() function. |
| 352 | **/ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 353 | class ConstantRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 354 | { |
| 355 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 356 | /** |
| 357 | * @brief Constructor from components. |
| 358 | * @param i_arg A BitStringBuffer containing the constant value. |
| 359 | */ |
| 360 | explicit ConstantRegister(const BitStringBuffer& i_arg) : |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 361 | OperatorRegister(BitString::getMinBytes(i_arg.getBitLen())) |
| 362 | { |
| 363 | iv_result = i_arg; |
| 364 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 365 | |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 366 | /** @brief Default destructor. */ |
| 367 | ~ConstantRegister() = default; |
| 368 | |
| 369 | /** @brief Default copy constructor. */ |
| 370 | ConstantRegister(const ConstantRegister&) = default; |
| 371 | |
| 372 | /** @brief Default assignment operator. */ |
| 373 | ConstantRegister& operator=(const ConstantRegister& r) = default; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 374 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 375 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame^] | 376 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 377 | { |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 378 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 379 | } |
| 380 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 381 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 382 | bool operator==(const ConstantRegister& r) const |
| 383 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 384 | return iv_result == r.iv_result; |
| 385 | } |
| 386 | |
| 387 | /** @brief Less-than operator. */ |
| 388 | bool operator<(const ConstantRegister& r) const |
| 389 | { |
| 390 | return iv_result < r.iv_result; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 391 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 392 | }; |
| 393 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 394 | } // end namespace libhei |