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