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 | */ |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 75 | explicit NotRegister(Register::ConstPtr i_arg) : |
| 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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 79 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 80 | ~NotRegister() = default; |
| 81 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 82 | /** @brief Copy constructor. */ |
| 83 | NotRegister(const NotRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 84 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 85 | /** @brief Assignment operator. */ |
| 86 | NotRegister& operator=(const NotRegister& r) = delete; |
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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 111 | const Register::ConstPtr 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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 129 | LeftShiftRegister(Register::ConstPtr i_arg, size_t i_amount) : |
| 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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 133 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 134 | ~LeftShiftRegister() = default; |
| 135 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 136 | /** @brief Copy constructor. */ |
| 137 | LeftShiftRegister(const LeftShiftRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 138 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 139 | /** @brief Assignment operator. */ |
| 140 | LeftShiftRegister& operator=(const LeftShiftRegister& r) = delete; |
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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 167 | const Register::ConstPtr iv_child; |
| 168 | const size_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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 186 | RightShiftRegister(Register::ConstPtr i_arg, size_t i_amount) : |
| 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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 190 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 191 | ~RightShiftRegister() = default; |
| 192 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 193 | /** @brief Copy constructor. */ |
| 194 | RightShiftRegister(const RightShiftRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 195 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 196 | /** @brief Assignment operator. */ |
| 197 | RightShiftRegister& operator=(const RightShiftRegister& r) = delete; |
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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 224 | const Register::ConstPtr iv_child; |
| 225 | const size_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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 244 | AndRegister(Register::ConstPtr i_left, Register::ConstPtr i_right) : |
| 245 | OperatorRegister(i_left->getSize()), iv_left(i_left), iv_right(i_right) |
| 246 | { |
| 247 | // The two registers must be the same sizes or it makes for some weird |
| 248 | // results. |
| 249 | HEI_ASSERT(iv_left->getSize() == iv_right->getSize()); |
| 250 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 251 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 252 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 253 | ~AndRegister() = default; |
| 254 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 255 | /** @brief Copy constructor. */ |
| 256 | AndRegister(const AndRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 257 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 258 | /** @brief Assignment operator. */ |
| 259 | AndRegister& operator=(const AndRegister& r) = delete; |
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 | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame] | 262 | const BitString* getBitString(const Chip& i_chip) const override |
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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 287 | const Register::ConstPtr iv_left; |
| 288 | const Register::ConstPtr 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 | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 307 | OrRegister(Register::ConstPtr i_left, Register::ConstPtr i_right) : |
| 308 | OperatorRegister(i_left->getSize()), iv_left(i_left), iv_right(i_right) |
| 309 | { |
| 310 | // The two registers must be the same sizes or it makes for some weird |
| 311 | // results. |
| 312 | HEI_ASSERT(iv_left->getSize() == iv_right->getSize()); |
| 313 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 314 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 315 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 316 | ~OrRegister() = default; |
| 317 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 318 | /** @brief Copy constructor. */ |
| 319 | OrRegister(const OrRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 320 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 321 | /** @brief Assignment operator. */ |
| 322 | OrRegister& operator=(const OrRegister& r) = delete; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 323 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 324 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame] | 325 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 326 | { |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 327 | const auto* l_bs = iv_left->getBitString(i_chip); |
| 328 | const auto* r_bs = iv_right->getBitString(i_chip); |
| 329 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 330 | (const_cast<OrRegister*>(this))->iv_result = (*l_bs) | (*r_bs); |
Zane Shelley | d4c0e98 | 2019-12-05 21:27:41 -0600 | [diff] [blame] | 331 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 332 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 333 | } |
| 334 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 335 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 336 | bool operator==(const OrRegister& r) const |
| 337 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 338 | return (iv_left == r.iv_left) && (iv_right == r.iv_right); |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 339 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 340 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 341 | /** @brief Less-than operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 342 | bool operator<(const OrRegister& r) const |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 343 | { |
| 344 | if (iv_left == r.iv_left) |
| 345 | return iv_right < r.iv_right; |
| 346 | return iv_left < r.iv_left; |
| 347 | } |
| 348 | |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 349 | private: |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 350 | const Register::ConstPtr iv_left; |
| 351 | const Register::ConstPtr iv_right; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 352 | }; |
| 353 | |
Paul Greenwood | dc47e0a | 2019-11-01 16:22:57 -0500 | [diff] [blame] | 354 | /** |
| 355 | * @brief Contains a constant value that can be used within any of the other |
| 356 | * register operators. The value can be retrieved using the |
| 357 | * getBitString() function. |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 358 | */ |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 359 | class ConstantRegister : public OperatorRegister |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 360 | { |
| 361 | public: |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 362 | /** |
| 363 | * @brief Constructor from components. |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 364 | * @param i_val An unsigned integer value. iv_result will be initialized to |
| 365 | * the size of type T and this value will be copied into that |
| 366 | * buffer. |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 367 | */ |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 368 | template <class T> |
| 369 | explicit ConstantRegister(T i_val) : OperatorRegister(sizeof(i_val)) |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 370 | { |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 371 | iv_result.setFieldRight(0, iv_result.getBitLen(), i_val); |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 372 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 373 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 374 | /** @brief Destructor. */ |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 375 | ~ConstantRegister() = default; |
| 376 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 377 | /** @brief Copy constructor. */ |
| 378 | ConstantRegister(const ConstantRegister&) = delete; |
Zane Shelley | 48aa860 | 2019-12-05 21:41:21 -0600 | [diff] [blame] | 379 | |
Zane Shelley | 6eb6190 | 2020-05-15 22:25:58 -0500 | [diff] [blame] | 380 | /** @brief Assignment operator. */ |
| 381 | ConstantRegister& operator=(const ConstantRegister& r) = delete; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 382 | |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 383 | /** @brief Overloaded from parent class. */ |
Zane Shelley | d065924 | 2020-05-15 23:02:29 -0500 | [diff] [blame] | 384 | const BitString* getBitString(const Chip& i_chip) const override |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 385 | { |
Zane Shelley | b0559b9 | 2019-12-05 22:18:20 -0600 | [diff] [blame] | 386 | return &iv_result; |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 387 | } |
| 388 | |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 389 | /** @brief Comparison operator. */ |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 390 | bool operator==(const ConstantRegister& r) const |
| 391 | { |
Zane Shelley | ec06f82 | 2019-12-05 22:23:19 -0600 | [diff] [blame] | 392 | return iv_result == r.iv_result; |
| 393 | } |
| 394 | |
| 395 | /** @brief Less-than operator. */ |
| 396 | bool operator<(const ConstantRegister& r) const |
| 397 | { |
| 398 | return iv_result < r.iv_result; |
Zane Shelley | caee69f | 2019-12-05 13:42:58 -0600 | [diff] [blame] | 399 | } |
Zane Shelley | fd3f9cc | 2019-07-29 15:02:24 -0500 | [diff] [blame] | 400 | }; |
| 401 | |
Zane Shelley | 871adec | 2019-07-30 11:01:39 -0500 | [diff] [blame] | 402 | } // end namespace libhei |