blob: 144a416592f930fe26ed3e05b9a4e3c500098b80 [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
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 Buzbee89efc3d2009-07-28 11:22:22 -070022#include "ArmLIR.h"
Ben Chengba4fc8b2009-06-01 13:00:29 -070023#include <unistd.h> /* for cacheflush */
24
25/*
Bill Buzbee89efc3d2009-07-28 11:22:22 -070026 * opcode: ArmOpCode enum
Ben Chengba4fc8b2009-06-01 13:00:29 -070027 * skeleton: pre-designated bit-pattern for this opcode
Bill Buzbee9bc3df32009-07-30 10:52:29 -070028 * k0: key to applying ds/de
Ben Chengba4fc8b2009-06-01 13:00:29 -070029 * ds: dest start bit position
30 * de: dest end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070031 * k1: key to applying s1s/s1e
Ben Chengba4fc8b2009-06-01 13:00:29 -070032 * s1s: src1 start bit position
33 * s1e: src1 end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070034 * k2: key to applying s2s/s2e
Ben Chengba4fc8b2009-06-01 13:00:29 -070035 * 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 Buzbee9bc3df32009-07-30 10:52:29 -070041#define ENCODING_MAP(opcode, skeleton, k0, ds, de, k1, s1s, s1e, k2, s2s, s2e, \
Bill Buzbee270c1d62009-08-13 16:58:07 -070042 k3, k3s, k3e, operands, name, fmt, size) \
43 {skeleton, {{k0, ds, de}, {k1, s1s, s1e}, {k2, s2s, s2e}, \
44 {k3, k3s, k3e}}, opcode, operands, name, fmt, size}
Ben Chengba4fc8b2009-06-01 13:00:29 -070045
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)
Bill Buzbee270c1d62009-08-13 16:58:07 -070054 * 3 -> operands[3] (extra)
Ben Chengba4fc8b2009-06-01 13:00:29 -070055 *
56 * [f]ormats:
57 * h -> 4-digit hex
58 * d -> decimal
59 * D -> decimal+8 (used to convert 3-bit regnum field to high reg)
60 * E -> decimal*4
61 * F -> decimal*2
62 * c -> branch condition (beq, bne, etc.)
63 * t -> pc-relative target
64 * u -> 1st half of bl[x] target
65 * v -> 2nd half ob bl[x] target
66 * R -> register list
Bill Buzbee9727c3d2009-08-01 11:32:36 -070067 * s -> single precision floating point register
68 * S -> double precision floating point register
Bill Buzbee7ea0f642009-08-10 17:06:51 -070069 * m -> Thumb2 modified immediate
Bill Buzbee270c1d62009-08-13 16:58:07 -070070 * n -> complimented Thumb2 modified immediate
Bill Buzbee7ea0f642009-08-10 17:06:51 -070071 * M -> Thumb2 16-bit zero-extended immediate
Ben Chengba4fc8b2009-06-01 13:00:29 -070072 *
73 * [!] escape. To insert "!", use "!!"
74 */
Bill Buzbee89efc3d2009-07-28 11:22:22 -070075/* NOTE: must be kept in sync with enum ArmOpcode from ArmLIR.h */
76ArmEncodingMap EncodingMap[ARM_LAST] = {
Bill Buzbee9bc3df32009-07-30 10:52:29 -070077 ENCODING_MAP(ARM_16BIT_DATA, 0x0000,
Bill Buzbee270c1d62009-08-13 16:58:07 -070078 BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -070079 IS_UNARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -070080 "data", "0x!0h(!0d)", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -070081 ENCODING_MAP(THUMB_ADC, 0x4140,
Bill Buzbee270c1d62009-08-13 16:58:07 -070082 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
83 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES | USES_CCODES,
84 "adcs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -070085 ENCODING_MAP(THUMB_ADD_RRI3, 0x1c00,
Bill Buzbee270c1d62009-08-13 16:58:07 -070086 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
87 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
88 "adds", "r!0d, r!1d, #!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -070089 ENCODING_MAP(THUMB_ADD_RI8, 0x3000,
Bill Buzbee270c1d62009-08-13 16:58:07 -070090 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
91 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
92 "adds", "r!0d, r!0d, #!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -070093 ENCODING_MAP(THUMB_ADD_RRR, 0x1800,
Bill Buzbee270c1d62009-08-13 16:58:07 -070094 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
95 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
96 "adds", "r!0d, r!1d, r!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -070097 ENCODING_MAP(THUMB_ADD_RR_LH, 0x4440,
Bill Buzbee270c1d62009-08-13 16:58:07 -070098 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -070099 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700100 "add", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700101 ENCODING_MAP(THUMB_ADD_RR_HL, 0x4480,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700102 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700103 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700104 "add", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700105 ENCODING_MAP(THUMB_ADD_RR_HH, 0x44c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700106 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700107 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700108 "add", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700109 ENCODING_MAP(THUMB_ADD_PC_REL, 0xa000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700110 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Cheng38329f52009-07-07 14:19:20 -0700111 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700112 "add", "r!0d, pc, #!1E", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700113 ENCODING_MAP(THUMB_ADD_SP_REL, 0xa800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700114 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700115 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700116 "add", "r!0d, sp, #!1E", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700117 ENCODING_MAP(THUMB_ADD_SPI7, 0xb000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700118 BITBLT, 6, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700119 IS_UNARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700120 "add", "sp, #!0d*4", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700121 ENCODING_MAP(THUMB_AND_RR, 0x4000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700122 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
123 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
124 "ands", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700125 ENCODING_MAP(THUMB_ASR, 0x1000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700126 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
127 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
128 "asrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700129 ENCODING_MAP(THUMB_ASRV, 0x4100,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700130 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
131 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
132 "asrs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700133 ENCODING_MAP(THUMB_B_COND, 0xd000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700134 BITBLT, 7, 0, BITBLT, 11, 8, UNUSED, -1, -1, UNUSED, -1, -1,
135 IS_BINARY_OP | IS_BRANCH | USES_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700136 "!1c", "!0t", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700137 ENCODING_MAP(THUMB_B_UNCOND, 0xe000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700138 BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700139 NO_OPERAND | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700140 "b", "!0t", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700141 ENCODING_MAP(THUMB_BIC, 0x4380,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700142 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
143 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
144 "bics", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700145 ENCODING_MAP(THUMB_BKPT, 0xbe00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700146 BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700147 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700148 "bkpt", "!0d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700149 ENCODING_MAP(THUMB_BLX_1, 0xf000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700150 BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700151 IS_BINARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700152 "blx_1", "!0u", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700153 ENCODING_MAP(THUMB_BLX_2, 0xe800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700154 BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700155 IS_BINARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700156 "blx_2", "!0v", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700157 ENCODING_MAP(THUMB_BL_1, 0xf000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700158 BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700159 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700160 "bl_1", "!0u", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700161 ENCODING_MAP(THUMB_BL_2, 0xf800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700162 BITBLT, 10, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700163 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700164 "bl_2", "!0v", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700165 ENCODING_MAP(THUMB_BLX_R, 0x4780,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700166 BITBLT, 6, 3, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700167 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700168 "blx", "r!0d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700169 ENCODING_MAP(THUMB_BX, 0x4700,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700170 BITBLT, 6, 3, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700171 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700172 "bx", "r!0d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700173 ENCODING_MAP(THUMB_CMN, 0x42c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700174 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
175 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700176 "cmn", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700177 ENCODING_MAP(THUMB_CMP_RI8, 0x2800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700178 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
179 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700180 "cmp", "r!0d, #!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700181 ENCODING_MAP(THUMB_CMP_RR, 0x4280,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700182 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
183 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700184 "cmp", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700185 ENCODING_MAP(THUMB_CMP_LH, 0x4540,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700186 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
187 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700188 "cmp", "r!0d, r!1D", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700189 ENCODING_MAP(THUMB_CMP_HL, 0x4580,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700190 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
191 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700192 "cmp", "r!0D, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700193 ENCODING_MAP(THUMB_CMP_HH, 0x45c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700194 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
195 IS_BINARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700196 "cmp", "r!0D, r!1D", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700197 ENCODING_MAP(THUMB_EOR, 0x4040,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700198 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
199 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
200 "eors", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700201 ENCODING_MAP(THUMB_LDMIA, 0xc800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700202 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700203 IS_BINARY_OP | CLOBBER_DEST | CLOBBER_SRC1,
Bill Buzbee716f1202009-07-23 13:22:09 -0700204 "ldmia", "r!0d!!, <!1R>", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700205 ENCODING_MAP(THUMB_LDR_RRI5, 0x6800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700206 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700207 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700208 "ldr", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700209 ENCODING_MAP(THUMB_LDR_RRR, 0x5800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700210 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700211 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700212 "ldr", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700213 ENCODING_MAP(THUMB_LDR_PC_REL, 0x4800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700214 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Cheng38329f52009-07-07 14:19:20 -0700215 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700216 "ldr", "r!0d, [pc, #!1E]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700217 ENCODING_MAP(THUMB_LDR_SP_REL, 0x9800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700218 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
219 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700220 "ldr", "r!0d, [sp, #!1E]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700221 ENCODING_MAP(THUMB_LDRB_RRI5, 0x7800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700222 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700223 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700224 "ldrb", "r!0d, [r!1d, #2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700225 ENCODING_MAP(THUMB_LDRB_RRR, 0x5c00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700226 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700227 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700228 "ldrb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700229 ENCODING_MAP(THUMB_LDRH_RRI5, 0x8800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700230 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700231 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700232 "ldrh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700233 ENCODING_MAP(THUMB_LDRH_RRR, 0x5a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700234 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700235 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700236 "ldrh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700237 ENCODING_MAP(THUMB_LDRSB_RRR, 0x5600,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700238 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700239 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700240 "ldrsb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700241 ENCODING_MAP(THUMB_LDRSH_RRR, 0x5e00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700242 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700243 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700244 "ldrsh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700245 ENCODING_MAP(THUMB_LSL, 0x0000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700246 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
247 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
248 "lsls", "r!0d, r!1d, #!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700249 ENCODING_MAP(THUMB_LSLV, 0x4080,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700250 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
251 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
252 "lsls", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700253 ENCODING_MAP(THUMB_LSR, 0x0800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700254 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
255 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
256 "lsrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700257 ENCODING_MAP(THUMB_LSRV, 0x40c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700258 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
259 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
260 "lsrs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700261 ENCODING_MAP(THUMB_MOV_IMM, 0x2000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700262 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
263 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
264 "movs", "r!0d, #!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700265 ENCODING_MAP(THUMB_MOV_RR, 0x1c00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700266 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
267 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
268 "movs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700269 ENCODING_MAP(THUMB_MOV_RR_H2H, 0x46c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700270 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700271 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700272 "mov", "r!0D, r!1D", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700273 ENCODING_MAP(THUMB_MOV_RR_H2L, 0x4640,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700274 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Cheng38329f52009-07-07 14:19:20 -0700275 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700276 "mov", "r!0d, r!1D", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700277 ENCODING_MAP(THUMB_MOV_RR_L2H, 0x4680,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700278 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Cheng38329f52009-07-07 14:19:20 -0700279 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700280 "mov", "r!0D, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700281 ENCODING_MAP(THUMB_MUL, 0x4340,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700282 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
283 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
284 "muls", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700285 ENCODING_MAP(THUMB_MVN, 0x43c0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700286 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
287 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
288 "mvns", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700289 ENCODING_MAP(THUMB_NEG, 0x4240,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700290 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
291 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
292 "negs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700293 ENCODING_MAP(THUMB_ORR, 0x4300,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700294 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
295 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
296 "orrs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700297 ENCODING_MAP(THUMB_POP, 0xbc00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700298 BITBLT, 8, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700299 IS_UNARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700300 "pop", "<!0R>", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700301 ENCODING_MAP(THUMB_PUSH, 0xb400,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700302 BITBLT, 8, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700303 IS_UNARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700304 "push", "<!0R>", 1),
Bill Buzbee270c1d62009-08-13 16:58:07 -0700305 ENCODING_MAP(THUMB_RORV, 0x41c0,
306 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
307 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
308 "rors", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700309 ENCODING_MAP(THUMB_SBC, 0x4180,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700310 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
311 IS_BINARY_OP | CLOBBER_DEST | USES_CCODES | SETS_CCODES,
312 "sbcs", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700313 ENCODING_MAP(THUMB_STMIA, 0xc000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700314 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700315 IS_BINARY_OP | CLOBBER_SRC1,
Bill Buzbee716f1202009-07-23 13:22:09 -0700316 "stmia", "r!0d!!, <!1R>", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700317 ENCODING_MAP(THUMB_STR_RRI5, 0x6000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700318 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700319 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700320 "str", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700321 ENCODING_MAP(THUMB_STR_RRR, 0x5000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700322 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700323 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700324 "str", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700325 ENCODING_MAP(THUMB_STR_SP_REL, 0x9000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700326 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700327 IS_BINARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700328 "str", "r!0d, [sp, #!1E]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700329 ENCODING_MAP(THUMB_STRB_RRI5, 0x7000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700330 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700331 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700332 "strb", "r!0d, [r!1d, #!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700333 ENCODING_MAP(THUMB_STRB_RRR, 0x5400,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700334 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700335 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700336 "strb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700337 ENCODING_MAP(THUMB_STRH_RRI5, 0x8000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700338 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 10, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700339 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700340 "strh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700341 ENCODING_MAP(THUMB_STRH_RRR, 0x5200,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700342 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700343 IS_TERTIARY_OP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700344 "strh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700345 ENCODING_MAP(THUMB_SUB_RRI3, 0x1e00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700346 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
347 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
348 "subs", "r!0d, r!1d, #!2d]", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700349 ENCODING_MAP(THUMB_SUB_RI8, 0x3800,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700350 BITBLT, 10, 8, BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1,
351 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
352 "subs", "r!0d, #!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700353 ENCODING_MAP(THUMB_SUB_RRR, 0x1a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700354 BITBLT, 2, 0, BITBLT, 5, 3, BITBLT, 8, 6, UNUSED, -1, -1,
355 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
356 "subs", "r!0d, r!1d, r!2d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700357 ENCODING_MAP(THUMB_SUB_SPI7, 0xb080,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700358 BITBLT, 6, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700359 IS_UNARY_OP | CLOBBER_DEST,
Bill Buzbee716f1202009-07-23 13:22:09 -0700360 "sub", "sp, #!0d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700361 ENCODING_MAP(THUMB_SWI, 0xdf00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700362 BITBLT, 7, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Ben Chenge9695e52009-06-16 16:11:47 -0700363 IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700364 "swi", "!0d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700365 ENCODING_MAP(THUMB_TST, 0x4200,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700366 BITBLT, 2, 0, BITBLT, 5, 3, UNUSED, -1, -1, UNUSED, -1, -1,
367 IS_UNARY_OP | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700368 "tst", "r!0d, r!1d", 1),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700369 ENCODING_MAP(THUMB2_VLDRS, 0xed900a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700370 SFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700371 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700372 "vldr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700373 ENCODING_MAP(THUMB2_VLDRD, 0xed900b00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700374 DFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700375 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700376 "vldr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700377 ENCODING_MAP(THUMB2_VMULS, 0xee200a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700378 SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700379 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700380 "vmuls", "!0s, !1s, !2s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700381 ENCODING_MAP(THUMB2_VMULD, 0xee200b00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700382 DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700383 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700384 "vmuld", "!0S, !1S, !2S", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700385 ENCODING_MAP(THUMB2_VSTRS, 0xed800a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700386 SFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, UNUSED, -1, -1,
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700387 IS_TERTIARY_OP,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700388 "vstr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700389 ENCODING_MAP(THUMB2_VSTRD, 0xed800b00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700390 DFP, 22, 12, BITBLT, 19, 16, BITBLT, 7, 0, UNUSED, -1, -1,
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700391 IS_TERTIARY_OP,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700392 "vstr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700393 ENCODING_MAP(THUMB2_VSUBS, 0xee300a40,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700394 SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700395 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700396 "vsub", "!0s, !1s, !2s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700397 ENCODING_MAP(THUMB2_VSUBD, 0xee300b40,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700398 DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700399 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700400 "vsub", "!0S, !1S, !2S", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700401 ENCODING_MAP(THUMB2_VADDS, 0xee300a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700402 SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700403 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700404 "vadd", "!0s, !1s, !2s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700405 ENCODING_MAP(THUMB2_VADDD, 0xee300b00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700406 DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700407 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700408 "vadd", "!0S, !1S, !2S", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700409 ENCODING_MAP(THUMB2_VDIVS, 0xee800a00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700410 SFP, 22, 12, SFP, 7, 16, SFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700411 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700412 "vdivs", "!0s, !1s, !2s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700413 ENCODING_MAP(THUMB2_VDIVD, 0xee800b00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700414 DFP, 22, 12, DFP, 7, 16, DFP, 5, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700415 IS_TERTIARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700416 "vdivs", "!0S, !1S, !2S", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700417 ENCODING_MAP(THUMB2_VCVTIF, 0xeeb80ac0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700418 SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700419 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700420 "vcvt.f32", "!0s, !1s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700421 ENCODING_MAP(THUMB2_VCVTID, 0xeeb80bc0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700422 DFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700423 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700424 "vcvt.f64", "!0S, !1s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700425 ENCODING_MAP(THUMB2_VCVTFI, 0xeebd0ac0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700426 SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700427 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700428 "vcvt.s32.f32 ", "!0s, !1s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700429 ENCODING_MAP(THUMB2_VCVTDI, 0xeebd0bc0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700430 SFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700431 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700432 "vcvt.s32.f64 ", "!0s, !1S", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700433 ENCODING_MAP(THUMB2_VCVTFD, 0xeeb70ac0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700434 DFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700435 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700436 "vcvt.f64.f32 ", "!0S, !1s", 2),
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700437 ENCODING_MAP(THUMB2_VCVTDF, 0xeeb70bc0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700438 SFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700439 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700440 "vcvt.f32.f64 ", "!0s, !1S", 2),
441 ENCODING_MAP(THUMB2_VSQRTS, 0xeeb10ac0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700442 SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700443 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700444 "vsqrt.f32 ", "!0s, !1s", 2),
445 ENCODING_MAP(THUMB2_VSQRTD, 0xeeb10bc0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700446 DFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700447 IS_BINARY_OP | CLOBBER_DEST,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700448 "vsqrt.f64 ", "!0S, !1S", 2),
Bill Buzbee270c1d62009-08-13 16:58:07 -0700449 ENCODING_MAP(THUMB2_MOV_IMM_SHIFT, 0xf04f0000, /* no setflags encoding */
450 BITBLT, 11, 8, MODIMM, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700451 IS_BINARY_OP | CLOBBER_DEST,
452 "mov", "r!0d, #!1m", 2),
453 ENCODING_MAP(THUMB2_MOV_IMM16, 0xf2400000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700454 BITBLT, 11, 8, IMM16, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700455 IS_BINARY_OP | CLOBBER_DEST,
456 "mov", "r!0d, #!1M", 2),
457 ENCODING_MAP(THUMB2_STR_RRI12, 0xf8c00000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700458 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700459 IS_TERTIARY_OP,
460 "str", "r!0d,[r!1d, #!2d", 2),
461 ENCODING_MAP(THUMB2_LDR_RRI12, 0xf8d00000,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700462 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700463 IS_TERTIARY_OP | CLOBBER_DEST,
464 "ldr", "r!0d,[r!1d, #!2d", 2),
465 ENCODING_MAP(THUMB2_STR_RRI8_PREDEC, 0xf8400c00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700466 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 8, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700467 IS_TERTIARY_OP,
468 "str", "r!0d,[r!1d, #-!2d]", 2),
469 ENCODING_MAP(THUMB2_LDR_RRI8_PREDEC, 0xf8500c00,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700470 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 8, 0, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700471 IS_TERTIARY_OP | CLOBBER_DEST,
472 "ldr", "r!0d,[r!1d, #-!2d]", 2),
473 ENCODING_MAP(THUMB2_CBNZ, 0xb900,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700474 BITBLT, 2, 0, IMM6, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
475 IS_BINARY_OP, /* Note: does not affect flags */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700476 "cbnz", "r!0d,!1t", 1),
477 ENCODING_MAP(THUMB2_CBZ, 0xb100,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700478 BITBLT, 2, 0, IMM6, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
479 IS_BINARY_OP, /* Note: does not affect flags */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700480 "cbz", "r!0d,!1t", 1),
Bill Buzbee270c1d62009-08-13 16:58:07 -0700481 ENCODING_MAP(THUMB2_ADD_RRI12, 0xf2000000,
482 BITBLT, 11, 8, BITBLT, 19, 16, IMM12, -1, -1, UNUSED, -1, -1,
483 IS_TERTIARY_OP | CLOBBER_DEST,/* Note: doesn't affect flags */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700484 "add", "r!0d,r!1d,#!2d", 2),
Bill Buzbee270c1d62009-08-13 16:58:07 -0700485 ENCODING_MAP(THUMB2_MOV_RR, 0xea4f0000, /* no setflags encoding */
486 BITBLT, 11, 8, BITBLT, 3, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700487 IS_BINARY_OP | CLOBBER_DEST,
488 "mov", "r!0d, r!1d", 2),
489 ENCODING_MAP(THUMB2_VMOVS, 0xeeb00a40,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700490 SFP, 22, 12, SFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700491 IS_BINARY_OP | CLOBBER_DEST,
492 "vmov.f32 ", "!0s, !1s", 2),
493 ENCODING_MAP(THUMB2_VMOVD, 0xeeb00b40,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700494 DFP, 22, 12, DFP, 5, 0, UNUSED, -1, -1, UNUSED, -1, -1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700495 IS_BINARY_OP | CLOBBER_DEST,
496 "vmov.f64 ", "!0s, !1s", 2),
Bill Buzbee270c1d62009-08-13 16:58:07 -0700497 ENCODING_MAP(THUMB2_LDMIA, 0xe8900000,
498 BITBLT, 19, 16, BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1,
499 IS_BINARY_OP | CLOBBER_DEST | CLOBBER_SRC1,
500 "ldmia", "r!0d!!, <!1R>", 2),
501 ENCODING_MAP(THUMB2_STMIA, 0xe8800000,
502 BITBLT, 19, 16, BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1,
503 IS_BINARY_OP | CLOBBER_SRC1,
504 "stmia", "r!0d!!, <!1R>", 2),
505 ENCODING_MAP(THUMB2_ADD_RRR, 0xeb100000, /* setflags encoding */
506 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
507 IS_QUAD_OP | CLOBBER_DEST | SETS_CCODES,
508 "adds", "r!0d, r!1d, r!2d", 2),
509 ENCODING_MAP(THUMB2_SUB_RRR, 0xebb00000, /* setflags enconding */
510 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
511 IS_QUAD_OP | CLOBBER_DEST | SETS_CCODES,
512 "subs", "r!0d, r!1d, r!2d", 2),
513 ENCODING_MAP(THUMB2_SBC_RRR, 0xeb700000, /* setflags encoding */
514 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
515 IS_QUAD_OP | CLOBBER_DEST | USES_CCODES | SETS_CCODES,
516 "sbcs", "r!0d, r!1d, r!2d", 2),
517 ENCODING_MAP(THUMB2_CMP_RR, 0xebb00f00,
518 BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1, UNUSED, -1, -1,
519 IS_TERTIARY_OP | SETS_CCODES,
520 "cmp", "r!0d, r!1d", 2),
521 ENCODING_MAP(THUMB2_SUB_RRI12, 0xf2a00000,
522 BITBLT, 11, 8, BITBLT, 19, 16, IMM12, -1, -1, UNUSED, -1, -1,
523 IS_TERTIARY_OP | CLOBBER_DEST,/* Note: doesn't affect flags */
524 "sub", "r!0d,r!1d,#!2d", 2),
525 ENCODING_MAP(THUMB2_MVN_IMM_SHIFT, 0xf06f0000, /* no setflags encoding */
526 BITBLT, 11, 8, MODIMM, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
527 IS_BINARY_OP | CLOBBER_DEST,
528 "mvn", "r!0d, #!1n", 2),
529 ENCODING_MAP(THUMB2_SEL, 0xfaa0f080,
530 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
531 IS_TERTIARY_OP | CLOBBER_DEST | USES_CCODES,
532 "sel", "r!0d, r!1d, r!2d", 2),
533 ENCODING_MAP(THUMB2_UBFX, 0xf3c00000,
534 BITBLT, 11, 8, BITBLT, 19, 16, LSB, -1, -1, BWIDTH, 4, 0,
535 IS_QUAD_OP | CLOBBER_DEST,
536 "ubfx", "r!0d, r!1d, #!2d, #!3d", 2),
537 ENCODING_MAP(THUMB2_SBFX, 0xf3400000,
538 BITBLT, 11, 8, BITBLT, 19, 16, LSB, -1, -1, BWIDTH, 4, 0,
539 IS_QUAD_OP | CLOBBER_DEST,
540 "sbfx", "r!0d, r!1d, #!2d, #!3d", 2),
541 ENCODING_MAP(THUMB2_LDR_RRR, 0xf8500000,
542 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
543 IS_QUAD_OP | CLOBBER_DEST,
544 "ldr", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
545 ENCODING_MAP(THUMB2_LDRH_RRR, 0xf8300000,
546 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
547 IS_QUAD_OP | CLOBBER_DEST,
548 "ldrh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
549 ENCODING_MAP(THUMB2_LDRSH_RRR, 0xf9300000,
550 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
551 IS_QUAD_OP | CLOBBER_DEST,
552 "ldrsh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
553 ENCODING_MAP(THUMB2_LDRB_RRR, 0xf8100000,
554 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
555 IS_QUAD_OP | CLOBBER_DEST,
556 "ldrb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
557 ENCODING_MAP(THUMB2_LDRSB_RRR, 0xf9100000,
558 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
559 IS_QUAD_OP | CLOBBER_DEST,
560 "ldrsb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
561 ENCODING_MAP(THUMB2_STR_RRR, 0xf8400000,
562 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
563 IS_QUAD_OP | CLOBBER_DEST,
564 "str", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
565 ENCODING_MAP(THUMB2_STRH_RRR, 0xf8200000,
566 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
567 IS_QUAD_OP | CLOBBER_DEST,
568 "strh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
569 ENCODING_MAP(THUMB2_STRB_RRR, 0xf8000000,
570 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 3, 0, BITBLT, 5, 4,
571 IS_QUAD_OP | CLOBBER_DEST,
572 "strb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
573 ENCODING_MAP(THUMB2_LDRH_RRI12, 0xf8b00000,
574 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
575 IS_TERTIARY_OP | CLOBBER_DEST,
576 "ldrh", "r!0d,[r!1d, #!2d", 2),
577 ENCODING_MAP(THUMB2_LDRSH_RRI12, 0xf9b00000,
578 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
579 IS_TERTIARY_OP | CLOBBER_DEST,
580 "ldrsh", "r!0d,[r!1d, #!2d", 2),
581 ENCODING_MAP(THUMB2_LDRB_RRI12, 0xf8900000,
582 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
583 IS_TERTIARY_OP | CLOBBER_DEST,
584 "ldrb", "r!0d,[r!1d, #!2d", 2),
585 ENCODING_MAP(THUMB2_LDRSB_RRI12, 0xf9900000,
586 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
587 IS_TERTIARY_OP | CLOBBER_DEST,
588 "ldrsb", "r!0d,[r!1d, #!2d", 2),
589 ENCODING_MAP(THUMB2_STRH_RRI12, 0xf8a00000,
590 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
591 IS_TERTIARY_OP | CLOBBER_DEST,
592 "strh", "r!0d,[r!1d, #!2d", 2),
593 ENCODING_MAP(THUMB2_STRB_RRI12, 0xf8800000,
594 BITBLT, 15, 12, BITBLT, 19, 16, BITBLT, 11, 0, UNUSED, -1, -1,
595 IS_TERTIARY_OP | CLOBBER_DEST,
596 "strb", "r!0d,[r!1d, #!2d", 2),
597 ENCODING_MAP(THUMB2_POP, 0xe8bd0000,
598 BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
599 IS_UNARY_OP,
600 "pop", "<!0R>", 2),
601 ENCODING_MAP(THUMB2_PUSH, 0xe8ad0000,
602 BITBLT, 15, 0, UNUSED, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
603 IS_UNARY_OP,
604 "push", "<!0R>", 2),
605 ENCODING_MAP(THUMB2_CMP_RI8, 0xf1b00f00,
606 BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1, UNUSED, -1, -1,
607 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
608 "cmp", "r!0d, #!1m", 2),
609 ENCODING_MAP(THUMB2_ADC_RRR, 0xeb500000, /* setflags encoding */
610 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
611 IS_QUAD_OP | CLOBBER_DEST | SETS_CCODES,
612 "acds", "r!0d, r!1d, r!2d, shift !3d", 2),
613 ENCODING_MAP(THUMB2_AND_RRR, 0xea000000,
614 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
615 IS_QUAD_OP | CLOBBER_DEST,
616 "and", "r!0d, r!1d, r!2d, shift !3d", 2),
617 ENCODING_MAP(THUMB2_BIC_RRR, 0xea200000,
618 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
619 IS_QUAD_OP | CLOBBER_DEST,
620 "bic", "r!0d, r!1d, r!2d, shift !3d", 2),
621 ENCODING_MAP(THUMB2_CMN_RR, 0xeb000000,
622 BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1, UNUSED, -1, -1,
623 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
624 "cmn", "r!0d, r!1d, shift !2d", 2),
625 ENCODING_MAP(THUMB2_EOR_RRR, 0xea800000,
626 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
627 IS_QUAD_OP | CLOBBER_DEST,
628 "eor", "r!0d, r!1d, r!2d, shift !3d", 2),
629 ENCODING_MAP(THUMB2_MUL_RRR, 0xfb00f000,
630 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
631 IS_TERTIARY_OP | CLOBBER_DEST,
632 "mul", "r!0d, r!1d, r!2d", 2),
633 ENCODING_MAP(THUMB2_MVN_RR, 0xea6f0000,
634 BITBLT, 11, 8, BITBLT, 3, 0, SHIFT, -1, -1, UNUSED, -1, -1,
635 IS_TERTIARY_OP | CLOBBER_DEST,
636 "mvn", "r!0d, r!1d, shift !2d", 2),
637 ENCODING_MAP(THUMB2_RSUB_RRI8, 0xf1d00000,
638 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
639 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
640 "rsb", "r!0d,r!1d,#!2m", 2),
641 ENCODING_MAP(THUMB2_NEG_RR, 0xf1d00000, /* instance of rsub */
642 BITBLT, 11, 8, BITBLT, 19, 16, UNUSED, -1, -1, UNUSED, -1, -1,
643 IS_BINARY_OP | CLOBBER_DEST | SETS_CCODES,
644 "neg", "r!0d,r!1d", 2),
645 ENCODING_MAP(THUMB2_ORR_RRR, 0xea400000,
646 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1,
647 IS_QUAD_OP | CLOBBER_DEST,
648 "orr", "r!0d, r!1d, r!2d, shift !3d", 2),
649 ENCODING_MAP(THUMB2_TST_RR, 0xea100f00,
650 BITBLT, 19, 16, BITBLT, 3, 0, SHIFT, -1, -1, UNUSED, -1, -1,
651 IS_TERTIARY_OP | SETS_CCODES,
652 "tst", "r!0d, r!1d, shift !2d", 2),
653 ENCODING_MAP(THUMB2_LSLV_RRR, 0xfa00f000,
654 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
655 IS_TERTIARY_OP | CLOBBER_DEST,
656 "lsl", "r!0d, r!1d, r!2d", 2),
657 ENCODING_MAP(THUMB2_LSRV_RRR, 0xfa20f000,
658 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
659 IS_TERTIARY_OP | CLOBBER_DEST,
660 "lsr", "r!0d, r!1d, r!2d", 2),
661 ENCODING_MAP(THUMB2_ASRV_RRR, 0xfa40f000,
662 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
663 IS_TERTIARY_OP | CLOBBER_DEST,
664 "asr", "r!0d, r!1d, r!2d", 2),
665 ENCODING_MAP(THUMB2_RORV_RRR, 0xfa60f000,
666 BITBLT, 11, 8, BITBLT, 19, 16, BITBLT, 3, 0, UNUSED, -1, -1,
667 IS_TERTIARY_OP | CLOBBER_DEST,
668 "ror", "r!0d, r!1d, r!2d", 2),
669 ENCODING_MAP(THUMB2_LSL_RRI5, 0xea4f0000,
670 BITBLT, 11, 8, BITBLT, 3, 0, SHIFT5, -1, -1, UNUSED, -1, -1,
671 IS_TERTIARY_OP | CLOBBER_DEST,
672 "lsl", "r!0d, r!1d, #!2d", 2),
673 ENCODING_MAP(THUMB2_LSR_RRI5, 0xea4f0010,
674 BITBLT, 11, 8, BITBLT, 3, 0, SHIFT5, -1, -1, UNUSED, -1, -1,
675 IS_TERTIARY_OP | CLOBBER_DEST,
676 "lsr", "r!0d, r!1d, #!2d", 2),
677 ENCODING_MAP(THUMB2_ASR_RRI5, 0xea4f0020,
678 BITBLT, 11, 8, BITBLT, 3, 0, SHIFT5, -1, -1, UNUSED, -1, -1,
679 IS_TERTIARY_OP | CLOBBER_DEST,
680 "asr", "r!0d, r!1d, #!2d", 2),
681 ENCODING_MAP(THUMB2_ROR_RRI5, 0xea4f0030,
682 BITBLT, 11, 8, BITBLT, 3, 0, SHIFT5, -1, -1, UNUSED, -1, -1,
683 IS_TERTIARY_OP | CLOBBER_DEST,
684 "ror", "r!0d, r!1d, #!2d", 2),
685 ENCODING_MAP(THUMB2_BIC_RRI8, 0xf0200000,
686 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
687 IS_TERTIARY_OP | CLOBBER_DEST,
688 "bic", "r!0d, r!1d, #!2m", 2),
689 ENCODING_MAP(THUMB2_AND_RRI8, 0xf0000000,
690 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
691 IS_TERTIARY_OP | CLOBBER_DEST,
692 "and", "r!0d, r!1d, #!2m", 2),
693 ENCODING_MAP(THUMB2_ORR_RRI8, 0xf0400000,
694 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
695 IS_TERTIARY_OP | CLOBBER_DEST,
696 "orr", "r!0d, r!1d, #!2m", 2),
697 ENCODING_MAP(THUMB2_EOR_RRI8, 0xf0800000,
698 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
699 IS_TERTIARY_OP | CLOBBER_DEST,
700 "eor", "r!0d, r!1d, #!2m", 2),
701 ENCODING_MAP(THUMB2_ADD_RRI8, 0xf1100000,
702 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
703 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
704 "adds", "r!0d, r!1d, #!2m", 2),
705 ENCODING_MAP(THUMB2_ADC_RRI8, 0xf1500000,
706 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
707 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES | USES_CCODES,
708 "adcs", "r!0d, r!1d, #!2m", 2),
709 ENCODING_MAP(THUMB2_SUB_RRI8, 0xf1b00000,
710 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
711 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES,
712 "subs", "r!0d, r!1d, #!2m", 2),
713 ENCODING_MAP(THUMB2_SBC_RRI8, 0xf1700000,
714 BITBLT, 11, 8, BITBLT, 19, 16, MODIMM, -1, -1, UNUSED, -1, -1,
715 IS_TERTIARY_OP | CLOBBER_DEST | SETS_CCODES | USES_CCODES,
716 "sbcs", "r!0d, r!1d, #!2m", 2),
Ben Chengba4fc8b2009-06-01 13:00:29 -0700717};
718
Bill Buzbee270c1d62009-08-13 16:58:07 -0700719
Ben Chengba4fc8b2009-06-01 13:00:29 -0700720#define PADDING_MOV_R0_R0 0x1C00
721
722/* Write the numbers in the literal pool to the codegen stream */
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700723static void installDataContent(CompilationUnit *cUnit)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700724{
Ben Chenge80cd942009-07-17 15:54:23 -0700725 int *dataPtr = (int *) ((char *) cUnit->baseAddr + cUnit->dataOffset);
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700726 ArmLIR *dataLIR = (ArmLIR *) cUnit->wordList;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700727 while (dataLIR) {
728 *dataPtr++ = dataLIR->operands[0];
729 dataLIR = NEXT_LIR(dataLIR);
730 }
731}
732
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700733/* Returns the size of a Jit trace description */
734static int jitTraceDescriptionSize(const JitTraceDescription *desc)
735{
736 int runCount;
737 for (runCount = 0; ; runCount++) {
738 if (desc->trace[runCount].frag.runEnd)
739 break;
740 }
741 return sizeof(JitCodeDesc) + ((runCount+1) * sizeof(JitTraceRun));
742}
743
Ben Chengba4fc8b2009-06-01 13:00:29 -0700744/* Return TRUE if error happens */
745static bool assembleInstructions(CompilationUnit *cUnit, intptr_t startAddr)
746{
747 short *bufferAddr = (short *) cUnit->codeBuffer;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700748 ArmLIR *lir;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700749
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700750 for (lir = (ArmLIR *) cUnit->firstLIRInsn; lir; lir = NEXT_LIR(lir)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700751 if (lir->opCode < 0) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700752 if ((lir->opCode == ARM_PSEUDO_ALIGN4) &&
Ben Cheng1efc9c52009-06-08 18:25:27 -0700753 /* 1 means padding is needed */
754 (lir->operands[0] == 1)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700755 *bufferAddr++ = PADDING_MOV_R0_R0;
756 }
757 continue;
758 }
759
Ben Chenge9695e52009-06-16 16:11:47 -0700760 if (lir->isNop) {
761 continue;
762 }
763
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700764 if (lir->opCode == THUMB_LDR_PC_REL ||
765 lir->opCode == THUMB_ADD_PC_REL) {
766 ArmLIR *lirTarget = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700767 intptr_t pc = (lir->generic.offset + 4) & ~3;
Ben Cheng38329f52009-07-07 14:19:20 -0700768 /*
769 * Allow an offset (stored in operands[2] to be added to the
770 * PC-relative target. Useful to get to a fixed field inside a
771 * chaining cell.
772 */
773 intptr_t target = lirTarget->generic.offset + lir->operands[2];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700774 int delta = target - pc;
775 if (delta & 0x3) {
776 LOGE("PC-rel distance is not multiples of 4: %d\n", delta);
777 dvmAbort();
778 }
Ben Cheng1efc9c52009-06-08 18:25:27 -0700779 if (delta > 1023) {
780 return true;
781 }
Ben Chengba4fc8b2009-06-01 13:00:29 -0700782 lir->operands[1] = delta >> 2;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700783 } else if (lir->opCode == THUMB2_CBNZ || lir->opCode == THUMB2_CBZ) {
784 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
785 intptr_t pc = lir->generic.offset + 4;
786 intptr_t target = targetLIR->generic.offset;
787 int delta = target - pc;
788 if (delta > 126 || delta < 0) {
789 return true;
790 }
791 lir->operands[1] = delta >> 1;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700792 } else if (lir->opCode == THUMB_B_COND) {
793 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700794 intptr_t pc = lir->generic.offset + 4;
795 intptr_t target = targetLIR->generic.offset;
796 int delta = target - pc;
797 if (delta > 254 || delta < -256) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700798 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700799 }
800 lir->operands[0] = delta >> 1;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700801 } else if (lir->opCode == THUMB_B_UNCOND) {
802 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700803 intptr_t pc = lir->generic.offset + 4;
804 intptr_t target = targetLIR->generic.offset;
805 int delta = target - pc;
806 if (delta > 2046 || delta < -2048) {
807 LOGE("Unconditional branch distance out of range: %d\n", delta);
808 dvmAbort();
809 }
810 lir->operands[0] = delta >> 1;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700811 } else if (lir->opCode == THUMB_BLX_1) {
812 assert(NEXT_LIR(lir)->opCode == THUMB_BLX_2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700813 /* curPC is Thumb */
814 intptr_t curPC = (startAddr + lir->generic.offset + 4) & ~3;
815 intptr_t target = lir->operands[1];
816
817 /* Match bit[1] in target with base */
818 if (curPC & 0x2) {
819 target |= 0x2;
820 }
821 int delta = target - curPC;
822 assert((delta >= -(1<<22)) && (delta <= ((1<<22)-2)));
823
824 lir->operands[0] = (delta >> 12) & 0x7ff;
825 NEXT_LIR(lir)->operands[0] = (delta>> 1) & 0x7ff;
826 }
827
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700828 ArmEncodingMap *encoder = &EncodingMap[lir->opCode];
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700829 u4 bits = encoder->skeleton;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700830 int i;
Bill Buzbee270c1d62009-08-13 16:58:07 -0700831 for (i = 0; i < 4; i++) {
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700832 u4 value;
833 switch(encoder->fieldLoc[i].kind) {
834 case UNUSED:
835 break;
Bill Buzbee270c1d62009-08-13 16:58:07 -0700836 case SHIFT5:
837 value = ((lir->operands[i] & 0x1c) >> 2) << 12;
838 value |= (lir->operands[i] & 0x03) << 6;
839 bits |= value;
840 break;
841 case SHIFT:
842 value = ((lir->operands[i] & 0x70) >> 4) << 12;
843 value |= (lir->operands[i] & 0x0f) << 4;
844 bits |= value;
845 break;
846 case BWIDTH:
847 value = lir->operands[i] - 1;
848 bits |= value;
849 break;
850 case LSB:
851 value = ((lir->operands[i] & 0x1c) >> 2) << 12;
852 value |= (lir->operands[i] & 0x03) << 6;
853 bits |= value;
854 break;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700855 case IMM6:
856 value = ((lir->operands[i] & 0x20) >> 5) << 9;
857 value |= (lir->operands[i] & 0x1f) << 3;
858 bits |= value;
859 break;
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700860 case BITBLT:
861 value = (lir->operands[i] << encoder->fieldLoc[i].start) &
862 ((1 << (encoder->fieldLoc[i].end + 1)) - 1);
863 bits |= value;
864 break;
865 case DFP:
866 /* Snag the 1-bit slice and position it */
867 value = ((lir->operands[i] & 0x10) >> 4) <<
868 encoder->fieldLoc[i].end;
869 /* Extract and position the 4-bit slice */
870 value |= (lir->operands[i] & 0x0f) <<
871 encoder->fieldLoc[i].start;
872 bits |= value;
873 break;
874 case SFP:
875 /* Snag the 1-bit slice and position it */
876 value = (lir->operands[i] & 0x1) <<
877 encoder->fieldLoc[i].end;
878 /* Extract and position the 4-bit slice */
879 value |= ((lir->operands[i] & 0x1e) >> 1) <<
880 encoder->fieldLoc[i].start;
881 bits |= value;
882 break;
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700883 case IMM12:
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700884 case MODIMM:
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700885 value = ((lir->operands[i] & 0x800) >> 11) << 26;
886 value |= ((lir->operands[i] & 0x700) >> 8) << 12;
887 value |= lir->operands[i] & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700888 bits |= value;
889 break;
890 case IMM16:
891 value = ((lir->operands[i] & 0x0800) >> 11) << 26;
892 value |= ((lir->operands[i] & 0xf000) >> 12) << 16;
893 value |= ((lir->operands[i] & 0x0700) >> 8) << 12;
894 value |= lir->operands[i] & 0x0ff;
895 bits |= value;
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700896 break;
897 default:
898 assert(0);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700899 }
900 }
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700901 if (encoder->size == 2) {
902 *bufferAddr++ = (bits >> 16) & 0xffff;
903 }
904 *bufferAddr++ = bits & 0xffff;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700905 }
Ben Cheng1efc9c52009-06-08 18:25:27 -0700906 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700907}
908
909/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700910 * Translation layout in the code cache. Note that the codeAddress pointer
911 * in JitTable will point directly to the code body (field codeAddress). The
912 * chain cell offset codeAddress - 2, and (if present) executionCount is at
913 * codeAddress - 6.
914 *
915 * +----------------------------+
916 * | Execution count | -> [Optional] 4 bytes
917 * +----------------------------+
918 * +--| Offset to chain cell counts| -> 2 bytes
919 * | +----------------------------+
920 * | | Code body | -> Start address for translation
921 * | | | variable in 2-byte chunks
922 * | . . (JitTable's codeAddress points here)
923 * | . .
924 * | | |
925 * | +----------------------------+
926 * | | Chaining Cells | -> 8 bytes each, must be 4 byte aligned
927 * | . .
928 * | . .
929 * | | |
930 * | +----------------------------+
931 * +->| Chaining cell counts | -> 4 bytes, chain cell counts by type
932 * +----------------------------+
933 * | Trace description | -> variable sized
934 * . .
935 * | |
936 * +----------------------------+
937 * | Literal pool | -> 4-byte aligned, variable size
938 * . .
939 * . .
940 * | |
941 * +----------------------------+
942 *
Ben Chengba4fc8b2009-06-01 13:00:29 -0700943 * Go over each instruction in the list and calculate the offset from the top
944 * before sending them off to the assembler. If out-of-range branch distance is
945 * seen rearrange the instructions a bit to correct it.
946 */
Bill Buzbee716f1202009-07-23 13:22:09 -0700947void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700948{
949 LIR *lir;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700950 ArmLIR *armLIR;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700951 int offset = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700952 int i;
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700953 ChainCellCounts chainCellCounts;
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700954 int descSize = jitTraceDescriptionSize(cUnit->traceDesc);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700955
Bill Buzbee716f1202009-07-23 13:22:09 -0700956 info->codeAddress = NULL;
957 info->instructionSet = cUnit->instructionSet;
958
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700959 /* Beginning offset needs to allow space for chain cell offset */
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700960 for (armLIR = (ArmLIR *) cUnit->firstLIRInsn;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700961 armLIR;
962 armLIR = NEXT_LIR(armLIR)) {
963 armLIR->generic.offset = offset;
Ben Chenge9695e52009-06-16 16:11:47 -0700964 if (armLIR->opCode >= 0 && !armLIR->isNop) {
Bill Buzbee9bc3df32009-07-30 10:52:29 -0700965 armLIR->size = EncodingMap[armLIR->opCode].size * 2;
966 offset += armLIR->size;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700967 } else if (armLIR->opCode == ARM_PSEUDO_ALIGN4) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700968 if (offset & 0x2) {
969 offset += 2;
970 armLIR->operands[0] = 1;
971 } else {
972 armLIR->operands[0] = 0;
973 }
974 }
975 /* Pseudo opcodes don't consume space */
976 }
977
978 /* Const values have to be word aligned */
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700979 offset = (offset + 3) & ~3;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700980
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700981 /* Add space for chain cell counts & trace description */
Ben Cheng1efc9c52009-06-08 18:25:27 -0700982 u4 chainCellOffset = offset;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700983 ArmLIR *chainCellOffsetLIR = (ArmLIR *) cUnit->chainCellOffsetLIR;
Bill Buzbee6e963e12009-06-17 16:56:19 -0700984 assert(chainCellOffsetLIR);
Ben Cheng1efc9c52009-06-08 18:25:27 -0700985 assert(chainCellOffset < 0x10000);
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700986 assert(chainCellOffsetLIR->opCode == ARM_16BIT_DATA &&
Ben Cheng1efc9c52009-06-08 18:25:27 -0700987 chainCellOffsetLIR->operands[0] == CHAIN_CELL_OFFSET_TAG);
988
Ben Chenge80cd942009-07-17 15:54:23 -0700989 /*
990 * Replace the CHAIN_CELL_OFFSET_TAG with the real value. If trace
991 * profiling is enabled, subtract 4 (occupied by the counter word) from
992 * the absolute offset as the value stored in chainCellOffsetLIR is the
993 * delta from &chainCellOffsetLIR to &ChainCellCounts.
994 */
995 chainCellOffsetLIR->operands[0] =
996 gDvmJit.profile ? (chainCellOffset - 4) : chainCellOffset;
Ben Cheng1efc9c52009-06-08 18:25:27 -0700997
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700998 offset += sizeof(chainCellCounts) + descSize;
999
1000 assert((offset & 0x3) == 0); /* Should still be word aligned */
1001
1002 /* Set up offsets for literals */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001003 cUnit->dataOffset = offset;
1004
1005 for (lir = cUnit->wordList; lir; lir = lir->next) {
1006 lir->offset = offset;
1007 offset += 4;
1008 }
1009
1010 cUnit->totalSize = offset;
1011
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001012 if (gDvmJit.codeCacheByteUsed + cUnit->totalSize > CODE_CACHE_SIZE) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001013 gDvmJit.codeCacheFull = true;
1014 cUnit->baseAddr = NULL;
1015 return;
1016 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001017
1018 /* Allocate enough space for the code block */
1019 cUnit->codeBuffer = dvmCompilerNew(chainCellOffset, true);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001020 if (cUnit->codeBuffer == NULL) {
1021 LOGE("Code buffer allocation failure\n");
1022 cUnit->baseAddr = NULL;
1023 return;
1024 }
1025
Ben Cheng1efc9c52009-06-08 18:25:27 -07001026 bool assemblerFailure = assembleInstructions(
Ben Chengba4fc8b2009-06-01 13:00:29 -07001027 cUnit, (intptr_t) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed);
1028
Ben Cheng1efc9c52009-06-08 18:25:27 -07001029 /*
1030 * Currently the only reason that can cause the assembler to fail is due to
1031 * trace length - cut it in half and retry.
1032 */
1033 if (assemblerFailure) {
1034 cUnit->halveInstCount = true;
1035 return;
1036 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001037
Bill Buzbee6e963e12009-06-17 16:56:19 -07001038
Ben Chengba4fc8b2009-06-01 13:00:29 -07001039 cUnit->baseAddr = (char *) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed;
1040 gDvmJit.codeCacheByteUsed += offset;
1041
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001042 /* Install the code block */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001043 memcpy((char*)cUnit->baseAddr, cUnit->codeBuffer, chainCellOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001044 gDvmJit.numCompilations++;
1045
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001046 /* Install the chaining cell counts */
1047 for (i=0; i< CHAINING_CELL_LAST; i++) {
1048 chainCellCounts.u.count[i] = cUnit->numChainingCells[i];
1049 }
1050 memcpy((char*)cUnit->baseAddr + chainCellOffset, &chainCellCounts,
1051 sizeof(chainCellCounts));
1052
1053 /* Install the trace description */
1054 memcpy((char*)cUnit->baseAddr + chainCellOffset + sizeof(chainCellCounts),
1055 cUnit->traceDesc, descSize);
1056
1057 /* Write the literals directly into the code cache */
1058 installDataContent(cUnit);
1059
Ben Chengba4fc8b2009-06-01 13:00:29 -07001060 /* Flush dcache and invalidate the icache to maintain coherence */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001061 cacheflush((long)cUnit->baseAddr,
Ben Chenge80cd942009-07-17 15:54:23 -07001062 (long)((char *) cUnit->baseAddr + offset), 0);
Bill Buzbee716f1202009-07-23 13:22:09 -07001063
1064 /* Record code entry point and instruction set */
1065 info->codeAddress = (char*)cUnit->baseAddr + cUnit->headerSize;
1066 info->instructionSet = cUnit->instructionSet;
1067 /* If applicable, mark low bit to denote thumb */
1068 if (info->instructionSet != DALVIK_JIT_ARM)
1069 info->codeAddress = (char*)info->codeAddress + 1;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001070}
1071
Ben Cheng38329f52009-07-07 14:19:20 -07001072static u4 assembleBXPair(int branchOffset)
1073{
1074 u4 thumb1, thumb2;
1075
1076 if ((branchOffset < -2048) | (branchOffset > 2046)) {
1077 thumb1 = (0xf000 | ((branchOffset>>12) & 0x7ff));
1078 thumb2 = (0xf800 | ((branchOffset>> 1) & 0x7ff));
1079 } else {
1080 thumb1 = (0xe000 | ((branchOffset>> 1) & 0x7ff));
1081 thumb2 = 0x4300; /* nop -> or r0, r0 */
1082 }
1083
1084 return thumb2<<16 | thumb1;
1085}
1086
Ben Chengba4fc8b2009-06-01 13:00:29 -07001087/*
1088 * Perform translation chain operation.
1089 * For ARM, we'll use a pair of thumb instructions to generate
1090 * an unconditional chaining branch of up to 4MB in distance.
1091 * Use a BL, though we don't really need the link. The format is
1092 * 111HHooooooooooo
1093 * Where HH is 10 for the 1st inst, and 11 for the second and
1094 * the "o" field is each instruction's 11-bit contribution to the
1095 * 22-bit branch offset.
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001096 * If the target is nearby, use a single-instruction bl.
1097 * If one or more threads is suspended, don't chain.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001098 */
1099void* dvmJitChain(void* tgtAddr, u4* branchAddr)
1100{
1101 int baseAddr = (u4) branchAddr + 4;
1102 int branchOffset = (int) tgtAddr - baseAddr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001103 u4 newInst;
1104
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001105 if (gDvm.sumThreadSuspendCount == 0) {
1106 assert((branchOffset >= -(1<<22)) && (branchOffset <= ((1<<22)-2)));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001107
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001108 gDvmJit.translationChains++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001109
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001110 COMPILER_TRACE_CHAINING(
1111 LOGD("Jit Runtime: chaining 0x%x to 0x%x\n",
1112 (int) branchAddr, (int) tgtAddr & -2));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001113
Ben Cheng38329f52009-07-07 14:19:20 -07001114 newInst = assembleBXPair(branchOffset);
1115
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001116 *branchAddr = newInst;
1117 cacheflush((long)branchAddr, (long)branchAddr + 4, 0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001118 }
1119
Ben Chengba4fc8b2009-06-01 13:00:29 -07001120 return tgtAddr;
1121}
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001122
1123/*
Ben Cheng38329f52009-07-07 14:19:20 -07001124 * This method is called from the invoke templates for virtual and interface
1125 * methods to speculatively setup a chain to the callee. The templates are
1126 * written in assembly and have setup method, cell, and clazz at r0, r2, and
1127 * r3 respectively, so there is a unused argument in the list. Upon return one
1128 * of the following three results may happen:
1129 * 1) Chain is not setup because the callee is native. Reset the rechain
1130 * count to a big number so that it will take a long time before the next
1131 * rechain attempt to happen.
1132 * 2) Chain is not setup because the callee has not been created yet. Reset
1133 * the rechain count to a small number and retry in the near future.
1134 * 3) Ask all other threads to stop before patching this chaining cell.
1135 * This is required because another thread may have passed the class check
1136 * but hasn't reached the chaining cell yet to follow the chain. If we
1137 * patch the content before halting the other thread, there could be a
1138 * small window for race conditions to happen that it may follow the new
1139 * but wrong chain to invoke a different method.
1140 */
1141const Method *dvmJitToPatchPredictedChain(const Method *method,
1142 void *unused,
1143 PredictedChainingCell *cell,
1144 const ClassObject *clazz)
1145{
Jeff Hao97319a82009-08-12 16:57:15 -07001146#if defined(WITH_SELF_VERIFICATION)
1147 /* Disable chaining and prevent this from triggering again for a while */
1148 cell->counter = PREDICTED_CHAIN_COUNTER_AVOID;
1149 cacheflush((long) cell, (long) (cell+1), 0);
1150 goto done;
1151#else
Ben Cheng38329f52009-07-07 14:19:20 -07001152 /* Don't come back here for a long time if the method is native */
1153 if (dvmIsNativeMethod(method)) {
1154 cell->counter = PREDICTED_CHAIN_COUNTER_AVOID;
1155 cacheflush((long) cell, (long) (cell+1), 0);
1156 COMPILER_TRACE_CHAINING(
1157 LOGD("Jit Runtime: predicted chain %p to native method %s ignored",
1158 cell, method->name));
1159 goto done;
1160 }
1161 int tgtAddr = (int) dvmJitGetCodeAddr(method->insns);
1162
1163 /*
1164 * Compilation not made yet for the callee. Reset the counter to a small
1165 * value and come back to check soon.
1166 */
1167 if (tgtAddr == 0) {
1168 /*
1169 * Wait for a few invocations (currently set to be 16) before trying
1170 * to setup the chain again.
1171 */
1172 cell->counter = PREDICTED_CHAIN_COUNTER_DELAY;
1173 cacheflush((long) cell, (long) (cell+1), 0);
1174 COMPILER_TRACE_CHAINING(
1175 LOGD("Jit Runtime: predicted chain %p to method %s delayed",
1176 cell, method->name));
1177 goto done;
1178 }
1179
1180 /* Stop the world */
1181 dvmSuspendAllThreads(SUSPEND_FOR_JIT);
1182
1183 int baseAddr = (int) cell + 4; // PC is cur_addr + 4
1184 int branchOffset = tgtAddr - baseAddr;
1185
1186 COMPILER_TRACE_CHAINING(
1187 LOGD("Jit Runtime: predicted chain %p from %s to %s (%s) patched",
1188 cell, cell->clazz ? cell->clazz->descriptor : "NULL",
1189 clazz->descriptor,
1190 method->name));
1191
1192 cell->branch = assembleBXPair(branchOffset);
1193 cell->clazz = clazz;
1194 cell->method = method;
1195 cell->counter = PREDICTED_CHAIN_COUNTER_RECHAIN;
1196
1197 cacheflush((long) cell, (long) (cell+1), 0);
1198
1199 /* All done - resume all other threads */
1200 dvmResumeAllThreads(SUSPEND_FOR_JIT);
Jeff Hao97319a82009-08-12 16:57:15 -07001201#endif
Ben Cheng38329f52009-07-07 14:19:20 -07001202
1203done:
1204 return method;
1205}
1206
1207/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001208 * Unchain a trace given the starting address of the translation
1209 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
1210 * Returns the address following the last cell unchained. Note that
1211 * the incoming codeAddr is a thumb code address, and therefore has
1212 * the low bit set.
1213 */
1214u4* dvmJitUnchain(void* codeAddr)
1215{
1216 u2* pChainCellOffset = (u2*)((char*)codeAddr - 3);
1217 u2 chainCellOffset = *pChainCellOffset;
1218 ChainCellCounts *pChainCellCounts =
Ben Chenge80cd942009-07-17 15:54:23 -07001219 (ChainCellCounts*)((char*)codeAddr + chainCellOffset - 3);
Ben Cheng38329f52009-07-07 14:19:20 -07001220 int cellSize;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001221 u4* pChainCells;
1222 u4* pStart;
1223 u4 thumb1;
1224 u4 thumb2;
1225 u4 newInst;
1226 int i,j;
Ben Cheng38329f52009-07-07 14:19:20 -07001227 PredictedChainingCell *predChainCell;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001228
1229 /* Get total count of chain cells */
Ben Cheng38329f52009-07-07 14:19:20 -07001230 for (i = 0, cellSize = 0; i < CHAINING_CELL_LAST; i++) {
1231 if (i != CHAINING_CELL_INVOKE_PREDICTED) {
1232 cellSize += pChainCellCounts->u.count[i] * 2;
1233 } else {
1234 cellSize += pChainCellCounts->u.count[i] * 4;
1235 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001236 }
1237
1238 /* Locate the beginning of the chain cell region */
Ben Cheng38329f52009-07-07 14:19:20 -07001239 pStart = pChainCells = ((u4 *) pChainCellCounts) - cellSize;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001240
1241 /* The cells are sorted in order - walk through them and reset */
1242 for (i = 0; i < CHAINING_CELL_LAST; i++) {
Ben Cheng38329f52009-07-07 14:19:20 -07001243 int elemSize = 2; /* Most chaining cell has two words */
1244 if (i == CHAINING_CELL_INVOKE_PREDICTED) {
1245 elemSize = 4;
1246 }
1247
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001248 for (j = 0; j < pChainCellCounts->u.count[i]; j++) {
1249 int targetOffset;
1250 switch(i) {
Ben Cheng1efc9c52009-06-08 18:25:27 -07001251 case CHAINING_CELL_NORMAL:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001252 targetOffset = offsetof(InterpState,
1253 jitToInterpEntries.dvmJitToInterpNormal);
1254 break;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001255 case CHAINING_CELL_HOT:
Ben Cheng38329f52009-07-07 14:19:20 -07001256 case CHAINING_CELL_INVOKE_SINGLETON:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001257 targetOffset = offsetof(InterpState,
1258 jitToInterpEntries.dvmJitToTraceSelect);
1259 break;
Ben Cheng38329f52009-07-07 14:19:20 -07001260 case CHAINING_CELL_INVOKE_PREDICTED:
1261 targetOffset = 0;
1262 predChainCell = (PredictedChainingCell *) pChainCells;
1263 /* Reset the cell to the init state */
1264 predChainCell->branch = PREDICTED_CHAIN_BX_PAIR_INIT;
1265 predChainCell->clazz = PREDICTED_CHAIN_CLAZZ_INIT;
1266 predChainCell->method = PREDICTED_CHAIN_METHOD_INIT;
1267 predChainCell->counter = PREDICTED_CHAIN_COUNTER_INIT;
1268 break;
Jeff Hao97319a82009-08-12 16:57:15 -07001269#if defined(WITH_SELF_VERIFICATION)
1270 case CHAINING_CELL_BACKWARD_BRANCH:
1271 targetOffset = offsetof(InterpState,
1272 jitToInterpEntries.dvmJitToBackwardBranch);
1273 break;
1274#endif
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001275 default:
1276 dvmAbort();
1277 }
Ben Cheng38329f52009-07-07 14:19:20 -07001278 COMPILER_TRACE_CHAINING(
1279 LOGD("Jit Runtime: unchaining 0x%x", (int)pChainCells));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001280 /*
Ben Cheng38329f52009-07-07 14:19:20 -07001281 * Thumb code sequence for a chaining cell is:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001282 * ldr r0, rGLUE, #<word offset>
1283 * blx r0
1284 */
Ben Cheng38329f52009-07-07 14:19:20 -07001285 if (i != CHAINING_CELL_INVOKE_PREDICTED) {
1286 targetOffset = targetOffset >> 2; /* convert to word offset */
1287 thumb1 = 0x6800 | (targetOffset << 6) |
1288 (rGLUE << 3) | (r0 << 0);
1289 thumb2 = 0x4780 | (r0 << 3);
1290 newInst = thumb2<<16 | thumb1;
1291 *pChainCells = newInst;
1292 }
1293 pChainCells += elemSize; /* Advance by a fixed number of words */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001294 }
1295 }
1296 return pChainCells;
1297}
1298
1299/* Unchain all translation in the cache. */
1300void dvmJitUnchainAll()
1301{
1302 u4* lowAddress = NULL;
1303 u4* highAddress = NULL;
1304 unsigned int i;
1305 if (gDvmJit.pJitEntryTable != NULL) {
1306 COMPILER_TRACE_CHAINING(LOGD("Jit Runtime: unchaining all"));
1307 dvmLockMutex(&gDvmJit.tableLock);
Bill Buzbee27176222009-06-09 09:20:16 -07001308 for (i = 0; i < gDvmJit.jitTableSize; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001309 if (gDvmJit.pJitEntryTable[i].dPC &&
1310 gDvmJit.pJitEntryTable[i].codeAddress) {
1311 u4* lastAddress;
1312 lastAddress =
1313 dvmJitUnchain(gDvmJit.pJitEntryTable[i].codeAddress);
1314 if (lowAddress == NULL ||
1315 (u4*)gDvmJit.pJitEntryTable[i].codeAddress < lowAddress)
1316 lowAddress = lastAddress;
1317 if (lastAddress > highAddress)
1318 highAddress = lastAddress;
1319 }
1320 }
1321 cacheflush((long)lowAddress, (long)highAddress, 0);
1322 dvmUnlockMutex(&gDvmJit.tableLock);
1323 }
1324}
Bill Buzbee716f1202009-07-23 13:22:09 -07001325
1326typedef struct jitProfileAddrToLine {
1327 u4 lineNum;
1328 u4 bytecodeOffset;
1329} jitProfileAddrToLine;
1330
1331
1332/* Callback function to track the bytecode offset/line number relationiship */
1333static int addrToLineCb (void *cnxt, u4 bytecodeOffset, u4 lineNum)
1334{
1335 jitProfileAddrToLine *addrToLine = (jitProfileAddrToLine *) cnxt;
1336
1337 /* Best match so far for this offset */
1338 if (addrToLine->bytecodeOffset >= bytecodeOffset) {
1339 addrToLine->lineNum = lineNum;
1340 }
1341 return 0;
1342}
1343
1344char *getTraceBase(const JitEntry *p)
1345{
1346 return (char*)p->codeAddress -
1347 (6 + (p->u.info.instructionSet == DALVIK_JIT_ARM ? 0 : 1));
1348}
1349
1350/* Dumps profile info for a single trace */
1351static int dumpTraceProfile(JitEntry *p)
1352{
1353 ChainCellCounts* pCellCounts;
1354 char* traceBase;
1355 u4* pExecutionCount;
1356 u2* pCellOffset;
1357 JitTraceDescription *desc;
1358 const Method* method;
1359
1360 traceBase = getTraceBase(p);
1361
1362 if (p->codeAddress == NULL) {
1363 LOGD("TRACEPROFILE 0x%08x 0 NULL 0 0", (int)traceBase);
1364 return 0;
1365 }
1366
1367 pExecutionCount = (u4*) (traceBase);
1368 pCellOffset = (u2*) (traceBase + 4);
1369 pCellCounts = (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1370 desc = (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1371 method = desc->method;
1372 char *methodDesc = dexProtoCopyMethodDescriptor(&method->prototype);
1373 jitProfileAddrToLine addrToLine = {0, desc->trace[0].frag.startOffset};
1374
1375 /*
1376 * We may end up decoding the debug information for the same method
1377 * multiple times, but the tradeoff is we don't need to allocate extra
1378 * space to store the addr/line mapping. Since this is a debugging feature
1379 * and done infrequently so the slower but simpler mechanism should work
1380 * just fine.
1381 */
1382 dexDecodeDebugInfo(method->clazz->pDvmDex->pDexFile,
1383 dvmGetMethodCode(method),
1384 method->clazz->descriptor,
1385 method->prototype.protoIdx,
1386 method->accessFlags,
1387 addrToLineCb, NULL, &addrToLine);
1388
1389 LOGD("TRACEPROFILE 0x%08x % 10d [%#x(+%d), %d] %s%s;%s",
1390 (int)traceBase,
1391 *pExecutionCount,
1392 desc->trace[0].frag.startOffset,
1393 desc->trace[0].frag.numInsts,
1394 addrToLine.lineNum,
1395 method->clazz->descriptor, method->name, methodDesc);
1396 free(methodDesc);
1397
1398 return *pExecutionCount;
1399}
1400
1401/* Handy function to retrieve the profile count */
1402static inline int getProfileCount(const JitEntry *entry)
1403{
1404 if (entry->dPC == 0 || entry->codeAddress == 0)
1405 return 0;
1406 u4 *pExecutionCount = (u4 *) getTraceBase(entry);
1407
1408 return *pExecutionCount;
1409}
1410
1411
1412/* qsort callback function */
1413static int sortTraceProfileCount(const void *entry1, const void *entry2)
1414{
1415 const JitEntry *jitEntry1 = entry1;
1416 const JitEntry *jitEntry2 = entry2;
1417
1418 int count1 = getProfileCount(jitEntry1);
1419 int count2 = getProfileCount(jitEntry2);
1420 return (count1 == count2) ? 0 : ((count1 > count2) ? -1 : 1);
1421}
1422
1423/* Sort the trace profile counts and dump them */
1424void dvmCompilerSortAndPrintTraceProfiles()
1425{
1426 JitEntry *sortedEntries;
1427 int numTraces = 0;
1428 unsigned long counts = 0;
1429 unsigned int i;
1430
1431 /* Make sure that the table is not changing */
1432 dvmLockMutex(&gDvmJit.tableLock);
1433
1434 /* Sort the entries by descending order */
1435 sortedEntries = malloc(sizeof(JitEntry) * gDvmJit.jitTableSize);
1436 if (sortedEntries == NULL)
1437 goto done;
1438 memcpy(sortedEntries, gDvmJit.pJitEntryTable,
1439 sizeof(JitEntry) * gDvmJit.jitTableSize);
1440 qsort(sortedEntries, gDvmJit.jitTableSize, sizeof(JitEntry),
1441 sortTraceProfileCount);
1442
1443 /* Dump the sorted entries */
1444 for (i=0; i < gDvmJit.jitTableSize; i++) {
1445 if (sortedEntries[i].dPC != 0) {
1446 counts += dumpTraceProfile(&sortedEntries[i]);
1447 numTraces++;
1448 }
1449 }
1450 if (numTraces == 0)
1451 numTraces = 1;
1452 LOGD("JIT: Average execution count -> %d",(int)(counts / numTraces));
1453
1454 free(sortedEntries);
1455done:
1456 dvmUnlockMutex(&gDvmJit.tableLock);
1457 return;
1458}