blob: 207b0b679565caef31a315e2a7532fc32107f893 [file] [log] [blame]
Sebastien Hertz807a2562013-04-15 09:33:39 +02001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_DEX_INSTRUCTION_INL_H_
18#define ART_RUNTIME_DEX_INSTRUCTION_INL_H_
Sebastien Hertz807a2562013-04-15 09:33:39 +020019
20#include "dex_instruction.h"
21
22namespace art {
23
Sebastien Hertz807a2562013-04-15 09:33:39 +020024//------------------------------------------------------------------------------
25// VRegA
26//------------------------------------------------------------------------------
Sebastien Hertz3b588e02013-09-11 14:33:18 +020027inline int8_t Instruction::VRegA_10t(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020028 DCHECK_EQ(FormatOf(Opcode()), k10t);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020029 return static_cast<int8_t>(InstAA(inst_data));
Sebastien Hertz807a2562013-04-15 09:33:39 +020030}
31
Sebastien Hertz3b588e02013-09-11 14:33:18 +020032inline uint8_t Instruction::VRegA_10x(uint16_t inst_data) const {
Sebastien Hertz5243e912013-05-21 10:55:07 +020033 DCHECK_EQ(FormatOf(Opcode()), k10x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020034 return InstAA(inst_data);
Sebastien Hertz5243e912013-05-21 10:55:07 +020035}
36
Sebastien Hertz3b588e02013-09-11 14:33:18 +020037inline uint4_t Instruction::VRegA_11n(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020038 DCHECK_EQ(FormatOf(Opcode()), k11n);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020039 return InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020040}
41
Sebastien Hertz3b588e02013-09-11 14:33:18 +020042inline uint8_t Instruction::VRegA_11x(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020043 DCHECK_EQ(FormatOf(Opcode()), k11x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020044 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020045}
46
Sebastien Hertz3b588e02013-09-11 14:33:18 +020047inline uint4_t Instruction::VRegA_12x(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020048 DCHECK_EQ(FormatOf(Opcode()), k12x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020049 return InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020050}
51
52inline int16_t Instruction::VRegA_20t() const {
53 DCHECK_EQ(FormatOf(Opcode()), k20t);
54 return static_cast<int16_t>(Fetch16(1));
55}
56
Sebastien Hertz3b588e02013-09-11 14:33:18 +020057inline uint8_t Instruction::VRegA_21c(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020058 DCHECK_EQ(FormatOf(Opcode()), k21c);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020059 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020060}
61
Sebastien Hertz3b588e02013-09-11 14:33:18 +020062inline uint8_t Instruction::VRegA_21h(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020063 DCHECK_EQ(FormatOf(Opcode()), k21h);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020064 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020065}
66
Sebastien Hertz3b588e02013-09-11 14:33:18 +020067inline uint8_t Instruction::VRegA_21s(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020068 DCHECK_EQ(FormatOf(Opcode()), k21s);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020069 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020070}
71
Sebastien Hertz3b588e02013-09-11 14:33:18 +020072inline uint8_t Instruction::VRegA_21t(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020073 DCHECK_EQ(FormatOf(Opcode()), k21t);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020074 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020075}
76
Sebastien Hertz3b588e02013-09-11 14:33:18 +020077inline uint8_t Instruction::VRegA_22b(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020078 DCHECK_EQ(FormatOf(Opcode()), k22b);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020079 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020080}
81
Sebastien Hertz3b588e02013-09-11 14:33:18 +020082inline uint4_t Instruction::VRegA_22c(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020083 DCHECK_EQ(FormatOf(Opcode()), k22c);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020084 return InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020085}
86
Sebastien Hertz3b588e02013-09-11 14:33:18 +020087inline uint4_t Instruction::VRegA_22s(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020088 DCHECK_EQ(FormatOf(Opcode()), k22s);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020089 return InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020090}
91
Sebastien Hertz3b588e02013-09-11 14:33:18 +020092inline uint4_t Instruction::VRegA_22t(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020093 DCHECK_EQ(FormatOf(Opcode()), k22t);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020094 return InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +020095}
96
Sebastien Hertz3b588e02013-09-11 14:33:18 +020097inline uint8_t Instruction::VRegA_22x(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +020098 DCHECK_EQ(FormatOf(Opcode()), k22x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +020099 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200100}
101
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200102inline uint8_t Instruction::VRegA_23x(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200103 DCHECK_EQ(FormatOf(Opcode()), k23x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200104 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200105}
106
107inline int32_t Instruction::VRegA_30t() const {
108 DCHECK_EQ(FormatOf(Opcode()), k30t);
109 return static_cast<int32_t>(Fetch32(1));
110}
111
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200112inline uint8_t Instruction::VRegA_31c(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200113 DCHECK_EQ(FormatOf(Opcode()), k31c);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200114 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200115}
116
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200117inline uint8_t Instruction::VRegA_31i(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200118 DCHECK_EQ(FormatOf(Opcode()), k31i);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200119 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200120}
121
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200122inline uint8_t Instruction::VRegA_31t(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200123 DCHECK_EQ(FormatOf(Opcode()), k31t);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200124 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200125}
126
127inline uint16_t Instruction::VRegA_32x() const {
128 DCHECK_EQ(FormatOf(Opcode()), k32x);
129 return Fetch16(1);
130}
131
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200132inline uint4_t Instruction::VRegA_35c(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200133 DCHECK_EQ(FormatOf(Opcode()), k35c);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200134 return InstB(inst_data); // This is labeled A in the spec.
Sebastien Hertz807a2562013-04-15 09:33:39 +0200135}
136
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200137inline uint8_t Instruction::VRegA_3rc(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200138 DCHECK_EQ(FormatOf(Opcode()), k3rc);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200139 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200140}
141
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200142inline uint8_t Instruction::VRegA_51l(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200143 DCHECK_EQ(FormatOf(Opcode()), k51l);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200144 return InstAA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200145}
146
147//------------------------------------------------------------------------------
148// VRegB
149//------------------------------------------------------------------------------
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200150inline int4_t Instruction::VRegB_11n(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200151 DCHECK_EQ(FormatOf(Opcode()), k11n);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200152 return static_cast<int4_t>((InstB(inst_data) << 28) >> 28);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200153}
154
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200155inline uint4_t Instruction::VRegB_12x(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200156 DCHECK_EQ(FormatOf(Opcode()), k12x);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200157 return InstB(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200158}
159
160inline uint16_t Instruction::VRegB_21c() const {
161 DCHECK_EQ(FormatOf(Opcode()), k21c);
162 return Fetch16(1);
163}
164
165inline uint16_t Instruction::VRegB_21h() const {
166 DCHECK_EQ(FormatOf(Opcode()), k21h);
167 return Fetch16(1);
168}
169
170inline int16_t Instruction::VRegB_21s() const {
171 DCHECK_EQ(FormatOf(Opcode()), k21s);
172 return static_cast<int16_t>(Fetch16(1));
173}
174
175inline int16_t Instruction::VRegB_21t() const {
176 DCHECK_EQ(FormatOf(Opcode()), k21t);
177 return static_cast<int16_t>(Fetch16(1));
178}
179
180inline uint8_t Instruction::VRegB_22b() const {
181 DCHECK_EQ(FormatOf(Opcode()), k22b);
182 return static_cast<uint8_t>(Fetch16(1) & 0xff);
183}
184
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200185inline uint4_t Instruction::VRegB_22c(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200186 DCHECK_EQ(FormatOf(Opcode()), k22c);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200187 return InstB(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200188}
189
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200190inline uint4_t Instruction::VRegB_22s(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200191 DCHECK_EQ(FormatOf(Opcode()), k22s);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200192 return InstB(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200193}
194
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200195inline uint4_t Instruction::VRegB_22t(uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200196 DCHECK_EQ(FormatOf(Opcode()), k22t);
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200197 return InstB(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200198}
199
200inline uint16_t Instruction::VRegB_22x() const {
201 DCHECK_EQ(FormatOf(Opcode()), k22x);
202 return Fetch16(1);
203}
204
205inline uint8_t Instruction::VRegB_23x() const {
206 DCHECK_EQ(FormatOf(Opcode()), k23x);
207 return static_cast<uint8_t>(Fetch16(1) & 0xff);
208}
209
210inline uint32_t Instruction::VRegB_31c() const {
211 DCHECK_EQ(FormatOf(Opcode()), k31c);
212 return Fetch32(1);
213}
214
215inline int32_t Instruction::VRegB_31i() const {
216 DCHECK_EQ(FormatOf(Opcode()), k31i);
217 return static_cast<int32_t>(Fetch32(1));
218}
219
220inline int32_t Instruction::VRegB_31t() const {
221 DCHECK_EQ(FormatOf(Opcode()), k31t);
222 return static_cast<int32_t>(Fetch32(1));
223}
224
225inline uint16_t Instruction::VRegB_32x() const {
226 DCHECK_EQ(FormatOf(Opcode()), k32x);
227 return Fetch16(2);
228}
229
230inline uint16_t Instruction::VRegB_35c() const {
231 DCHECK_EQ(FormatOf(Opcode()), k35c);
232 return Fetch16(1);
233}
234
235inline uint16_t Instruction::VRegB_3rc() const {
236 DCHECK_EQ(FormatOf(Opcode()), k3rc);
237 return Fetch16(1);
238}
239
240inline uint64_t Instruction::VRegB_51l() const {
241 DCHECK_EQ(FormatOf(Opcode()), k51l);
242 uint64_t vB_wide = Fetch32(1) | ((uint64_t) Fetch32(3) << 32);
243 return vB_wide;
244}
245
246//------------------------------------------------------------------------------
247// VRegC
248//------------------------------------------------------------------------------
249inline int8_t Instruction::VRegC_22b() const {
250 DCHECK_EQ(FormatOf(Opcode()), k22b);
251 return static_cast<int8_t>(Fetch16(1) >> 8);
252}
253
254inline uint16_t Instruction::VRegC_22c() const {
255 DCHECK_EQ(FormatOf(Opcode()), k22c);
256 return Fetch16(1);
257}
258
259inline int16_t Instruction::VRegC_22s() const {
260 DCHECK_EQ(FormatOf(Opcode()), k22s);
261 return static_cast<int16_t>(Fetch16(1));
262}
263
264inline int16_t Instruction::VRegC_22t() const {
265 DCHECK_EQ(FormatOf(Opcode()), k22t);
266 return static_cast<int16_t>(Fetch16(1));
267}
268
269inline uint8_t Instruction::VRegC_23x() const {
270 DCHECK_EQ(FormatOf(Opcode()), k23x);
271 return static_cast<uint8_t>(Fetch16(1) >> 8);
272}
273
274inline uint4_t Instruction::VRegC_35c() const {
275 DCHECK_EQ(FormatOf(Opcode()), k35c);
276 return static_cast<uint4_t>(Fetch16(2) & 0x0f);
277}
278
279inline uint16_t Instruction::VRegC_3rc() const {
280 DCHECK_EQ(FormatOf(Opcode()), k3rc);
281 return Fetch16(2);
282}
283
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200284inline void Instruction::GetArgs(uint32_t arg[5], uint16_t inst_data) const {
Sebastien Hertz807a2562013-04-15 09:33:39 +0200285 DCHECK_EQ(FormatOf(Opcode()), k35c);
286
287 /*
288 * Note that the fields mentioned in the spec don't appear in
289 * their "usual" positions here compared to most formats. This
290 * was done so that the field names for the argument count and
291 * reference index match between this format and the corresponding
292 * range formats (3rc and friends).
293 *
294 * Bottom line: The argument count is always in vA, and the
295 * method constant (or equivalent) is always in vB.
296 */
297 uint16_t regList = Fetch16(2);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200298 uint4_t count = InstB(inst_data); // This is labeled A in the spec.
299 DCHECK_LE(count, 5U) << "Invalid arg count in 35c (" << count << ")";
Sebastien Hertz807a2562013-04-15 09:33:39 +0200300
301 /*
302 * Copy the argument registers into the arg[] array, and
303 * also copy the first argument (if any) into vC. (The
304 * DecodedInstruction structure doesn't have separate
305 * fields for {vD, vE, vF, vG}, so there's no need to make
306 * copies of those.) Note that cases 5..2 fall through.
307 */
308 switch (count) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200309 case 5: arg[4] = InstA(inst_data);
Sebastien Hertz807a2562013-04-15 09:33:39 +0200310 case 4: arg[3] = (regList >> 12) & 0x0f;
311 case 3: arg[2] = (regList >> 8) & 0x0f;
312 case 2: arg[1] = (regList >> 4) & 0x0f;
313 case 1: arg[0] = regList & 0x0f; break;
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200314 default: // case 0
315 break; // Valid, but no need to do anything.
Sebastien Hertz807a2562013-04-15 09:33:39 +0200316 }
317}
318
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700319} // namespace art
Sebastien Hertz807a2562013-04-15 09:33:39 +0200320
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700321#endif // ART_RUNTIME_DEX_INSTRUCTION_INL_H_