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