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