Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_ |
| 18 | #define ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include "dex/compiler_internals.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | /* |
| 25 | * Runtime register conventions. |
| 26 | * |
| 27 | * zero is always the value 0 |
| 28 | * at is scratch (normally used as temp reg by assembler) |
| 29 | * v0, v1 are scratch (normally hold subroutine return values) |
| 30 | * a0-a3 are scratch (normally hold subroutine arguments) |
| 31 | * t0-t8 are scratch |
| 32 | * t9 is scratch (normally used for function calls) |
| 33 | * s0 (rMIPS_SUSPEND) is reserved [holds suspend-check counter] |
| 34 | * s1 (rMIPS_SELF) is reserved [holds current &Thread] |
| 35 | * s2-s7 are callee save (promotion target) |
| 36 | * k0, k1 are reserved for use by interrupt handlers |
| 37 | * gp is reserved for global pointer |
| 38 | * sp is reserved |
| 39 | * s8 is callee save (promotion target) |
| 40 | * ra is scratch (normally holds the return addr) |
| 41 | * |
| 42 | * Preserved across C calls: s0-s8 |
| 43 | * Trashed across C calls: at, v0-v1, a0-a3, t0-t9, gp, ra |
| 44 | * |
| 45 | * Floating pointer registers |
| 46 | * NOTE: there are 32 fp registers (16 df pairs), but currently |
| 47 | * only support 16 fp registers (8 df pairs). |
| 48 | * f0-f15 |
| 49 | * df0-df7, where df0={f0,f1}, df1={f2,f3}, ... , df7={f14,f15} |
| 50 | * |
| 51 | * f0-f15 (df0-df7) trashed across C calls |
| 52 | * |
| 53 | * For mips32 code use: |
| 54 | * a0-a3 to hold operands |
| 55 | * v0-v1 to hold results |
| 56 | * t0-t9 for temps |
| 57 | * |
| 58 | * All jump/branch instructions have a delay slot after it. |
| 59 | * |
| 60 | * Stack frame diagram (stack grows down, higher addresses at top): |
| 61 | * |
| 62 | * +------------------------+ |
| 63 | * | IN[ins-1] | {Note: resides in caller's frame} |
| 64 | * | . | |
| 65 | * | IN[0] | |
| 66 | * | caller's Method* | |
| 67 | * +========================+ {Note: start of callee's frame} |
| 68 | * | spill region | {variable sized - will include lr if non-leaf.} |
| 69 | * +------------------------+ |
| 70 | * | ...filler word... | {Note: used as 2nd word of V[locals-1] if long] |
| 71 | * +------------------------+ |
| 72 | * | V[locals-1] | |
| 73 | * | V[locals-2] | |
| 74 | * | . | |
| 75 | * | . | |
| 76 | * | V[1] | |
| 77 | * | V[0] | |
| 78 | * +------------------------+ |
| 79 | * | 0 to 3 words padding | |
| 80 | * +------------------------+ |
| 81 | * | OUT[outs-1] | |
| 82 | * | OUT[outs-2] | |
| 83 | * | . | |
| 84 | * | OUT[0] | |
| 85 | * | cur_method* | <<== sp w/ 16-byte alignment |
| 86 | * +========================+ |
| 87 | */ |
| 88 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 89 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 90 | #define LOWORD_OFFSET 0 |
| 91 | #define HIWORD_OFFSET 4 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 92 | #define rARG0 rA0 |
| 93 | #define rs_rARG0 rs_rA0 |
| 94 | #define rARG1 rA1 |
| 95 | #define rs_rARG1 rs_rA1 |
| 96 | #define rARG2 rA2 |
| 97 | #define rs_rARG2 rs_rA2 |
| 98 | #define rARG3 rA3 |
| 99 | #define rs_rARG3 rs_rA3 |
| 100 | #define rRESULT0 rV0 |
| 101 | #define rs_rRESULT0 rs_rV0 |
| 102 | #define rRESULT1 rV1 |
| 103 | #define rs_rRESULT1 rs_rV1 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 104 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 105 | #define rFARG0 rF12 |
| 106 | #define rs_rFARG0 rs_rF12 |
| 107 | #define rFARG1 rF13 |
| 108 | #define rs_rFARG1 rs_rF13 |
| 109 | #define rFARG2 rF14 |
| 110 | #define rs_rFARG2 rs_rF14 |
| 111 | #define rFARG3 rF15 |
| 112 | #define rs_rFARG3 rs_rF15 |
| 113 | #define rFRESULT0 rF0 |
| 114 | #define rs_rFRESULT0 rs_rF0 |
| 115 | #define rFRESULT1 rF1 |
| 116 | #define rs_rFRESULT1 rs_rF1 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 117 | |
| 118 | // Regs not used for Mips. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 119 | #define rMIPS_LR RegStorage::kInvalidRegVal |
| 120 | #define rMIPS_PC RegStorage::kInvalidRegVal |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 121 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 122 | enum MipsResourceEncodingPos { |
| 123 | kMipsGPReg0 = 0, |
| 124 | kMipsRegSP = 29, |
| 125 | kMipsRegLR = 31, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 126 | kMipsFPReg0 = 32, // only 16 fp regs supported currently. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 127 | kMipsFPRegEnd = 48, |
| 128 | kMipsRegHI = kMipsFPRegEnd, |
| 129 | kMipsRegLO, |
| 130 | kMipsRegPC, |
| 131 | kMipsRegEnd = 51, |
| 132 | }; |
| 133 | |
| 134 | #define ENCODE_MIPS_REG_LIST(N) (static_cast<uint64_t>(N)) |
| 135 | #define ENCODE_MIPS_REG_SP (1ULL << kMipsRegSP) |
| 136 | #define ENCODE_MIPS_REG_LR (1ULL << kMipsRegLR) |
| 137 | #define ENCODE_MIPS_REG_PC (1ULL << kMipsRegPC) |
buzbee | 9da5c10 | 2014-03-28 12:59:18 -0700 | [diff] [blame] | 138 | #define ENCODE_MIPS_REG_HI (1ULL << kMipsRegHI) |
| 139 | #define ENCODE_MIPS_REG_LO (1ULL << kMipsRegLO) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 140 | |
| 141 | enum MipsNativeRegisterPool { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 142 | rZERO = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 0, |
| 143 | rAT = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 1, |
| 144 | rV0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 2, |
| 145 | rV1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 3, |
| 146 | rA0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 4, |
| 147 | rA1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 5, |
| 148 | rA2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 6, |
| 149 | rA3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 7, |
| 150 | rT0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 8, |
| 151 | rT1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 9, |
| 152 | rT2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 10, |
| 153 | rT3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 11, |
| 154 | rT4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 12, |
| 155 | rT5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 13, |
| 156 | rT6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 14, |
| 157 | rT7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 15, |
| 158 | rS0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 16, |
| 159 | rS1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 17, |
| 160 | rS2 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 18, |
| 161 | rS3 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 19, |
| 162 | rS4 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 20, |
| 163 | rS5 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 21, |
| 164 | rS6 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 22, |
| 165 | rS7 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 23, |
| 166 | rT8 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 24, |
| 167 | rT9 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 25, |
| 168 | rK0 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 26, |
| 169 | rK1 = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 27, |
| 170 | rGP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 28, |
| 171 | rSP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 29, |
| 172 | rFP = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 30, |
| 173 | rRA = RegStorage::k32BitSolo | RegStorage::kCoreRegister | 31, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 174 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 175 | rF0 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 0, |
| 176 | rF1 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 1, |
| 177 | rF2 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 2, |
| 178 | rF3 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 3, |
| 179 | rF4 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 4, |
| 180 | rF5 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 5, |
| 181 | rF6 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 6, |
| 182 | rF7 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 7, |
| 183 | rF8 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 8, |
| 184 | rF9 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 9, |
| 185 | rF10 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 10, |
| 186 | rF11 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 11, |
| 187 | rF12 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 12, |
| 188 | rF13 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 13, |
| 189 | rF14 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 14, |
| 190 | rF15 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 15, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 191 | #if 0 |
| 192 | /* |
| 193 | * TODO: The shared resource mask doesn't have enough bit positions to describe all |
| 194 | * MIPS registers. Expand it and enable use of fp registers 16 through 31. |
| 195 | */ |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 196 | rF16 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 16, |
| 197 | rF17 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 17, |
| 198 | rF18 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 18, |
| 199 | rF19 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 19, |
| 200 | rF20 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 20, |
| 201 | rF21 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 21, |
| 202 | rF22 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 22, |
| 203 | rF23 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 23, |
| 204 | rF24 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 24, |
| 205 | rF25 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 25, |
| 206 | rF26 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 26, |
| 207 | rF27 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 27, |
| 208 | rF28 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 28, |
| 209 | rF29 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 29, |
| 210 | rF30 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 30, |
| 211 | rF31 = RegStorage::k32BitSolo | RegStorage::kFloatingPoint | 31, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 212 | #endif |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 213 | rD0 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 0, |
| 214 | rD1 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 1, |
| 215 | rD2 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 2, |
| 216 | rD3 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 3, |
| 217 | rD4 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 4, |
| 218 | rD5 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 5, |
| 219 | rD6 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 6, |
| 220 | rD7 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 7, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 221 | #if 0 // TODO: expand resource mask to enable use of all MIPS fp registers. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 222 | rD8 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 8, |
| 223 | rD9 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 9, |
| 224 | rD10 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 10, |
| 225 | rD11 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 11, |
| 226 | rD12 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 12, |
| 227 | rD13 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 13, |
| 228 | rD14 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 14, |
| 229 | rD15 = RegStorage::k64BitSolo | RegStorage::kFloatingPoint | 15, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 230 | #endif |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 233 | constexpr RegStorage rs_rZERO(RegStorage::kValid | rZERO); |
| 234 | constexpr RegStorage rs_rAT(RegStorage::kValid | rAT); |
| 235 | constexpr RegStorage rs_rV0(RegStorage::kValid | rV0); |
| 236 | constexpr RegStorage rs_rV1(RegStorage::kValid | rV1); |
| 237 | constexpr RegStorage rs_rA0(RegStorage::kValid | rA0); |
| 238 | constexpr RegStorage rs_rA1(RegStorage::kValid | rA1); |
| 239 | constexpr RegStorage rs_rA2(RegStorage::kValid | rA2); |
| 240 | constexpr RegStorage rs_rA3(RegStorage::kValid | rA3); |
| 241 | constexpr RegStorage rs_rT0(RegStorage::kValid | rT0); |
| 242 | constexpr RegStorage rs_rT1(RegStorage::kValid | rT1); |
| 243 | constexpr RegStorage rs_rT2(RegStorage::kValid | rT2); |
| 244 | constexpr RegStorage rs_rT3(RegStorage::kValid | rT3); |
| 245 | constexpr RegStorage rs_rT4(RegStorage::kValid | rT4); |
| 246 | constexpr RegStorage rs_rT5(RegStorage::kValid | rT5); |
| 247 | constexpr RegStorage rs_rT6(RegStorage::kValid | rT6); |
| 248 | constexpr RegStorage rs_rT7(RegStorage::kValid | rT7); |
| 249 | constexpr RegStorage rs_rS0(RegStorage::kValid | rS0); |
| 250 | constexpr RegStorage rs_rS1(RegStorage::kValid | rS1); |
| 251 | constexpr RegStorage rs_rS2(RegStorage::kValid | rS2); |
| 252 | constexpr RegStorage rs_rS3(RegStorage::kValid | rS3); |
| 253 | constexpr RegStorage rs_rS4(RegStorage::kValid | rS4); |
| 254 | constexpr RegStorage rs_rS5(RegStorage::kValid | rS5); |
| 255 | constexpr RegStorage rs_rS6(RegStorage::kValid | rS6); |
| 256 | constexpr RegStorage rs_rS7(RegStorage::kValid | rS7); |
| 257 | constexpr RegStorage rs_rT8(RegStorage::kValid | rT8); |
| 258 | constexpr RegStorage rs_rT9(RegStorage::kValid | rT9); |
| 259 | constexpr RegStorage rs_rK0(RegStorage::kValid | rK0); |
| 260 | constexpr RegStorage rs_rK1(RegStorage::kValid | rK1); |
| 261 | constexpr RegStorage rs_rGP(RegStorage::kValid | rGP); |
| 262 | constexpr RegStorage rs_rSP(RegStorage::kValid | rSP); |
| 263 | constexpr RegStorage rs_rFP(RegStorage::kValid | rFP); |
| 264 | constexpr RegStorage rs_rRA(RegStorage::kValid | rRA); |
| 265 | |
| 266 | constexpr RegStorage rs_rMIPS_LR(RegStorage::kInvalid); // Not used for MIPS. |
| 267 | constexpr RegStorage rs_rMIPS_PC(RegStorage::kInvalid); // Not used for MIPS. |
| 268 | constexpr RegStorage rs_rMIPS_COUNT(RegStorage::kInvalid); // Not used for MIPS. |
| 269 | |
| 270 | constexpr RegStorage rs_rF0(RegStorage::kValid | rF0); |
| 271 | constexpr RegStorage rs_rF1(RegStorage::kValid | rF1); |
| 272 | constexpr RegStorage rs_rF2(RegStorage::kValid | rF2); |
| 273 | constexpr RegStorage rs_rF3(RegStorage::kValid | rF3); |
| 274 | constexpr RegStorage rs_rF4(RegStorage::kValid | rF4); |
| 275 | constexpr RegStorage rs_rF5(RegStorage::kValid | rF5); |
| 276 | constexpr RegStorage rs_rF6(RegStorage::kValid | rF6); |
| 277 | constexpr RegStorage rs_rF7(RegStorage::kValid | rF7); |
| 278 | constexpr RegStorage rs_rF8(RegStorage::kValid | rF8); |
| 279 | constexpr RegStorage rs_rF9(RegStorage::kValid | rF9); |
| 280 | constexpr RegStorage rs_rF10(RegStorage::kValid | rF10); |
| 281 | constexpr RegStorage rs_rF11(RegStorage::kValid | rF11); |
| 282 | constexpr RegStorage rs_rF12(RegStorage::kValid | rF12); |
| 283 | constexpr RegStorage rs_rF13(RegStorage::kValid | rF13); |
| 284 | constexpr RegStorage rs_rF14(RegStorage::kValid | rF14); |
| 285 | constexpr RegStorage rs_rF15(RegStorage::kValid | rF15); |
| 286 | |
| 287 | constexpr RegStorage rs_rD0(RegStorage::kValid | rD0); |
| 288 | constexpr RegStorage rs_rD1(RegStorage::kValid | rD1); |
| 289 | constexpr RegStorage rs_rD2(RegStorage::kValid | rD2); |
| 290 | constexpr RegStorage rs_rD3(RegStorage::kValid | rD3); |
| 291 | constexpr RegStorage rs_rD4(RegStorage::kValid | rD4); |
| 292 | constexpr RegStorage rs_rD5(RegStorage::kValid | rD5); |
| 293 | constexpr RegStorage rs_rD6(RegStorage::kValid | rD6); |
| 294 | constexpr RegStorage rs_rD7(RegStorage::kValid | rD7); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 295 | |
| 296 | // TODO: reduce/eliminate use of these. |
| 297 | #define rMIPS_SUSPEND rS0 |
| 298 | #define rs_rMIPS_SUSPEND rs_rS0 |
| 299 | #define rMIPS_SELF rS1 |
| 300 | #define rs_rMIPS_SELF rs_rS1 |
| 301 | #define rMIPS_SP rSP |
| 302 | #define rs_rMIPS_SP rs_rSP |
| 303 | #define rMIPS_ARG0 rARG0 |
| 304 | #define rs_rMIPS_ARG0 rs_rARG0 |
| 305 | #define rMIPS_ARG1 rARG1 |
| 306 | #define rs_rMIPS_ARG1 rs_rARG1 |
| 307 | #define rMIPS_ARG2 rARG2 |
| 308 | #define rs_rMIPS_ARG2 rs_rARG2 |
| 309 | #define rMIPS_ARG3 rARG3 |
| 310 | #define rs_rMIPS_ARG3 rs_rARG3 |
| 311 | #define rMIPS_FARG0 rFARG0 |
| 312 | #define rs_rMIPS_FARG0 rs_rFARG0 |
| 313 | #define rMIPS_FARG1 rFARG1 |
| 314 | #define rs_rMIPS_FARG1 rs_rFARG1 |
| 315 | #define rMIPS_FARG2 rFARG2 |
| 316 | #define rs_rMIPS_FARG2 rs_rFARG2 |
| 317 | #define rMIPS_FARG3 rFARG3 |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 318 | #define rs_rMIPS_FARG3 rs_rFARG3 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 319 | #define rMIPS_RET0 rRESULT0 |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 320 | #define rs_rMIPS_RET0 rs_rRESULT0 |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 321 | #define rMIPS_RET1 rRESULT1 |
| 322 | #define rs_rMIPS_RET1 rs_rRESULT1 |
| 323 | #define rMIPS_INVOKE_TGT rT9 |
| 324 | #define rs_rMIPS_INVOKE_TGT rs_rT9 |
| 325 | #define rMIPS_COUNT RegStorage::kInvalidRegVal |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 326 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 327 | // RegisterLocation templates return values (r_V0, or r_V0/r_V1). |
| 328 | const RegLocation mips_loc_c_return |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 329 | {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 330 | RegStorage(RegStorage::k32BitSolo, rV0), INVALID_SREG, INVALID_SREG}; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 331 | const RegLocation mips_loc_c_return_wide |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 332 | {kLocPhysReg, 1, 0, 0, 0, 0, 0, 0, 1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 333 | RegStorage(RegStorage::k64BitPair, rV0, rV1), INVALID_SREG, INVALID_SREG}; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 334 | const RegLocation mips_loc_c_return_float |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 335 | {kLocPhysReg, 0, 0, 0, 1, 0, 0, 0, 1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 336 | RegStorage(RegStorage::k32BitSolo, rF0), INVALID_SREG, INVALID_SREG}; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 337 | // FIXME: move MIPS to k64Bitsolo for doubles |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 338 | const RegLocation mips_loc_c_return_double |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 339 | {kLocPhysReg, 1, 0, 0, 1, 0, 0, 0, 1, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 340 | RegStorage(RegStorage::k64BitPair, rF0, rF1), INVALID_SREG, INVALID_SREG}; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 341 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 342 | enum MipsShiftEncodings { |
| 343 | kMipsLsl = 0x0, |
| 344 | kMipsLsr = 0x1, |
| 345 | kMipsAsr = 0x2, |
| 346 | kMipsRor = 0x3 |
| 347 | }; |
| 348 | |
| 349 | // MIPS sync kinds (Note: support for kinds other than kSYNC0 may not exist). |
| 350 | #define kSYNC0 0x00 |
| 351 | #define kSYNC_WMB 0x04 |
| 352 | #define kSYNC_MB 0x01 |
| 353 | #define kSYNC_ACQUIRE 0x11 |
| 354 | #define kSYNC_RELEASE 0x12 |
| 355 | #define kSYNC_RMB 0x13 |
| 356 | |
| 357 | // TODO: Use smaller hammer when appropriate for target CPU. |
| 358 | #define kST kSYNC0 |
| 359 | #define kSY kSYNC0 |
| 360 | |
| 361 | /* |
| 362 | * The following enum defines the list of supported Thumb instructions by the |
| 363 | * assembler. Their corresponding EncodingMap positions will be defined in |
| 364 | * Assemble.cc. |
| 365 | */ |
| 366 | enum MipsOpCode { |
| 367 | kMipsFirst = 0, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 368 | kMips32BitData = kMipsFirst, // data [31..0]. |
| 369 | kMipsAddiu, // addiu t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0]. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 370 | kMipsAddu, // add d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100001]. |
| 371 | kMipsAnd, // and d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100100]. |
| 372 | kMipsAndi, // andi t,s,imm16 [001100] s[25..21] t[20..16] imm16[15..0]. |
| 373 | kMipsB, // b o [0001000000000000] o[15..0]. |
| 374 | kMipsBal, // bal o [0000010000010001] o[15..0]. |
| 375 | // NOTE: the code tests the range kMipsBeq thru kMipsBne, so adding an instruction in this |
| 376 | // range may require updates. |
| 377 | kMipsBeq, // beq s,t,o [000100] s[25..21] t[20..16] o[15..0]. |
| 378 | kMipsBeqz, // beqz s,o [000100] s[25..21] [00000] o[15..0]. |
| 379 | kMipsBgez, // bgez s,o [000001] s[25..21] [00001] o[15..0]. |
| 380 | kMipsBgtz, // bgtz s,o [000111] s[25..21] [00000] o[15..0]. |
| 381 | kMipsBlez, // blez s,o [000110] s[25..21] [00000] o[15..0]. |
| 382 | kMipsBltz, // bltz s,o [000001] s[25..21] [00000] o[15..0]. |
| 383 | kMipsBnez, // bnez s,o [000101] s[25..21] [00000] o[15..0]. |
| 384 | kMipsBne, // bne s,t,o [000101] s[25..21] t[20..16] o[15..0]. |
| 385 | kMipsDiv, // div s,t [000000] s[25..21] t[20..16] [0000000000011010]. |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 386 | #if __mips_isa_rev >= 2 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 387 | kMipsExt, // ext t,s,p,z [011111] s[25..21] t[20..16] z[15..11] p[10..6] [000000]. |
| 388 | #endif |
| 389 | kMipsJal, // jal t [000011] t[25..0]. |
| 390 | kMipsJalr, // jalr d,s [000000] s[25..21] [00000] d[15..11] hint[10..6] [001001]. |
| 391 | kMipsJr, // jr s [000000] s[25..21] [0000000000] hint[10..6] [001000]. |
| 392 | kMipsLahi, // lui t,imm16 [00111100000] t[20..16] imm16[15..0] load addr hi. |
| 393 | kMipsLalo, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0] load addr lo. |
| 394 | kMipsLui, // lui t,imm16 [00111100000] t[20..16] imm16[15..0]. |
| 395 | kMipsLb, // lb t,o(b) [100000] b[25..21] t[20..16] o[15..0]. |
| 396 | kMipsLbu, // lbu t,o(b) [100100] b[25..21] t[20..16] o[15..0]. |
| 397 | kMipsLh, // lh t,o(b) [100001] b[25..21] t[20..16] o[15..0]. |
| 398 | kMipsLhu, // lhu t,o(b) [100101] b[25..21] t[20..16] o[15..0]. |
| 399 | kMipsLw, // lw t,o(b) [100011] b[25..21] t[20..16] o[15..0]. |
| 400 | kMipsMfhi, // mfhi d [0000000000000000] d[15..11] [00000010000]. |
| 401 | kMipsMflo, // mflo d [0000000000000000] d[15..11] [00000010010]. |
| 402 | kMipsMove, // move d,s [000000] s[25..21] [00000] d[15..11] [00000100101]. |
| 403 | kMipsMovz, // movz d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000001010]. |
| 404 | kMipsMul, // mul d,s,t [011100] s[25..21] t[20..16] d[15..11] [00000000010]. |
| 405 | kMipsNop, // nop [00000000000000000000000000000000]. |
| 406 | kMipsNor, // nor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100111]. |
| 407 | kMipsOr, // or d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100101]. |
| 408 | kMipsOri, // ori t,s,imm16 [001001] s[25..21] t[20..16] imm16[15..0]. |
| 409 | kMipsPref, // pref h,o(b) [101011] b[25..21] h[20..16] o[15..0]. |
| 410 | kMipsSb, // sb t,o(b) [101000] b[25..21] t[20..16] o[15..0]. |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 411 | #if __mips_isa_rev >= 2 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 412 | kMipsSeb, // seb d,t [01111100000] t[20..16] d[15..11] [10000100000]. |
| 413 | kMipsSeh, // seh d,t [01111100000] t[20..16] d[15..11] [11000100000]. |
| 414 | #endif |
| 415 | kMipsSh, // sh t,o(b) [101001] b[25..21] t[20..16] o[15..0]. |
| 416 | kMipsSll, // sll d,t,a [00000000000] t[20..16] d[15..11] a[10..6] [000000]. |
| 417 | kMipsSllv, // sllv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000100]. |
| 418 | kMipsSlt, // slt d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101010]. |
| 419 | kMipsSlti, // slti t,s,imm16 [001010] s[25..21] t[20..16] imm16[15..0]. |
| 420 | kMipsSltu, // sltu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000101011]. |
| 421 | kMipsSra, // sra d,s,imm5 [00000000000] t[20..16] d[15..11] imm5[10..6] [000011]. |
| 422 | kMipsSrav, // srav d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000111]. |
| 423 | kMipsSrl, // srl d,t,a [00000000000] t[20..16] d[20..16] a[10..6] [000010]. |
| 424 | kMipsSrlv, // srlv d,t,s [000000] s[25..21] t[20..16] d[15..11] [00000000110]. |
| 425 | kMipsSubu, // subu d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100011]. |
| 426 | kMipsSw, // sw t,o(b) [101011] b[25..21] t[20..16] o[15..0]. |
| 427 | kMipsXor, // xor d,s,t [000000] s[25..21] t[20..16] d[15..11] [00000100110]. |
| 428 | kMipsXori, // xori t,s,imm16 [001110] s[25..21] t[20..16] imm16[15..0]. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 429 | kMipsFadds, // add.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000000]. |
| 430 | kMipsFsubs, // sub.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000001]. |
| 431 | kMipsFmuls, // mul.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000010]. |
| 432 | kMipsFdivs, // div.s d,s,t [01000110000] t[20..16] s[15..11] d[10..6] [000011]. |
| 433 | kMipsFaddd, // add.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000000]. |
| 434 | kMipsFsubd, // sub.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000001]. |
| 435 | kMipsFmuld, // mul.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000010]. |
| 436 | kMipsFdivd, // div.d d,s,t [01000110001] t[20..16] s[15..11] d[10..6] [000011]. |
| 437 | kMipsFcvtsd, // cvt.s.d d,s [01000110001] [00000] s[15..11] d[10..6] [100000]. |
| 438 | kMipsFcvtsw, // cvt.s.w d,s [01000110100] [00000] s[15..11] d[10..6] [100000]. |
| 439 | kMipsFcvtds, // cvt.d.s d,s [01000110000] [00000] s[15..11] d[10..6] [100001]. |
| 440 | kMipsFcvtdw, // cvt.d.w d,s [01000110100] [00000] s[15..11] d[10..6] [100001]. |
| 441 | kMipsFcvtws, // cvt.w.d d,s [01000110000] [00000] s[15..11] d[10..6] [100100]. |
| 442 | kMipsFcvtwd, // cvt.w.d d,s [01000110001] [00000] s[15..11] d[10..6] [100100]. |
| 443 | kMipsFmovs, // mov.s d,s [01000110000] [00000] s[15..11] d[10..6] [000110]. |
| 444 | kMipsFmovd, // mov.d d,s [01000110001] [00000] s[15..11] d[10..6] [000110]. |
| 445 | kMipsFlwc1, // lwc1 t,o(b) [110001] b[25..21] t[20..16] o[15..0]. |
| 446 | kMipsFldc1, // ldc1 t,o(b) [110101] b[25..21] t[20..16] o[15..0]. |
| 447 | kMipsFswc1, // swc1 t,o(b) [111001] b[25..21] t[20..16] o[15..0]. |
| 448 | kMipsFsdc1, // sdc1 t,o(b) [111101] b[25..21] t[20..16] o[15..0]. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 449 | kMipsMfc1, // mfc1 t,s [01000100000] t[20..16] s[15..11] [00000000000]. |
| 450 | kMipsMtc1, // mtc1 t,s [01000100100] t[20..16] s[15..11] [00000000000]. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 451 | kMipsDelta, // Psuedo for ori t, s, <label>-<label>. |
| 452 | kMipsDeltaHi, // Pseudo for lui t, high16(<label>-<label>). |
| 453 | kMipsDeltaLo, // Pseudo for ori t, s, low16(<label>-<label>). |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 454 | kMipsCurrPC, // jal to .+8 to materialize pc. |
| 455 | kMipsSync, // sync kind [000000] [0000000000000000] s[10..6] [001111]. |
| 456 | kMipsUndefined, // undefined [011001xxxxxxxxxxxxxxxx]. |
| 457 | kMipsLast |
| 458 | }; |
| 459 | |
| 460 | // Instruction assembly field_loc kind. |
| 461 | enum MipsEncodingKind { |
| 462 | kFmtUnused, |
| 463 | kFmtBitBlt, /* Bit string using end/start */ |
| 464 | kFmtDfp, /* Double FP reg */ |
| 465 | kFmtSfp, /* Single FP reg */ |
| 466 | kFmtBlt5_2, /* Same 5-bit field to 2 locations */ |
| 467 | }; |
| 468 | |
| 469 | // Struct used to define the snippet positions for each MIPS opcode. |
| 470 | struct MipsEncodingMap { |
| 471 | uint32_t skeleton; |
| 472 | struct { |
| 473 | MipsEncodingKind kind; |
| 474 | int end; // end for kFmtBitBlt, 1-bit slice end for FP regs. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 475 | int start; // start for kFmtBitBlt, 4-bit slice end for FP regs. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 476 | } field_loc[4]; |
| 477 | MipsOpCode opcode; |
| 478 | uint64_t flags; |
| 479 | const char *name; |
| 480 | const char* fmt; |
| 481 | int size; // Note: size is in bytes. |
| 482 | }; |
| 483 | |
| 484 | extern MipsEncodingMap EncodingMap[kMipsLast]; |
| 485 | |
| 486 | #define IS_UIMM16(v) ((0 <= (v)) && ((v) <= 65535)) |
| 487 | #define IS_SIMM16(v) ((-32768 <= (v)) && ((v) <= 32766)) |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 488 | #define IS_SIMM16_2WORD(v) ((-32764 <= (v)) && ((v) <= 32763)) // 2 offsets must fit. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 489 | |
| 490 | } // namespace art |
| 491 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 492 | #endif // ART_COMPILER_DEX_QUICK_MIPS_MIPS_LIR_H_ |