blob: 66fbd2959e3018be62cf5d95035a51917dde8071 [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
17#ifndef ART_SRC_DEX_INSTRUCTION_INL_H_
18#define ART_SRC_DEX_INSTRUCTION_INL_H_
19
20#include "dex_instruction.h"
21
22namespace art {
23
24//------------------------------------------------------------------------------
25// VRegA
26//------------------------------------------------------------------------------
27inline int8_t Instruction::VRegA_10t() const {
28 DCHECK_EQ(FormatOf(Opcode()), k10t);
29 return static_cast<int8_t>(InstAA());
30}
31
32inline uint4_t Instruction::VRegA_11n() const {
33 DCHECK_EQ(FormatOf(Opcode()), k11n);
34 return InstA();
35}
36
37inline uint8_t Instruction::VRegA_11x() const {
38 DCHECK_EQ(FormatOf(Opcode()), k11x);
39 return InstAA();
40}
41
42inline uint4_t Instruction::VRegA_12x() const {
43 DCHECK_EQ(FormatOf(Opcode()), k12x);
44 return InstA();
45}
46
47inline int16_t Instruction::VRegA_20t() const {
48 DCHECK_EQ(FormatOf(Opcode()), k20t);
49 return static_cast<int16_t>(Fetch16(1));
50}
51
52inline uint8_t Instruction::VRegA_21c() const {
53 DCHECK_EQ(FormatOf(Opcode()), k21c);
54 return InstAA();
55}
56
57inline uint8_t Instruction::VRegA_21h() const {
58 DCHECK_EQ(FormatOf(Opcode()), k21h);
59 return InstAA();
60}
61
62inline uint8_t Instruction::VRegA_21s() const {
63 DCHECK_EQ(FormatOf(Opcode()), k21s);
64 return InstAA();
65}
66
67inline uint8_t Instruction::VRegA_21t() const {
68 DCHECK_EQ(FormatOf(Opcode()), k21t);
69 return InstAA();
70}
71
72inline uint8_t Instruction::VRegA_22b() const {
73 DCHECK_EQ(FormatOf(Opcode()), k22b);
74 return InstAA();
75}
76
77inline uint4_t Instruction::VRegA_22c() const {
78 DCHECK_EQ(FormatOf(Opcode()), k22c);
79 return InstA();
80}
81
82inline uint4_t Instruction::VRegA_22s() const {
83 DCHECK_EQ(FormatOf(Opcode()), k22s);
84 return InstA();
85}
86
87inline uint4_t Instruction::VRegA_22t() const {
88 DCHECK_EQ(FormatOf(Opcode()), k22t);
89 return InstA();
90}
91
92inline uint8_t Instruction::VRegA_22x() const {
93 DCHECK_EQ(FormatOf(Opcode()), k22x);
94 return InstAA();
95}
96
97inline uint8_t Instruction::VRegA_23x() const {
98 DCHECK_EQ(FormatOf(Opcode()), k23x);
99 return InstAA();
100}
101
102inline int32_t Instruction::VRegA_30t() const {
103 DCHECK_EQ(FormatOf(Opcode()), k30t);
104 return static_cast<int32_t>(Fetch32(1));
105}
106
107inline uint8_t Instruction::VRegA_31c() const {
108 DCHECK_EQ(FormatOf(Opcode()), k31c);
109 return InstAA();
110}
111
112inline uint8_t Instruction::VRegA_31i() const {
113 DCHECK_EQ(FormatOf(Opcode()), k31i);
114 return InstAA();
115}
116
117inline uint8_t Instruction::VRegA_31t() const {
118 DCHECK_EQ(FormatOf(Opcode()), k31t);
119 return InstAA();
120}
121
122inline uint16_t Instruction::VRegA_32x() const {
123 DCHECK_EQ(FormatOf(Opcode()), k32x);
124 return Fetch16(1);
125}
126
127inline uint4_t Instruction::VRegA_35c() const {
128 DCHECK_EQ(FormatOf(Opcode()), k35c);
129 return InstB(); // This is labeled A in the spec.
130}
131
132inline uint8_t Instruction::VRegA_3rc() const {
133 DCHECK_EQ(FormatOf(Opcode()), k3rc);
134 return InstAA();
135}
136
137inline uint8_t Instruction::VRegA_51l() const {
138 DCHECK_EQ(FormatOf(Opcode()), k51l);
139 return InstAA();
140}
141
142//------------------------------------------------------------------------------
143// VRegB
144//------------------------------------------------------------------------------
145inline int4_t Instruction::VRegB_11n() const {
146 DCHECK_EQ(FormatOf(Opcode()), k11n);
147 return static_cast<int4_t>((InstB() << 28) >> 28);
148}
149
150inline uint4_t Instruction::VRegB_12x() const {
151 DCHECK_EQ(FormatOf(Opcode()), k12x);
152 return InstB();
153}
154
155inline uint16_t Instruction::VRegB_21c() const {
156 DCHECK_EQ(FormatOf(Opcode()), k21c);
157 return Fetch16(1);
158}
159
160inline uint16_t Instruction::VRegB_21h() const {
161 DCHECK_EQ(FormatOf(Opcode()), k21h);
162 return Fetch16(1);
163}
164
165inline int16_t Instruction::VRegB_21s() const {
166 DCHECK_EQ(FormatOf(Opcode()), k21s);
167 return static_cast<int16_t>(Fetch16(1));
168}
169
170inline int16_t Instruction::VRegB_21t() const {
171 DCHECK_EQ(FormatOf(Opcode()), k21t);
172 return static_cast<int16_t>(Fetch16(1));
173}
174
175inline uint8_t Instruction::VRegB_22b() const {
176 DCHECK_EQ(FormatOf(Opcode()), k22b);
177 return static_cast<uint8_t>(Fetch16(1) & 0xff);
178}
179
180inline uint4_t Instruction::VRegB_22c() const {
181 DCHECK_EQ(FormatOf(Opcode()), k22c);
182 return InstB();
183}
184
185inline uint4_t Instruction::VRegB_22s() const {
186 DCHECK_EQ(FormatOf(Opcode()), k22s);
187 return InstB();
188}
189
190inline uint4_t Instruction::VRegB_22t() const {
191 DCHECK_EQ(FormatOf(Opcode()), k22t);
192 return InstB();
193}
194
195inline uint16_t Instruction::VRegB_22x() const {
196 DCHECK_EQ(FormatOf(Opcode()), k22x);
197 return Fetch16(1);
198}
199
200inline uint8_t Instruction::VRegB_23x() const {
201 DCHECK_EQ(FormatOf(Opcode()), k23x);
202 return static_cast<uint8_t>(Fetch16(1) & 0xff);
203}
204
205inline uint32_t Instruction::VRegB_31c() const {
206 DCHECK_EQ(FormatOf(Opcode()), k31c);
207 return Fetch32(1);
208}
209
210inline int32_t Instruction::VRegB_31i() const {
211 DCHECK_EQ(FormatOf(Opcode()), k31i);
212 return static_cast<int32_t>(Fetch32(1));
213}
214
215inline int32_t Instruction::VRegB_31t() const {
216 DCHECK_EQ(FormatOf(Opcode()), k31t);
217 return static_cast<int32_t>(Fetch32(1));
218}
219
220inline uint16_t Instruction::VRegB_32x() const {
221 DCHECK_EQ(FormatOf(Opcode()), k32x);
222 return Fetch16(2);
223}
224
225inline uint16_t Instruction::VRegB_35c() const {
226 DCHECK_EQ(FormatOf(Opcode()), k35c);
227 return Fetch16(1);
228}
229
230inline uint16_t Instruction::VRegB_3rc() const {
231 DCHECK_EQ(FormatOf(Opcode()), k3rc);
232 return Fetch16(1);
233}
234
235inline uint64_t Instruction::VRegB_51l() const {
236 DCHECK_EQ(FormatOf(Opcode()), k51l);
237 uint64_t vB_wide = Fetch32(1) | ((uint64_t) Fetch32(3) << 32);
238 return vB_wide;
239}
240
241//------------------------------------------------------------------------------
242// VRegC
243//------------------------------------------------------------------------------
244inline int8_t Instruction::VRegC_22b() const {
245 DCHECK_EQ(FormatOf(Opcode()), k22b);
246 return static_cast<int8_t>(Fetch16(1) >> 8);
247}
248
249inline uint16_t Instruction::VRegC_22c() const {
250 DCHECK_EQ(FormatOf(Opcode()), k22c);
251 return Fetch16(1);
252}
253
254inline int16_t Instruction::VRegC_22s() const {
255 DCHECK_EQ(FormatOf(Opcode()), k22s);
256 return static_cast<int16_t>(Fetch16(1));
257}
258
259inline int16_t Instruction::VRegC_22t() const {
260 DCHECK_EQ(FormatOf(Opcode()), k22t);
261 return static_cast<int16_t>(Fetch16(1));
262}
263
264inline uint8_t Instruction::VRegC_23x() const {
265 DCHECK_EQ(FormatOf(Opcode()), k23x);
266 return static_cast<uint8_t>(Fetch16(1) >> 8);
267}
268
269inline uint4_t Instruction::VRegC_35c() const {
270 DCHECK_EQ(FormatOf(Opcode()), k35c);
271 return static_cast<uint4_t>(Fetch16(2) & 0x0f);
272}
273
274inline uint16_t Instruction::VRegC_3rc() const {
275 DCHECK_EQ(FormatOf(Opcode()), k3rc);
276 return Fetch16(2);
277}
278
279inline void Instruction::GetArgs(uint32_t arg[5]) const {
280 DCHECK_EQ(FormatOf(Opcode()), k35c);
281
282 /*
283 * Note that the fields mentioned in the spec don't appear in
284 * their "usual" positions here compared to most formats. This
285 * was done so that the field names for the argument count and
286 * reference index match between this format and the corresponding
287 * range formats (3rc and friends).
288 *
289 * Bottom line: The argument count is always in vA, and the
290 * method constant (or equivalent) is always in vB.
291 */
292 uint16_t regList = Fetch16(2);
293 uint4_t count = InstB(); // This is labeled A in the spec.
294
295 /*
296 * Copy the argument registers into the arg[] array, and
297 * also copy the first argument (if any) into vC. (The
298 * DecodedInstruction structure doesn't have separate
299 * fields for {vD, vE, vF, vG}, so there's no need to make
300 * copies of those.) Note that cases 5..2 fall through.
301 */
302 switch (count) {
303 case 5: arg[4] = InstA();
304 case 4: arg[3] = (regList >> 12) & 0x0f;
305 case 3: arg[2] = (regList >> 8) & 0x0f;
306 case 2: arg[1] = (regList >> 4) & 0x0f;
307 case 1: arg[0] = regList & 0x0f; break;
308 case 0: break; // Valid, but no need to do anything.
309 default:
310 LOG(ERROR) << "Invalid arg count in 35c (" << count << ")";
311 return;
312 }
313}
314
315} // namespace art
316
317#endif // ART_SRC_DEX_INSTRUCTION_INL_H_