Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_DEX_REG_STORAGE_H_ |
| 18 | #define ART_COMPILER_DEX_REG_STORAGE_H_ |
| 19 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 20 | #include "base/logging.h" |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | /* |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 25 | * 16-bit representation of the physical register container holding a Dalvik value. |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 26 | * The encoding allows up to 64 physical elements per storage class, and supports eight |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 27 | * register container shapes. |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 28 | * |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 29 | * [V] [HHHHH] [SSS] [F] [LLLLLL] |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 30 | * |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 31 | * [LLLLLL] |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 32 | * Physical register number for the low or solo register. |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 33 | * 0..63 |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 34 | * |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 35 | * [F] |
| 36 | * Describes type of the [LLLLL] register. |
| 37 | * 0: Core |
| 38 | * 1: Floating point |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 39 | * |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 40 | * [SSS] |
| 41 | * Shape of the register container. |
| 42 | * 000: Invalid |
| 43 | * 001: 32-bit solo register |
| 44 | * 010: 64-bit solo register |
| 45 | * 011: 64-bit pair consisting of two 32-bit solo registers |
| 46 | * 100: 128-bit solo register |
| 47 | * 101: 256-bit solo register |
| 48 | * 110: 512-bit solo register |
| 49 | * 111: 1024-bit solo register |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 50 | * |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 51 | * [HHHHH] |
| 52 | * Physical register number of the high register (valid only for register pair). |
| 53 | * 0..31 |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 54 | * |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 55 | * [V] |
| 56 | * 0 -> Invalid |
| 57 | * 1 -> Valid |
| 58 | * |
| 59 | * Note that in all non-invalid cases, we can determine if the storage is floating point |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 60 | * by testing bit 7. Note also that a register pair is effectively limited to a pair of |
| 61 | * physical register numbers in the 0..31 range. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 62 | * |
| 63 | * On some target architectures, the same underlying physical register container can be given |
| 64 | * different views. For example, Arm's 32-bit single-precision floating point registers |
| 65 | * s2 and s3 map to the low and high halves of double-precision d1. Similarly, X86's xmm3 |
| 66 | * vector register can be viewed as 32-bit, 64-bit, 128-bit, etc. In these cases the use of |
| 67 | * one view will affect the other views. The RegStorage class does not concern itself |
| 68 | * with potential aliasing. That will be done using the associated RegisterInfo struct. |
| 69 | * Distinct RegStorage elements should be created for each view of a physical register |
| 70 | * container. The management of the aliased physical elements will be handled via RegisterInfo |
| 71 | * records. |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 72 | */ |
| 73 | |
| 74 | class RegStorage { |
| 75 | public: |
| 76 | enum RegStorageKind { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 77 | kValidMask = 0x8000, |
| 78 | kValid = 0x8000, |
| 79 | kInvalid = 0x0000, |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 80 | kShapeMask = 0x0380, |
| 81 | k32BitSolo = 0x0080, |
| 82 | k64BitSolo = 0x0100, |
| 83 | k64BitPair = 0x0180, |
| 84 | k128BitSolo = 0x0200, |
| 85 | k256BitSolo = 0x0280, |
| 86 | k512BitSolo = 0x0300, |
| 87 | k1024BitSolo = 0x0380, |
| 88 | k64BitMask = 0x0300, |
| 89 | k64Bits = 0x0100, |
| 90 | kShapeTypeMask = 0x03c0, |
| 91 | kFloatingPoint = 0x0040, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 92 | kCoreRegister = 0x0000, |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 95 | static const uint16_t kRegValMask = 0x03ff; // Num, type and shape. |
| 96 | static const uint16_t kRegTypeMask = 0x007f; // Num and type. |
| 97 | static const uint16_t kRegNumMask = 0x003f; // Num only. |
| 98 | static const uint16_t kHighRegNumMask = 0x001f; // 0..31 for high reg |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 99 | static const uint16_t kMaxRegs = kRegValMask + 1; |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 100 | // TODO: deprecate use of kInvalidRegVal and speed up GetReg(). Rely on valid bit instead. |
| 101 | static const uint16_t kInvalidRegVal = 0x03ff; |
| 102 | static const uint16_t kHighRegShift = 10; |
| 103 | static const uint16_t kHighRegMask = (kHighRegNumMask << kHighRegShift); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 104 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 105 | // Reg is [F][LLLLL], will override any existing shape and use rs_kind. |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 106 | constexpr RegStorage(RegStorageKind rs_kind, int reg) |
| 107 | : reg_( |
| 108 | DCHECK_CONSTEXPR(rs_kind != k64BitPair, , 0u) |
| 109 | DCHECK_CONSTEXPR((rs_kind & ~kShapeMask) == 0, , 0u) |
| 110 | kValid | rs_kind | (reg & kRegTypeMask)) { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 111 | } |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 112 | constexpr RegStorage(RegStorageKind rs_kind, int low_reg, int high_reg) |
| 113 | : reg_( |
| 114 | DCHECK_CONSTEXPR(rs_kind == k64BitPair, << rs_kind, 0u) |
| 115 | DCHECK_CONSTEXPR((low_reg & kFloatingPoint) == (high_reg & kFloatingPoint), |
| 116 | << low_reg << ", " << high_reg, 0u) |
| 117 | DCHECK_CONSTEXPR((high_reg & kRegNumMask) <= kHighRegNumMask, |
| 118 | << "High reg must be in 0..31: " << high_reg, false) |
| 119 | kValid | rs_kind | ((high_reg & kHighRegNumMask) << kHighRegShift) | |
| 120 | (low_reg & kRegTypeMask)) { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 121 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 122 | constexpr explicit RegStorage(uint16_t val) : reg_(val) {} |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 123 | RegStorage() : reg_(kInvalid) {} |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 124 | |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame] | 125 | // We do not provide a general operator overload for equality of reg storage, as this is |
| 126 | // dangerous in the case of architectures with multiple views, and the naming ExactEquals |
| 127 | // expresses the exact match expressed here. It is more likely that a comparison between the views |
| 128 | // is intended in most cases. Such code can be found in, for example, Mir2Lir::IsSameReg. |
| 129 | // |
| 130 | // If you know what you are doing, include reg_storage_eq.h, which defines == and != for brevity. |
| 131 | |
| 132 | bool ExactlyEquals(const RegStorage& rhs) const { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 133 | return (reg_ == rhs.GetRawBits()); |
| 134 | } |
| 135 | |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame] | 136 | bool NotExactlyEquals(const RegStorage& rhs) const { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 137 | return (reg_ != rhs.GetRawBits()); |
| 138 | } |
| 139 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 140 | constexpr bool Valid() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 141 | return ((reg_ & kValidMask) == kValid); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 144 | constexpr bool Is32Bit() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 145 | return ((reg_ & kShapeMask) == k32BitSolo); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 146 | } |
| 147 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 148 | constexpr bool Is64Bit() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 149 | return ((reg_ & k64BitMask) == k64Bits); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 152 | constexpr bool Is64BitSolo() const { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 153 | return ((reg_ & kShapeMask) == k64BitSolo); |
| 154 | } |
| 155 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 156 | constexpr bool IsPair() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 157 | return ((reg_ & kShapeMask) == k64BitPair); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 160 | constexpr bool IsFloat() const { |
| 161 | return |
| 162 | DCHECK_CONSTEXPR(Valid(), , false) |
| 163 | ((reg_ & kFloatingPoint) == kFloatingPoint); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 166 | constexpr bool IsDouble() const { |
| 167 | return |
| 168 | DCHECK_CONSTEXPR(Valid(), , false) |
| 169 | (reg_ & (kFloatingPoint | k64BitMask)) == (kFloatingPoint | k64Bits); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 172 | constexpr bool IsSingle() const { |
| 173 | return |
| 174 | DCHECK_CONSTEXPR(Valid(), , false) |
| 175 | (reg_ & (kFloatingPoint | k64BitMask)) == kFloatingPoint; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 178 | static constexpr bool IsFloat(uint16_t reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 179 | return ((reg & kFloatingPoint) == kFloatingPoint); |
| 180 | } |
| 181 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 182 | static constexpr bool IsDouble(uint16_t reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 183 | return (reg & (kFloatingPoint | k64BitMask)) == (kFloatingPoint | k64Bits); |
| 184 | } |
| 185 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 186 | static constexpr bool IsSingle(uint16_t reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 187 | return (reg & (kFloatingPoint | k64BitMask)) == kFloatingPoint; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | // Used to retrieve either the low register of a pair, or the only register. |
| 191 | int GetReg() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 192 | DCHECK(!IsPair()) << "reg_ = 0x" << std::hex << reg_; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 193 | return Valid() ? (reg_ & kRegValMask) : kInvalidRegVal; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 194 | } |
| 195 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 196 | // Sets shape, type and num of solo. |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 197 | void SetReg(int reg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 198 | DCHECK(Valid()); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 199 | DCHECK(!IsPair()); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 200 | reg_ = (reg_ & ~kRegValMask) | reg; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 201 | } |
| 202 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 203 | // Set the reg number and type only, target remain 64-bit pair. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 204 | void SetLowReg(int reg) { |
| 205 | DCHECK(IsPair()); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 206 | reg_ = (reg_ & ~kRegTypeMask) | (reg & kRegTypeMask); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 207 | } |
| 208 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 209 | // Retrieve the least significant register of a pair and return as 32-bit solo. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 210 | int GetLowReg() const { |
| 211 | DCHECK(IsPair()); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 212 | return ((reg_ & kRegTypeMask) | k32BitSolo); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | // Create a stand-alone RegStorage from the low reg of a pair. |
| 216 | RegStorage GetLow() const { |
| 217 | DCHECK(IsPair()); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 218 | return RegStorage(k32BitSolo, reg_ & kRegTypeMask); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // Retrieve the most significant register of a pair. |
| 222 | int GetHighReg() const { |
| 223 | DCHECK(IsPair()); |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 224 | return k32BitSolo | ((reg_ & kHighRegMask) >> kHighRegShift) | (reg_ & kFloatingPoint); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 225 | } |
| 226 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 227 | // Create a stand-alone RegStorage from the high reg of a pair. |
| 228 | RegStorage GetHigh() const { |
| 229 | DCHECK(IsPair()); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 230 | return RegStorage(kValid | GetHighReg()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 233 | void SetHighReg(int reg) { |
| 234 | DCHECK(IsPair()); |
buzbee | d111c6e | 2014-05-11 21:09:53 -0700 | [diff] [blame] | 235 | reg_ = (reg_ & ~kHighRegMask) | ((reg & kHighRegNumMask) << kHighRegShift); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // Return the register number of low or solo. |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 239 | constexpr int GetRegNum() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 240 | return reg_ & kRegNumMask; |
| 241 | } |
| 242 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 243 | // Is register number in 0..7? |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 244 | constexpr bool Low8() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 245 | return GetRegNum() < 8; |
| 246 | } |
| 247 | |
| 248 | // Is register number in 0..3? |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 249 | constexpr bool Low4() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 250 | return GetRegNum() < 4; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 251 | } |
| 252 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 253 | // Combine 2 32-bit solo regs into a pair. |
| 254 | static RegStorage MakeRegPair(RegStorage low, RegStorage high) { |
| 255 | DCHECK(!low.IsPair()); |
| 256 | DCHECK(low.Is32Bit()); |
| 257 | DCHECK(!high.IsPair()); |
| 258 | DCHECK(high.Is32Bit()); |
| 259 | return RegStorage(k64BitPair, low.GetReg(), high.GetReg()); |
| 260 | } |
| 261 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 262 | static constexpr bool SameRegType(RegStorage reg1, RegStorage reg2) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 263 | return (reg1.IsDouble() == reg2.IsDouble()) && (reg1.IsSingle() == reg2.IsSingle()); |
| 264 | } |
| 265 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 266 | static constexpr bool SameRegType(int reg1, int reg2) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 267 | return (IsDouble(reg1) == IsDouble(reg2)) && (IsSingle(reg1) == IsSingle(reg2)); |
| 268 | } |
| 269 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 270 | // Create a 32-bit solo. |
| 271 | static RegStorage Solo32(int reg_num) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 272 | return RegStorage(k32BitSolo, reg_num & kRegTypeMask); |
| 273 | } |
| 274 | |
| 275 | // Create a floating point 32-bit solo. |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 276 | static constexpr RegStorage FloatSolo32(int reg_num) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 277 | return RegStorage(k32BitSolo, (reg_num & kRegNumMask) | kFloatingPoint); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 280 | // Create a 128-bit solo. |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 281 | static constexpr RegStorage Solo128(int reg_num) { |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 282 | return RegStorage(k128BitSolo, reg_num & kRegTypeMask); |
| 283 | } |
| 284 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 285 | // Create a 64-bit solo. |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 286 | static constexpr RegStorage Solo64(int reg_num) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 287 | return RegStorage(k64BitSolo, reg_num & kRegTypeMask); |
| 288 | } |
| 289 | |
| 290 | // Create a floating point 64-bit solo. |
| 291 | static RegStorage FloatSolo64(int reg_num) { |
| 292 | return RegStorage(k64BitSolo, (reg_num & kRegNumMask) | kFloatingPoint); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 295 | static constexpr RegStorage InvalidReg() { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 296 | return RegStorage(kInvalid); |
| 297 | } |
| 298 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 299 | static constexpr uint16_t RegNum(int raw_reg_bits) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 300 | return raw_reg_bits & kRegNumMask; |
| 301 | } |
| 302 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 303 | constexpr int GetRawBits() const { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 304 | return reg_; |
| 305 | } |
| 306 | |
Vladimir Marko | 8364248 | 2014-06-11 12:12:07 +0100 | [diff] [blame] | 307 | size_t StorageSize() const { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 308 | switch (reg_ & kShapeMask) { |
| 309 | case kInvalid: return 0; |
| 310 | case k32BitSolo: return 4; |
| 311 | case k64BitSolo: return 8; |
| 312 | case k64BitPair: return 8; // Is this useful? Might want to disallow taking size of pair. |
| 313 | case k128BitSolo: return 16; |
| 314 | case k256BitSolo: return 32; |
| 315 | case k512BitSolo: return 64; |
| 316 | case k1024BitSolo: return 128; |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 317 | default: LOG(FATAL) << "Unexpected shape"; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 318 | } |
| 319 | return 0; |
| 320 | } |
| 321 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 322 | private: |
| 323 | uint16_t reg_; |
| 324 | }; |
| 325 | |
| 326 | } // namespace art |
| 327 | |
| 328 | #endif // ART_COMPILER_DEX_REG_STORAGE_H_ |