| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #include "Dalvik.h" |
| 18 | #include "libdex/OpCode.h" |
| 19 | #include "dexdump/OpCodeNames.h" |
| 20 | |
| 21 | #include "../../CompilerInternals.h" |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 22 | #include "ArmLIR.h" |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 23 | #include <unistd.h> /* for cacheflush */ |
| 24 | |
| 25 | /* |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 26 | * opcode: ArmOpCode enum |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 27 | * skeleton: pre-designated bit-pattern for this opcode |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 28 | * k0: key to applying ds/de |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 29 | * ds: dest start bit position |
| 30 | * de: dest end bit position |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 31 | * k1: key to applying s1s/s1e |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 32 | * s1s: src1 start bit position |
| 33 | * s1e: src1 end bit position |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 34 | * k2: key to applying s2s/s2e |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 35 | * s2s: src2 start bit position |
| 36 | * s2e: src2 end bit position |
| 37 | * operands: number of operands (for sanity check purposes) |
| 38 | * name: mnemonic name |
| 39 | * fmt: for pretty-prining |
| 40 | */ |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 41 | #define ENCODING_MAP(opcode, skeleton, k0, ds, de, k1, s1s, s1e, k2, s2s, s2e, \ |
| 42 | operands, name, fmt, size) \ |
| 43 | {skeleton, {{k0, ds, de}, {k1, s1s, s1e}, {k2, s2s, s2e}}, \ |
| 44 | opcode, operands, name, fmt, size} |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 45 | |
| 46 | /* Instruction dump string format keys: !pf, where "!" is the start |
| 47 | * of the key, "p" is which numeric operand to use and "f" is the |
| 48 | * print format. |
| 49 | * |
| 50 | * [p]ositions: |
| 51 | * 0 -> operands[0] (dest) |
| 52 | * 1 -> operands[1] (src1) |
| 53 | * 2 -> operands[2] (src2) |
| 54 | * |
| 55 | * [f]ormats: |
| 56 | * h -> 4-digit hex |
| 57 | * d -> decimal |
| 58 | * D -> decimal+8 (used to convert 3-bit regnum field to high reg) |
| 59 | * E -> decimal*4 |
| 60 | * F -> decimal*2 |
| 61 | * c -> branch condition (beq, bne, etc.) |
| 62 | * t -> pc-relative target |
| 63 | * u -> 1st half of bl[x] target |
| 64 | * v -> 2nd half ob bl[x] target |
| 65 | * R -> register list |
| 66 | * |
| 67 | * [!] escape. To insert "!", use "!!" |
| 68 | */ |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 69 | /* NOTE: must be kept in sync with enum ArmOpcode from ArmLIR.h */ |
| 70 | ArmEncodingMap EncodingMap[ARM_LAST] = { |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 71 | ENCODING_MAP(ARM_16BIT_DATA, 0x0000, |
| 72 | BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 73 | IS_UNARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 74 | "data", "0x!0h(!0d)", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 75 | ENCODING_MAP(THUMB_ADC, 0x4140, |
| 76 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 77 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 78 | "adc", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 79 | ENCODING_MAP(THUMB_ADD_RRI3, 0x1c00, |
| 80 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 81 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 82 | "add", "r!0d, r!1d, #!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 83 | ENCODING_MAP(THUMB_ADD_RI8, 0x3000, |
| 84 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 85 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 86 | "add", "r!0d, r!0d, #!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 87 | ENCODING_MAP(THUMB_ADD_RRR, 0x1800, |
| 88 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 89 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 90 | "add", "r!0d, r!1d, r!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 91 | ENCODING_MAP(THUMB_ADD_RR_LH, 0x4440, |
| 92 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 93 | IS_BINARY_OP | CLOBBER_DEST, |
| 94 | "add", |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 95 | "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 96 | ENCODING_MAP(THUMB_ADD_RR_HL, 0x4480, |
| 97 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 98 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 99 | "add", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 100 | ENCODING_MAP(THUMB_ADD_RR_HH, 0x44c0, |
| 101 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 102 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 103 | "add", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 104 | ENCODING_MAP(THUMB_ADD_PC_REL, 0xa000, |
| 105 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 106 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 107 | "add", "r!0d, pc, #!1E", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 108 | ENCODING_MAP(THUMB_ADD_SP_REL, 0xa800, |
| 109 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 110 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 111 | "add", "r!0d, sp, #!1E", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 112 | ENCODING_MAP(THUMB_ADD_SPI7, 0xb000, |
| 113 | BITBLT, 6, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 114 | IS_UNARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 115 | "add", "sp, #!0d*4", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 116 | ENCODING_MAP(THUMB_AND_RR, 0x4000, |
| 117 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 118 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 119 | "and", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 120 | ENCODING_MAP(THUMB_ASR, 0x1000, |
| 121 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 122 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 123 | "asr", "r!0d, r!1d, #!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 124 | ENCODING_MAP(THUMB_ASRV, 0x4100, |
| 125 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 126 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 127 | "asr", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 128 | ENCODING_MAP(THUMB_B_COND, 0xd000, |
| 129 | BITBLT, 7, 0, BITBLT, 11, 8, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 130 | IS_BINARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 131 | "!1c", "!0t", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 132 | ENCODING_MAP(THUMB_B_UNCOND, 0xe000, |
| 133 | BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 134 | NO_OPERAND | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 135 | "b", "!0t", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 136 | ENCODING_MAP(THUMB_BIC, 0x4380, |
| 137 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 138 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 139 | "bic", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 140 | ENCODING_MAP(THUMB_BKPT, 0xbe00, |
| 141 | BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 142 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 143 | "bkpt", "!0d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 144 | ENCODING_MAP(THUMB_BLX_1, 0xf000, |
| 145 | BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 146 | IS_BINARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 147 | "blx_1", "!0u", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 148 | ENCODING_MAP(THUMB_BLX_2, 0xe800, |
| 149 | BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 150 | IS_BINARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 151 | "blx_2", "!0v", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 152 | ENCODING_MAP(THUMB_BL_1, 0xf000, |
| 153 | BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 154 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 155 | "bl_1", "!0u", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 156 | ENCODING_MAP(THUMB_BL_2, 0xf800, |
| 157 | BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 158 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 159 | "bl_2", "!0v", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 160 | ENCODING_MAP(THUMB_BLX_R, 0x4780, |
| 161 | BITBLT, 6, 3, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 162 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 163 | "blx", "r!0d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 164 | ENCODING_MAP(THUMB_BX, 0x4700, |
| 165 | BITBLT, 6, 3, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 166 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 167 | "bx", "r!0d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 168 | ENCODING_MAP(THUMB_CMN, 0x42c0, |
| 169 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 170 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 171 | "cmn", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 172 | ENCODING_MAP(THUMB_CMP_RI8, 0x2800, |
| 173 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 174 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 175 | "cmp", "r!0d, #!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 176 | ENCODING_MAP(THUMB_CMP_RR, 0x4280, |
| 177 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 178 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 179 | "cmp", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 180 | ENCODING_MAP(THUMB_CMP_LH, 0x4540, |
| 181 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 182 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 183 | "cmp", "r!0d, r!1D", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 184 | ENCODING_MAP(THUMB_CMP_HL, 0x4580, |
| 185 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 186 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 187 | "cmp", "r!0D, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 188 | ENCODING_MAP(THUMB_CMP_HH, 0x45c0, |
| 189 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 190 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 191 | "cmp", "r!0D, r!1D", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 192 | ENCODING_MAP(THUMB_EOR, 0x4040, |
| 193 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 194 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 195 | "eor", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 196 | ENCODING_MAP(THUMB_LDMIA, 0xc800, |
| 197 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 198 | IS_BINARY_OP | CLOBBER_DEST | CLOBBER_SRC1, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 199 | "ldmia", "r!0d!!, <!1R>", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 200 | ENCODING_MAP(THUMB_LDR_RRI5, 0x6800, |
| 201 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 202 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 203 | "ldr", "r!0d, [r!1d, #!2E]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 204 | ENCODING_MAP(THUMB_LDR_RRR, 0x5800, |
| 205 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 206 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 207 | "ldr", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 208 | ENCODING_MAP(THUMB_LDR_PC_REL, 0x4800, |
| 209 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 210 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 211 | "ldr", "r!0d, [pc, #!1E]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 212 | ENCODING_MAP(THUMB_LDR_SP_REL, 0x9800, |
| 213 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 214 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 215 | "ldr", "r!0d, [sp, #!1E]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 216 | ENCODING_MAP(THUMB_LDRB_RRI5, 0x7800, |
| 217 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 218 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 219 | "ldrb", "r!0d, [r!1d, #2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 220 | ENCODING_MAP(THUMB_LDRB_RRR, 0x5c00, |
| 221 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 222 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 223 | "ldrb", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 224 | ENCODING_MAP(THUMB_LDRH_RRI5, 0x8800, |
| 225 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 226 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 227 | "ldrh", "r!0d, [r!1d, #!2F]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 228 | ENCODING_MAP(THUMB_LDRH_RRR, 0x5a00, |
| 229 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 230 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 231 | "ldrh", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 232 | ENCODING_MAP(THUMB_LDRSB_RRR, 0x5600, |
| 233 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 234 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 235 | "ldrsb", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 236 | ENCODING_MAP(THUMB_LDRSH_RRR, 0x5e00, |
| 237 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 238 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 239 | "ldrsh", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 240 | ENCODING_MAP(THUMB_LSL, 0x0000, |
| 241 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 242 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 243 | "lsl", "r!0d, r!1d, #!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 244 | ENCODING_MAP(THUMB_LSLV, 0x4080, |
| 245 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 246 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 247 | "lsl", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 248 | ENCODING_MAP(THUMB_LSR, 0x0800, |
| 249 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 250 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 251 | "lsr", "r!0d, r!1d, #!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 252 | ENCODING_MAP(THUMB_LSRV, 0x40c0, |
| 253 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 254 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 255 | "lsr", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 256 | ENCODING_MAP(THUMB_MOV_IMM, 0x2000, |
| 257 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 258 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 259 | "mov", "r!0d, #!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 260 | ENCODING_MAP(THUMB_MOV_RR, 0x1c00, |
| 261 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 262 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 263 | "mov", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 264 | ENCODING_MAP(THUMB_MOV_RR_H2H, 0x46c0, |
| 265 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 266 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 267 | "mov", "r!0D, r!1D", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 268 | ENCODING_MAP(THUMB_MOV_RR_H2L, 0x4640, |
| 269 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 270 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 271 | "mov", "r!0d, r!1D", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 272 | ENCODING_MAP(THUMB_MOV_RR_L2H, 0x4680, |
| 273 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 274 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 275 | "mov", "r!0D, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 276 | ENCODING_MAP(THUMB_MUL, 0x4340, |
| 277 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 278 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 279 | "mul", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 280 | ENCODING_MAP(THUMB_MVN, 0x43c0, |
| 281 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 282 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 283 | "mvn", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 284 | ENCODING_MAP(THUMB_NEG, 0x4240, |
| 285 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 286 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 287 | "neg", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 288 | ENCODING_MAP(THUMB_ORR, 0x4300, |
| 289 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 290 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 291 | "orr", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 292 | ENCODING_MAP(THUMB_POP, 0xbc00, |
| 293 | BITBLT, 8, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 294 | IS_UNARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 295 | "pop", "<!0R>", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 296 | ENCODING_MAP(THUMB_PUSH, 0xb400, |
| 297 | BITBLT, 8, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 298 | IS_UNARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 299 | "push", "<!0R>", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 300 | ENCODING_MAP(THUMB_ROR, 0x41c0, |
| 301 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 302 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 303 | "ror", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 304 | ENCODING_MAP(THUMB_SBC, 0x4180, |
| 305 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 306 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 307 | "sbc", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 308 | ENCODING_MAP(THUMB_STMIA, 0xc000, |
| 309 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 310 | IS_BINARY_OP | CLOBBER_SRC1, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 311 | "stmia", "r!0d!!, <!1R>", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 312 | ENCODING_MAP(THUMB_STR_RRI5, 0x6000, |
| 313 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 314 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 315 | "str", "r!0d, [r!1d, #!2E]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 316 | ENCODING_MAP(THUMB_STR_RRR, 0x5000, |
| 317 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 318 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 319 | "str", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 320 | ENCODING_MAP(THUMB_STR_SP_REL, 0x9000, |
| 321 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 322 | IS_BINARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 323 | "str", "r!0d, [sp, #!1E]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 324 | ENCODING_MAP(THUMB_STRB_RRI5, 0x7000, |
| 325 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 326 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 327 | "strb", "r!0d, [r!1d, #!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 328 | ENCODING_MAP(THUMB_STRB_RRR, 0x5400, |
| 329 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 330 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 331 | "strb", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 332 | ENCODING_MAP(THUMB_STRH_RRI5, 0x8000, |
| 333 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 334 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 335 | "strh", "r!0d, [r!1d, #!2F]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 336 | ENCODING_MAP(THUMB_STRH_RRR, 0x5200, |
| 337 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 338 | IS_TERTIARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 339 | "strh", "r!0d, [r!1d, r!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 340 | ENCODING_MAP(THUMB_SUB_RRI3, 0x1e00, |
| 341 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 342 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 343 | "sub", "r!0d, r!1d, #!2d]", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 344 | ENCODING_MAP(THUMB_SUB_RI8, 0x3800, |
| 345 | BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 346 | IS_BINARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 347 | "sub", "r!0d, #!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 348 | ENCODING_MAP(THUMB_SUB_RRR, 0x1a00, |
| 349 | BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 350 | IS_TERTIARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 351 | "sub", "r!0d, r!1d, r!2d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 352 | ENCODING_MAP(THUMB_SUB_SPI7, 0xb080, |
| 353 | BITBLT, 6, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 354 | IS_UNARY_OP | CLOBBER_DEST, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 355 | "sub", "sp, #!0d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 356 | ENCODING_MAP(THUMB_SWI, 0xdf00, |
| 357 | BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 358 | IS_UNARY_OP | IS_BRANCH, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 359 | "swi", "!0d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 360 | ENCODING_MAP(THUMB_TST, 0x4200, |
| 361 | BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 362 | IS_UNARY_OP, |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 363 | "tst", "r!0d, r!1d", 1), |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 364 | ENCODING_MAP(THUMB2_VLDRS, 0xed900a00, |
| 365 | SFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, |
| 366 | IS_TERTIARY_OP, |
| 367 | "vldr", "s!0d, [r!1d, #!2E]", 2), |
| 368 | ENCODING_MAP(THUMB2_VLDRD, 0xed900b00, |
| 369 | DFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, |
| 370 | IS_TERTIARY_OP, |
| 371 | "vldr", "d!0d, [r!1d, #!2E]", 2), |
| 372 | ENCODING_MAP(THUMB2_VMULS, 0xee200a00, |
| 373 | SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, |
| 374 | IS_TERTIARY_OP, |
| 375 | "vmuls", "s!0d, s!1d, s!2d", 2), |
| 376 | ENCODING_MAP(THUMB2_VMULD, 0xee200b00, |
| 377 | DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, |
| 378 | IS_TERTIARY_OP, |
| 379 | "vmuld", "d!0d, d!1d, d!2d", 2), |
| 380 | ENCODING_MAP(THUMB2_VSTRS, 0xed800a00, |
| 381 | SFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, |
| 382 | IS_TERTIARY_OP, |
| 383 | "vstr", "s!0d, [r!1d, #!2E]", 2), |
| 384 | ENCODING_MAP(THUMB2_VSTRD, 0xed800b00, |
| 385 | DFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, |
| 386 | IS_TERTIARY_OP, |
| 387 | "vstr", "d!0d, [r!1d, #!2E]", 2), |
| 388 | ENCODING_MAP(THUMB2_VSUBS, 0xee300a40, |
| 389 | SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, |
| 390 | IS_TERTIARY_OP, |
| 391 | "vsub", "s!0d, s!1d, s!2d", 2), |
| 392 | ENCODING_MAP(THUMB2_VSUBD, 0xee300b40, |
| 393 | DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, |
| 394 | IS_TERTIARY_OP, |
| 395 | "vsub", "d!0d, s!1d, s!2d", 2), |
| 396 | ENCODING_MAP(THUMB2_VADDS, 0xee300a00, |
| 397 | SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, |
| 398 | IS_TERTIARY_OP, |
| 399 | "vadd", "s!0d, s!1d, s!2d", 2), |
| 400 | ENCODING_MAP(THUMB2_VADDD, 0xee300b00, |
| 401 | DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, |
| 402 | IS_TERTIARY_OP, |
| 403 | "vadd", "d!0d, s!1d, s!2d", 2), |
| 404 | ENCODING_MAP(THUMB2_VDIVS, 0xee800a00, |
| 405 | SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, |
| 406 | IS_TERTIARY_OP, |
| 407 | "vdivs", "s!0d, s!1d, s!2d", 2), |
| 408 | ENCODING_MAP(THUMB2_VDIVD, 0xee800b00, |
| 409 | DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, |
| 410 | IS_TERTIARY_OP, |
| 411 | "vdivs", "s!0d, s!1d, s!2d", 2), |
| 412 | ENCODING_MAP(THUMB2_VCVTIF, 0xeeb80ac0, |
| 413 | SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, |
| 414 | IS_BINARY_OP, |
| 415 | "vcvf.f32", "s!0d, s!1d", 2), |
| 416 | ENCODING_MAP(THUMB2_VCVTID, 0xeeb80bc0, |
| 417 | DFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, |
| 418 | IS_BINARY_OP, |
| 419 | "vcvf.f64", "s!0d, s!1d", 2), |
| 420 | ENCODING_MAP(THUMB2_VCVTFI, 0xeebd0ac0, |
| 421 | SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, |
| 422 | IS_BINARY_OP, |
| 423 | "vcvf.s32.f32", "s!0d, s!1d", 2), |
| 424 | ENCODING_MAP(THUMB2_VCVTDI, 0xeebd0bc0, |
| 425 | SFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, |
| 426 | IS_BINARY_OP, |
| 427 | "vcvf.s32.f64", "s!0d, s!1d", 2), |
| 428 | ENCODING_MAP(THUMB2_VCVTFD, 0xeeb70ac0, |
| 429 | DFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, |
| 430 | IS_BINARY_OP, |
| 431 | "vcvf.f64.f32", "s!0d, s!1d", 2), |
| 432 | ENCODING_MAP(THUMB2_VCVTDF, 0xeeb70bc0, |
| 433 | SFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, |
| 434 | IS_BINARY_OP, |
| 435 | "vcvf.f32.f64", "s!0d, s!1d", 2), |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | #define PADDING_MOV_R0_R0 0x1C00 |
| 439 | |
| 440 | /* Write the numbers in the literal pool to the codegen stream */ |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 441 | static void installDataContent(CompilationUnit *cUnit) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 442 | { |
| Ben Cheng | e80cd94 | 2009-07-17 15:54:23 -0700 | [diff] [blame] | 443 | int *dataPtr = (int *) ((char *) cUnit->baseAddr + cUnit->dataOffset); |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 444 | ArmLIR *dataLIR = (ArmLIR *) cUnit->wordList; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 445 | while (dataLIR) { |
| 446 | *dataPtr++ = dataLIR->operands[0]; |
| 447 | dataLIR = NEXT_LIR(dataLIR); |
| 448 | } |
| 449 | } |
| 450 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 451 | /* Returns the size of a Jit trace description */ |
| 452 | static int jitTraceDescriptionSize(const JitTraceDescription *desc) |
| 453 | { |
| 454 | int runCount; |
| 455 | for (runCount = 0; ; runCount++) { |
| 456 | if (desc->trace[runCount].frag.runEnd) |
| 457 | break; |
| 458 | } |
| 459 | return sizeof(JitCodeDesc) + ((runCount+1) * sizeof(JitTraceRun)); |
| 460 | } |
| 461 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 462 | /* Return TRUE if error happens */ |
| 463 | static bool assembleInstructions(CompilationUnit *cUnit, intptr_t startAddr) |
| 464 | { |
| 465 | short *bufferAddr = (short *) cUnit->codeBuffer; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 466 | ArmLIR *lir; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 467 | |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 468 | for (lir = (ArmLIR *) cUnit->firstLIRInsn; lir; lir = NEXT_LIR(lir)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 469 | if (lir->opCode < 0) { |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 470 | if ((lir->opCode == ARM_PSEUDO_ALIGN4) && |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 471 | /* 1 means padding is needed */ |
| 472 | (lir->operands[0] == 1)) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 473 | *bufferAddr++ = PADDING_MOV_R0_R0; |
| 474 | } |
| 475 | continue; |
| 476 | } |
| 477 | |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 478 | if (lir->isNop) { |
| 479 | continue; |
| 480 | } |
| 481 | |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 482 | if (lir->opCode == THUMB_LDR_PC_REL || |
| 483 | lir->opCode == THUMB_ADD_PC_REL) { |
| 484 | ArmLIR *lirTarget = (ArmLIR *) lir->generic.target; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 485 | intptr_t pc = (lir->generic.offset + 4) & ~3; |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 486 | /* |
| 487 | * Allow an offset (stored in operands[2] to be added to the |
| 488 | * PC-relative target. Useful to get to a fixed field inside a |
| 489 | * chaining cell. |
| 490 | */ |
| 491 | intptr_t target = lirTarget->generic.offset + lir->operands[2]; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 492 | int delta = target - pc; |
| 493 | if (delta & 0x3) { |
| 494 | LOGE("PC-rel distance is not multiples of 4: %d\n", delta); |
| 495 | dvmAbort(); |
| 496 | } |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 497 | if (delta > 1023) { |
| 498 | return true; |
| 499 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 500 | lir->operands[1] = delta >> 2; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 501 | } else if (lir->opCode == THUMB_B_COND) { |
| 502 | ArmLIR *targetLIR = (ArmLIR *) lir->generic.target; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 503 | intptr_t pc = lir->generic.offset + 4; |
| 504 | intptr_t target = targetLIR->generic.offset; |
| 505 | int delta = target - pc; |
| 506 | if (delta > 254 || delta < -256) { |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 507 | return true; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 508 | } |
| 509 | lir->operands[0] = delta >> 1; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 510 | } else if (lir->opCode == THUMB_B_UNCOND) { |
| 511 | ArmLIR *targetLIR = (ArmLIR *) lir->generic.target; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 512 | intptr_t pc = lir->generic.offset + 4; |
| 513 | intptr_t target = targetLIR->generic.offset; |
| 514 | int delta = target - pc; |
| 515 | if (delta > 2046 || delta < -2048) { |
| 516 | LOGE("Unconditional branch distance out of range: %d\n", delta); |
| 517 | dvmAbort(); |
| 518 | } |
| 519 | lir->operands[0] = delta >> 1; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 520 | } else if (lir->opCode == THUMB_BLX_1) { |
| 521 | assert(NEXT_LIR(lir)->opCode == THUMB_BLX_2); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 522 | /* curPC is Thumb */ |
| 523 | intptr_t curPC = (startAddr + lir->generic.offset + 4) & ~3; |
| 524 | intptr_t target = lir->operands[1]; |
| 525 | |
| 526 | /* Match bit[1] in target with base */ |
| 527 | if (curPC & 0x2) { |
| 528 | target |= 0x2; |
| 529 | } |
| 530 | int delta = target - curPC; |
| 531 | assert((delta >= -(1<<22)) && (delta <= ((1<<22)-2))); |
| 532 | |
| 533 | lir->operands[0] = (delta >> 12) & 0x7ff; |
| 534 | NEXT_LIR(lir)->operands[0] = (delta>> 1) & 0x7ff; |
| 535 | } |
| 536 | |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 537 | ArmEncodingMap *encoder = &EncodingMap[lir->opCode]; |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 538 | u4 bits = encoder->skeleton; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 539 | int i; |
| 540 | for (i = 0; i < 3; i++) { |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 541 | u4 value; |
| 542 | switch(encoder->fieldLoc[i].kind) { |
| 543 | case UNUSED: |
| 544 | break; |
| 545 | case BITBLT: |
| 546 | value = (lir->operands[i] << encoder->fieldLoc[i].start) & |
| 547 | ((1 << (encoder->fieldLoc[i].end + 1)) - 1); |
| 548 | bits |= value; |
| 549 | break; |
| 550 | case DFP: |
| 551 | /* Snag the 1-bit slice and position it */ |
| 552 | value = ((lir->operands[i] & 0x10) >> 4) << |
| 553 | encoder->fieldLoc[i].end; |
| 554 | /* Extract and position the 4-bit slice */ |
| 555 | value |= (lir->operands[i] & 0x0f) << |
| 556 | encoder->fieldLoc[i].start; |
| 557 | bits |= value; |
| 558 | break; |
| 559 | case SFP: |
| 560 | /* Snag the 1-bit slice and position it */ |
| 561 | value = (lir->operands[i] & 0x1) << |
| 562 | encoder->fieldLoc[i].end; |
| 563 | /* Extract and position the 4-bit slice */ |
| 564 | value |= ((lir->operands[i] & 0x1e) >> 1) << |
| 565 | encoder->fieldLoc[i].start; |
| 566 | bits |= value; |
| 567 | break; |
| 568 | case IMMSHIFT8: |
| 569 | case IMM12: |
| 570 | value = ((lir->operands[i] & 0x800) >> 11) << 26; |
| 571 | value |= ((lir->operands[i] & 0x700) >> 8) << 12; |
| 572 | value |= lir->operands[i] & 0x0ff; |
| 573 | break; |
| 574 | default: |
| 575 | assert(0); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 576 | } |
| 577 | } |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 578 | if (encoder->size == 2) { |
| 579 | *bufferAddr++ = (bits >> 16) & 0xffff; |
| 580 | } |
| 581 | *bufferAddr++ = bits & 0xffff; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 582 | } |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 583 | return false; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 587 | * Translation layout in the code cache. Note that the codeAddress pointer |
| 588 | * in JitTable will point directly to the code body (field codeAddress). The |
| 589 | * chain cell offset codeAddress - 2, and (if present) executionCount is at |
| 590 | * codeAddress - 6. |
| 591 | * |
| 592 | * +----------------------------+ |
| 593 | * | Execution count | -> [Optional] 4 bytes |
| 594 | * +----------------------------+ |
| 595 | * +--| Offset to chain cell counts| -> 2 bytes |
| 596 | * | +----------------------------+ |
| 597 | * | | Code body | -> Start address for translation |
| 598 | * | | | variable in 2-byte chunks |
| 599 | * | . . (JitTable's codeAddress points here) |
| 600 | * | . . |
| 601 | * | | | |
| 602 | * | +----------------------------+ |
| 603 | * | | Chaining Cells | -> 8 bytes each, must be 4 byte aligned |
| 604 | * | . . |
| 605 | * | . . |
| 606 | * | | | |
| 607 | * | +----------------------------+ |
| 608 | * +->| Chaining cell counts | -> 4 bytes, chain cell counts by type |
| 609 | * +----------------------------+ |
| 610 | * | Trace description | -> variable sized |
| 611 | * . . |
| 612 | * | | |
| 613 | * +----------------------------+ |
| 614 | * | Literal pool | -> 4-byte aligned, variable size |
| 615 | * . . |
| 616 | * . . |
| 617 | * | | |
| 618 | * +----------------------------+ |
| 619 | * |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 620 | * Go over each instruction in the list and calculate the offset from the top |
| 621 | * before sending them off to the assembler. If out-of-range branch distance is |
| 622 | * seen rearrange the instructions a bit to correct it. |
| 623 | */ |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 624 | void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info) |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 625 | { |
| 626 | LIR *lir; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 627 | ArmLIR *armLIR; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 628 | int offset = 0; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 629 | int i; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 630 | ChainCellCounts chainCellCounts; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 631 | int descSize = jitTraceDescriptionSize(cUnit->traceDesc); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 632 | |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 633 | info->codeAddress = NULL; |
| 634 | info->instructionSet = cUnit->instructionSet; |
| 635 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 636 | /* Beginning offset needs to allow space for chain cell offset */ |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 637 | for (armLIR = (ArmLIR *) cUnit->firstLIRInsn; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 638 | armLIR; |
| 639 | armLIR = NEXT_LIR(armLIR)) { |
| 640 | armLIR->generic.offset = offset; |
| Ben Cheng | e9695e5 | 2009-06-16 16:11:47 -0700 | [diff] [blame] | 641 | if (armLIR->opCode >= 0 && !armLIR->isNop) { |
| Bill Buzbee | 9bc3df3 | 2009-07-30 10:52:29 -0700 | [diff] [blame^] | 642 | armLIR->size = EncodingMap[armLIR->opCode].size * 2; |
| 643 | offset += armLIR->size; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 644 | } else if (armLIR->opCode == ARM_PSEUDO_ALIGN4) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 645 | if (offset & 0x2) { |
| 646 | offset += 2; |
| 647 | armLIR->operands[0] = 1; |
| 648 | } else { |
| 649 | armLIR->operands[0] = 0; |
| 650 | } |
| 651 | } |
| 652 | /* Pseudo opcodes don't consume space */ |
| 653 | } |
| 654 | |
| 655 | /* Const values have to be word aligned */ |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 656 | offset = (offset + 3) & ~3; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 657 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 658 | /* Add space for chain cell counts & trace description */ |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 659 | u4 chainCellOffset = offset; |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 660 | ArmLIR *chainCellOffsetLIR = (ArmLIR *) cUnit->chainCellOffsetLIR; |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 661 | assert(chainCellOffsetLIR); |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 662 | assert(chainCellOffset < 0x10000); |
| Bill Buzbee | 89efc3d | 2009-07-28 11:22:22 -0700 | [diff] [blame] | 663 | assert(chainCellOffsetLIR->opCode == ARM_16BIT_DATA && |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 664 | chainCellOffsetLIR->operands[0] == CHAIN_CELL_OFFSET_TAG); |
| 665 | |
| Ben Cheng | e80cd94 | 2009-07-17 15:54:23 -0700 | [diff] [blame] | 666 | /* |
| 667 | * Replace the CHAIN_CELL_OFFSET_TAG with the real value. If trace |
| 668 | * profiling is enabled, subtract 4 (occupied by the counter word) from |
| 669 | * the absolute offset as the value stored in chainCellOffsetLIR is the |
| 670 | * delta from &chainCellOffsetLIR to &ChainCellCounts. |
| 671 | */ |
| 672 | chainCellOffsetLIR->operands[0] = |
| 673 | gDvmJit.profile ? (chainCellOffset - 4) : chainCellOffset; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 674 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 675 | offset += sizeof(chainCellCounts) + descSize; |
| 676 | |
| 677 | assert((offset & 0x3) == 0); /* Should still be word aligned */ |
| 678 | |
| 679 | /* Set up offsets for literals */ |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 680 | cUnit->dataOffset = offset; |
| 681 | |
| 682 | for (lir = cUnit->wordList; lir; lir = lir->next) { |
| 683 | lir->offset = offset; |
| 684 | offset += 4; |
| 685 | } |
| 686 | |
| 687 | cUnit->totalSize = offset; |
| 688 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 689 | if (gDvmJit.codeCacheByteUsed + cUnit->totalSize > CODE_CACHE_SIZE) { |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 690 | gDvmJit.codeCacheFull = true; |
| 691 | cUnit->baseAddr = NULL; |
| 692 | return; |
| 693 | } |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 694 | |
| 695 | /* Allocate enough space for the code block */ |
| 696 | cUnit->codeBuffer = dvmCompilerNew(chainCellOffset, true); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 697 | if (cUnit->codeBuffer == NULL) { |
| 698 | LOGE("Code buffer allocation failure\n"); |
| 699 | cUnit->baseAddr = NULL; |
| 700 | return; |
| 701 | } |
| 702 | |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 703 | bool assemblerFailure = assembleInstructions( |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 704 | cUnit, (intptr_t) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed); |
| 705 | |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 706 | /* |
| 707 | * Currently the only reason that can cause the assembler to fail is due to |
| 708 | * trace length - cut it in half and retry. |
| 709 | */ |
| 710 | if (assemblerFailure) { |
| 711 | cUnit->halveInstCount = true; |
| 712 | return; |
| 713 | } |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 714 | |
| Bill Buzbee | 6e963e1 | 2009-06-17 16:56:19 -0700 | [diff] [blame] | 715 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 716 | cUnit->baseAddr = (char *) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed; |
| 717 | gDvmJit.codeCacheByteUsed += offset; |
| 718 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 719 | /* Install the code block */ |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 720 | memcpy((char*)cUnit->baseAddr, cUnit->codeBuffer, chainCellOffset); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 721 | gDvmJit.numCompilations++; |
| 722 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 723 | /* Install the chaining cell counts */ |
| 724 | for (i=0; i< CHAINING_CELL_LAST; i++) { |
| 725 | chainCellCounts.u.count[i] = cUnit->numChainingCells[i]; |
| 726 | } |
| 727 | memcpy((char*)cUnit->baseAddr + chainCellOffset, &chainCellCounts, |
| 728 | sizeof(chainCellCounts)); |
| 729 | |
| 730 | /* Install the trace description */ |
| 731 | memcpy((char*)cUnit->baseAddr + chainCellOffset + sizeof(chainCellCounts), |
| 732 | cUnit->traceDesc, descSize); |
| 733 | |
| 734 | /* Write the literals directly into the code cache */ |
| 735 | installDataContent(cUnit); |
| 736 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 737 | /* Flush dcache and invalidate the icache to maintain coherence */ |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 738 | cacheflush((long)cUnit->baseAddr, |
| Ben Cheng | e80cd94 | 2009-07-17 15:54:23 -0700 | [diff] [blame] | 739 | (long)((char *) cUnit->baseAddr + offset), 0); |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 740 | |
| 741 | /* Record code entry point and instruction set */ |
| 742 | info->codeAddress = (char*)cUnit->baseAddr + cUnit->headerSize; |
| 743 | info->instructionSet = cUnit->instructionSet; |
| 744 | /* If applicable, mark low bit to denote thumb */ |
| 745 | if (info->instructionSet != DALVIK_JIT_ARM) |
| 746 | info->codeAddress = (char*)info->codeAddress + 1; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 749 | static u4 assembleBXPair(int branchOffset) |
| 750 | { |
| 751 | u4 thumb1, thumb2; |
| 752 | |
| 753 | if ((branchOffset < -2048) | (branchOffset > 2046)) { |
| 754 | thumb1 = (0xf000 | ((branchOffset>>12) & 0x7ff)); |
| 755 | thumb2 = (0xf800 | ((branchOffset>> 1) & 0x7ff)); |
| 756 | } else { |
| 757 | thumb1 = (0xe000 | ((branchOffset>> 1) & 0x7ff)); |
| 758 | thumb2 = 0x4300; /* nop -> or r0, r0 */ |
| 759 | } |
| 760 | |
| 761 | return thumb2<<16 | thumb1; |
| 762 | } |
| 763 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 764 | /* |
| 765 | * Perform translation chain operation. |
| 766 | * For ARM, we'll use a pair of thumb instructions to generate |
| 767 | * an unconditional chaining branch of up to 4MB in distance. |
| 768 | * Use a BL, though we don't really need the link. The format is |
| 769 | * 111HHooooooooooo |
| 770 | * Where HH is 10 for the 1st inst, and 11 for the second and |
| 771 | * the "o" field is each instruction's 11-bit contribution to the |
| 772 | * 22-bit branch offset. |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 773 | * If the target is nearby, use a single-instruction bl. |
| 774 | * If one or more threads is suspended, don't chain. |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 775 | */ |
| 776 | void* dvmJitChain(void* tgtAddr, u4* branchAddr) |
| 777 | { |
| 778 | int baseAddr = (u4) branchAddr + 4; |
| 779 | int branchOffset = (int) tgtAddr - baseAddr; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 780 | u4 newInst; |
| 781 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 782 | if (gDvm.sumThreadSuspendCount == 0) { |
| 783 | assert((branchOffset >= -(1<<22)) && (branchOffset <= ((1<<22)-2))); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 784 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 785 | gDvmJit.translationChains++; |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 786 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 787 | COMPILER_TRACE_CHAINING( |
| 788 | LOGD("Jit Runtime: chaining 0x%x to 0x%x\n", |
| 789 | (int) branchAddr, (int) tgtAddr & -2)); |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 790 | |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 791 | newInst = assembleBXPair(branchOffset); |
| 792 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 793 | *branchAddr = newInst; |
| 794 | cacheflush((long)branchAddr, (long)branchAddr + 4, 0); |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| Ben Cheng | ba4fc8b | 2009-06-01 13:00:29 -0700 | [diff] [blame] | 797 | return tgtAddr; |
| 798 | } |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 799 | |
| 800 | /* |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 801 | * This method is called from the invoke templates for virtual and interface |
| 802 | * methods to speculatively setup a chain to the callee. The templates are |
| 803 | * written in assembly and have setup method, cell, and clazz at r0, r2, and |
| 804 | * r3 respectively, so there is a unused argument in the list. Upon return one |
| 805 | * of the following three results may happen: |
| 806 | * 1) Chain is not setup because the callee is native. Reset the rechain |
| 807 | * count to a big number so that it will take a long time before the next |
| 808 | * rechain attempt to happen. |
| 809 | * 2) Chain is not setup because the callee has not been created yet. Reset |
| 810 | * the rechain count to a small number and retry in the near future. |
| 811 | * 3) Ask all other threads to stop before patching this chaining cell. |
| 812 | * This is required because another thread may have passed the class check |
| 813 | * but hasn't reached the chaining cell yet to follow the chain. If we |
| 814 | * patch the content before halting the other thread, there could be a |
| 815 | * small window for race conditions to happen that it may follow the new |
| 816 | * but wrong chain to invoke a different method. |
| 817 | */ |
| 818 | const Method *dvmJitToPatchPredictedChain(const Method *method, |
| 819 | void *unused, |
| 820 | PredictedChainingCell *cell, |
| 821 | const ClassObject *clazz) |
| 822 | { |
| 823 | /* Don't come back here for a long time if the method is native */ |
| 824 | if (dvmIsNativeMethod(method)) { |
| 825 | cell->counter = PREDICTED_CHAIN_COUNTER_AVOID; |
| 826 | cacheflush((long) cell, (long) (cell+1), 0); |
| 827 | COMPILER_TRACE_CHAINING( |
| 828 | LOGD("Jit Runtime: predicted chain %p to native method %s ignored", |
| 829 | cell, method->name)); |
| 830 | goto done; |
| 831 | } |
| 832 | int tgtAddr = (int) dvmJitGetCodeAddr(method->insns); |
| 833 | |
| 834 | /* |
| 835 | * Compilation not made yet for the callee. Reset the counter to a small |
| 836 | * value and come back to check soon. |
| 837 | */ |
| 838 | if (tgtAddr == 0) { |
| 839 | /* |
| 840 | * Wait for a few invocations (currently set to be 16) before trying |
| 841 | * to setup the chain again. |
| 842 | */ |
| 843 | cell->counter = PREDICTED_CHAIN_COUNTER_DELAY; |
| 844 | cacheflush((long) cell, (long) (cell+1), 0); |
| 845 | COMPILER_TRACE_CHAINING( |
| 846 | LOGD("Jit Runtime: predicted chain %p to method %s delayed", |
| 847 | cell, method->name)); |
| 848 | goto done; |
| 849 | } |
| 850 | |
| 851 | /* Stop the world */ |
| 852 | dvmSuspendAllThreads(SUSPEND_FOR_JIT); |
| 853 | |
| 854 | int baseAddr = (int) cell + 4; // PC is cur_addr + 4 |
| 855 | int branchOffset = tgtAddr - baseAddr; |
| 856 | |
| 857 | COMPILER_TRACE_CHAINING( |
| 858 | LOGD("Jit Runtime: predicted chain %p from %s to %s (%s) patched", |
| 859 | cell, cell->clazz ? cell->clazz->descriptor : "NULL", |
| 860 | clazz->descriptor, |
| 861 | method->name)); |
| 862 | |
| 863 | cell->branch = assembleBXPair(branchOffset); |
| 864 | cell->clazz = clazz; |
| 865 | cell->method = method; |
| 866 | cell->counter = PREDICTED_CHAIN_COUNTER_RECHAIN; |
| 867 | |
| 868 | cacheflush((long) cell, (long) (cell+1), 0); |
| 869 | |
| 870 | /* All done - resume all other threads */ |
| 871 | dvmResumeAllThreads(SUSPEND_FOR_JIT); |
| 872 | |
| 873 | done: |
| 874 | return method; |
| 875 | } |
| 876 | |
| 877 | /* |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 878 | * Unchain a trace given the starting address of the translation |
| 879 | * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR. |
| 880 | * Returns the address following the last cell unchained. Note that |
| 881 | * the incoming codeAddr is a thumb code address, and therefore has |
| 882 | * the low bit set. |
| 883 | */ |
| 884 | u4* dvmJitUnchain(void* codeAddr) |
| 885 | { |
| 886 | u2* pChainCellOffset = (u2*)((char*)codeAddr - 3); |
| 887 | u2 chainCellOffset = *pChainCellOffset; |
| 888 | ChainCellCounts *pChainCellCounts = |
| Ben Cheng | e80cd94 | 2009-07-17 15:54:23 -0700 | [diff] [blame] | 889 | (ChainCellCounts*)((char*)codeAddr + chainCellOffset - 3); |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 890 | int cellSize; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 891 | u4* pChainCells; |
| 892 | u4* pStart; |
| 893 | u4 thumb1; |
| 894 | u4 thumb2; |
| 895 | u4 newInst; |
| 896 | int i,j; |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 897 | PredictedChainingCell *predChainCell; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 898 | |
| 899 | /* Get total count of chain cells */ |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 900 | for (i = 0, cellSize = 0; i < CHAINING_CELL_LAST; i++) { |
| 901 | if (i != CHAINING_CELL_INVOKE_PREDICTED) { |
| 902 | cellSize += pChainCellCounts->u.count[i] * 2; |
| 903 | } else { |
| 904 | cellSize += pChainCellCounts->u.count[i] * 4; |
| 905 | } |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | /* Locate the beginning of the chain cell region */ |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 909 | pStart = pChainCells = ((u4 *) pChainCellCounts) - cellSize; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 910 | |
| 911 | /* The cells are sorted in order - walk through them and reset */ |
| 912 | for (i = 0; i < CHAINING_CELL_LAST; i++) { |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 913 | int elemSize = 2; /* Most chaining cell has two words */ |
| 914 | if (i == CHAINING_CELL_INVOKE_PREDICTED) { |
| 915 | elemSize = 4; |
| 916 | } |
| 917 | |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 918 | for (j = 0; j < pChainCellCounts->u.count[i]; j++) { |
| 919 | int targetOffset; |
| 920 | switch(i) { |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 921 | case CHAINING_CELL_NORMAL: |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 922 | targetOffset = offsetof(InterpState, |
| 923 | jitToInterpEntries.dvmJitToInterpNormal); |
| 924 | break; |
| Ben Cheng | 1efc9c5 | 2009-06-08 18:25:27 -0700 | [diff] [blame] | 925 | case CHAINING_CELL_HOT: |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 926 | case CHAINING_CELL_INVOKE_SINGLETON: |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 927 | targetOffset = offsetof(InterpState, |
| 928 | jitToInterpEntries.dvmJitToTraceSelect); |
| 929 | break; |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 930 | case CHAINING_CELL_INVOKE_PREDICTED: |
| 931 | targetOffset = 0; |
| 932 | predChainCell = (PredictedChainingCell *) pChainCells; |
| 933 | /* Reset the cell to the init state */ |
| 934 | predChainCell->branch = PREDICTED_CHAIN_BX_PAIR_INIT; |
| 935 | predChainCell->clazz = PREDICTED_CHAIN_CLAZZ_INIT; |
| 936 | predChainCell->method = PREDICTED_CHAIN_METHOD_INIT; |
| 937 | predChainCell->counter = PREDICTED_CHAIN_COUNTER_INIT; |
| 938 | break; |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 939 | default: |
| 940 | dvmAbort(); |
| 941 | } |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 942 | COMPILER_TRACE_CHAINING( |
| 943 | LOGD("Jit Runtime: unchaining 0x%x", (int)pChainCells)); |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 944 | /* |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 945 | * Thumb code sequence for a chaining cell is: |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 946 | * ldr r0, rGLUE, #<word offset> |
| 947 | * blx r0 |
| 948 | */ |
| Ben Cheng | 38329f5 | 2009-07-07 14:19:20 -0700 | [diff] [blame] | 949 | if (i != CHAINING_CELL_INVOKE_PREDICTED) { |
| 950 | targetOffset = targetOffset >> 2; /* convert to word offset */ |
| 951 | thumb1 = 0x6800 | (targetOffset << 6) | |
| 952 | (rGLUE << 3) | (r0 << 0); |
| 953 | thumb2 = 0x4780 | (r0 << 3); |
| 954 | newInst = thumb2<<16 | thumb1; |
| 955 | *pChainCells = newInst; |
| 956 | } |
| 957 | pChainCells += elemSize; /* Advance by a fixed number of words */ |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | return pChainCells; |
| 961 | } |
| 962 | |
| 963 | /* Unchain all translation in the cache. */ |
| 964 | void dvmJitUnchainAll() |
| 965 | { |
| 966 | u4* lowAddress = NULL; |
| 967 | u4* highAddress = NULL; |
| 968 | unsigned int i; |
| 969 | if (gDvmJit.pJitEntryTable != NULL) { |
| 970 | COMPILER_TRACE_CHAINING(LOGD("Jit Runtime: unchaining all")); |
| 971 | dvmLockMutex(&gDvmJit.tableLock); |
| Bill Buzbee | 2717622 | 2009-06-09 09:20:16 -0700 | [diff] [blame] | 972 | for (i = 0; i < gDvmJit.jitTableSize; i++) { |
| Bill Buzbee | 46cd5b6 | 2009-06-05 15:36:06 -0700 | [diff] [blame] | 973 | if (gDvmJit.pJitEntryTable[i].dPC && |
| 974 | gDvmJit.pJitEntryTable[i].codeAddress) { |
| 975 | u4* lastAddress; |
| 976 | lastAddress = |
| 977 | dvmJitUnchain(gDvmJit.pJitEntryTable[i].codeAddress); |
| 978 | if (lowAddress == NULL || |
| 979 | (u4*)gDvmJit.pJitEntryTable[i].codeAddress < lowAddress) |
| 980 | lowAddress = lastAddress; |
| 981 | if (lastAddress > highAddress) |
| 982 | highAddress = lastAddress; |
| 983 | } |
| 984 | } |
| 985 | cacheflush((long)lowAddress, (long)highAddress, 0); |
| 986 | dvmUnlockMutex(&gDvmJit.tableLock); |
| 987 | } |
| 988 | } |
| Bill Buzbee | 716f120 | 2009-07-23 13:22:09 -0700 | [diff] [blame] | 989 | |
| 990 | typedef struct jitProfileAddrToLine { |
| 991 | u4 lineNum; |
| 992 | u4 bytecodeOffset; |
| 993 | } jitProfileAddrToLine; |
| 994 | |
| 995 | |
| 996 | /* Callback function to track the bytecode offset/line number relationiship */ |
| 997 | static int addrToLineCb (void *cnxt, u4 bytecodeOffset, u4 lineNum) |
| 998 | { |
| 999 | jitProfileAddrToLine *addrToLine = (jitProfileAddrToLine *) cnxt; |
| 1000 | |
| 1001 | /* Best match so far for this offset */ |
| 1002 | if (addrToLine->bytecodeOffset >= bytecodeOffset) { |
| 1003 | addrToLine->lineNum = lineNum; |
| 1004 | } |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
| 1008 | char *getTraceBase(const JitEntry *p) |
| 1009 | { |
| 1010 | return (char*)p->codeAddress - |
| 1011 | (6 + (p->u.info.instructionSet == DALVIK_JIT_ARM ? 0 : 1)); |
| 1012 | } |
| 1013 | |
| 1014 | /* Dumps profile info for a single trace */ |
| 1015 | static int dumpTraceProfile(JitEntry *p) |
| 1016 | { |
| 1017 | ChainCellCounts* pCellCounts; |
| 1018 | char* traceBase; |
| 1019 | u4* pExecutionCount; |
| 1020 | u2* pCellOffset; |
| 1021 | JitTraceDescription *desc; |
| 1022 | const Method* method; |
| 1023 | |
| 1024 | traceBase = getTraceBase(p); |
| 1025 | |
| 1026 | if (p->codeAddress == NULL) { |
| 1027 | LOGD("TRACEPROFILE 0x%08x 0 NULL 0 0", (int)traceBase); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | pExecutionCount = (u4*) (traceBase); |
| 1032 | pCellOffset = (u2*) (traceBase + 4); |
| 1033 | pCellCounts = (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset); |
| 1034 | desc = (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts)); |
| 1035 | method = desc->method; |
| 1036 | char *methodDesc = dexProtoCopyMethodDescriptor(&method->prototype); |
| 1037 | jitProfileAddrToLine addrToLine = {0, desc->trace[0].frag.startOffset}; |
| 1038 | |
| 1039 | /* |
| 1040 | * We may end up decoding the debug information for the same method |
| 1041 | * multiple times, but the tradeoff is we don't need to allocate extra |
| 1042 | * space to store the addr/line mapping. Since this is a debugging feature |
| 1043 | * and done infrequently so the slower but simpler mechanism should work |
| 1044 | * just fine. |
| 1045 | */ |
| 1046 | dexDecodeDebugInfo(method->clazz->pDvmDex->pDexFile, |
| 1047 | dvmGetMethodCode(method), |
| 1048 | method->clazz->descriptor, |
| 1049 | method->prototype.protoIdx, |
| 1050 | method->accessFlags, |
| 1051 | addrToLineCb, NULL, &addrToLine); |
| 1052 | |
| 1053 | LOGD("TRACEPROFILE 0x%08x % 10d [%#x(+%d), %d] %s%s;%s", |
| 1054 | (int)traceBase, |
| 1055 | *pExecutionCount, |
| 1056 | desc->trace[0].frag.startOffset, |
| 1057 | desc->trace[0].frag.numInsts, |
| 1058 | addrToLine.lineNum, |
| 1059 | method->clazz->descriptor, method->name, methodDesc); |
| 1060 | free(methodDesc); |
| 1061 | |
| 1062 | return *pExecutionCount; |
| 1063 | } |
| 1064 | |
| 1065 | /* Handy function to retrieve the profile count */ |
| 1066 | static inline int getProfileCount(const JitEntry *entry) |
| 1067 | { |
| 1068 | if (entry->dPC == 0 || entry->codeAddress == 0) |
| 1069 | return 0; |
| 1070 | u4 *pExecutionCount = (u4 *) getTraceBase(entry); |
| 1071 | |
| 1072 | return *pExecutionCount; |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | /* qsort callback function */ |
| 1077 | static int sortTraceProfileCount(const void *entry1, const void *entry2) |
| 1078 | { |
| 1079 | const JitEntry *jitEntry1 = entry1; |
| 1080 | const JitEntry *jitEntry2 = entry2; |
| 1081 | |
| 1082 | int count1 = getProfileCount(jitEntry1); |
| 1083 | int count2 = getProfileCount(jitEntry2); |
| 1084 | return (count1 == count2) ? 0 : ((count1 > count2) ? -1 : 1); |
| 1085 | } |
| 1086 | |
| 1087 | /* Sort the trace profile counts and dump them */ |
| 1088 | void dvmCompilerSortAndPrintTraceProfiles() |
| 1089 | { |
| 1090 | JitEntry *sortedEntries; |
| 1091 | int numTraces = 0; |
| 1092 | unsigned long counts = 0; |
| 1093 | unsigned int i; |
| 1094 | |
| 1095 | /* Make sure that the table is not changing */ |
| 1096 | dvmLockMutex(&gDvmJit.tableLock); |
| 1097 | |
| 1098 | /* Sort the entries by descending order */ |
| 1099 | sortedEntries = malloc(sizeof(JitEntry) * gDvmJit.jitTableSize); |
| 1100 | if (sortedEntries == NULL) |
| 1101 | goto done; |
| 1102 | memcpy(sortedEntries, gDvmJit.pJitEntryTable, |
| 1103 | sizeof(JitEntry) * gDvmJit.jitTableSize); |
| 1104 | qsort(sortedEntries, gDvmJit.jitTableSize, sizeof(JitEntry), |
| 1105 | sortTraceProfileCount); |
| 1106 | |
| 1107 | /* Dump the sorted entries */ |
| 1108 | for (i=0; i < gDvmJit.jitTableSize; i++) { |
| 1109 | if (sortedEntries[i].dPC != 0) { |
| 1110 | counts += dumpTraceProfile(&sortedEntries[i]); |
| 1111 | numTraces++; |
| 1112 | } |
| 1113 | } |
| 1114 | if (numTraces == 0) |
| 1115 | numTraces = 1; |
| 1116 | LOGD("JIT: Average execution count -> %d",(int)(counts / numTraces)); |
| 1117 | |
| 1118 | free(sortedEntries); |
| 1119 | done: |
| 1120 | dvmUnlockMutex(&gDvmJit.tableLock); |
| 1121 | return; |
| 1122 | } |